Skip to content

Commit 7a86cab

Browse files
committed
feat: some cdoe update
Signed-off-by: Fang Yuan <wojiushifangyuanlove@gmail.com>
1 parent d0ff3ee commit 7a86cab

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
.vscode
3+
local
4+
data/**/*.txt
5+
.flake8
6+

img2txt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def main(opt):
2222
if opt.mode == "simple":
2323
CHAR_LIST = '@%#*+=-:. '
2424
else:
25-
CHAR_LIST = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "
25+
# CHAR_LIST = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "
26+
CHAR_LIST = r"$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "
2627
num_chars = len(CHAR_LIST)
2728
num_cols = opt.num_cols
2829
image = cv2.imread(opt.input)

utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33

44

55
def sort_chars(char_list, font, language):
6+
67
if language == "chinese":
78
char_width, char_height = font.getsize("制")
89
elif language == "korean":
910
char_width, char_height = font.getsize("ㅊ")
1011
elif language == "japanese":
1112
char_width, char_height = font.getsize("あ")
12-
elif language in ["english", "german", "french", "spanish", "italian", "portuguese", "polish"]:
13+
elif language in [
14+
"english", "german", "french", "spanish", "italian", "portuguese",
15+
"polish"
16+
]:
1317
char_width, char_height = font.getsize("A")
1418
elif language == "russian":
1519
char_width, char_height = font.getsize("A")
@@ -21,7 +25,10 @@ def sort_chars(char_list, font, language):
2125
draw.text((0, 0), char_list, fill=0, font=font)
2226
cropped_image = ImageOps.invert(out_image).getbbox()
2327
out_image = out_image.crop(cropped_image)
24-
brightness = [np.mean(np.array(out_image)[:, 10 * i:10 * (i + 1)]) for i in range(len(char_list))]
28+
brightness = [
29+
np.mean(np.array(out_image)[:, 10 * i:10 * (i + 1)])
30+
for i in range(len(char_list))
31+
]
2532
char_list = list(char_list)
2633
zipped_lists = zip(brightness, char_list)
2734
zipped_lists = sorted(zipped_lists)

0 commit comments

Comments
 (0)