Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
.vscode
local
data/**/*.txt
.flake8

3 changes: 2 additions & 1 deletion img2txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def main(opt):
if opt.mode == "simple":
CHAR_LIST = '@%#*+=-:. '
else:
CHAR_LIST = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "
# CHAR_LIST = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "
CHAR_LIST = r"$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "
num_chars = len(CHAR_LIST)
num_cols = opt.num_cols
image = cv2.imread(opt.input)
Expand Down
11 changes: 9 additions & 2 deletions utils.py
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seem meaningless.

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@


def sort_chars(char_list, font, language):

if language == "chinese":
char_width, char_height = font.getsize("制")
elif language == "korean":
char_width, char_height = font.getsize("ㅊ")
elif language == "japanese":
char_width, char_height = font.getsize("あ")
elif language in ["english", "german", "french", "spanish", "italian", "portuguese", "polish"]:
elif language in [
"english", "german", "french", "spanish", "italian", "portuguese",
"polish"
]:
char_width, char_height = font.getsize("A")
elif language == "russian":
char_width, char_height = font.getsize("A")
Expand All @@ -21,7 +25,10 @@ def sort_chars(char_list, font, language):
draw.text((0, 0), char_list, fill=0, font=font)
cropped_image = ImageOps.invert(out_image).getbbox()
out_image = out_image.crop(cropped_image)
brightness = [np.mean(np.array(out_image)[:, 10 * i:10 * (i + 1)]) for i in range(len(char_list))]
brightness = [
np.mean(np.array(out_image)[:, 10 * i:10 * (i + 1)])
for i in range(len(char_list))
]
char_list = list(char_list)
zipped_lists = zip(brightness, char_list)
zipped_lists = sorted(zipped_lists)
Expand Down