Skip to content

Commit

Permalink
fix problems caused by English symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamGallery committed Oct 9, 2023
1 parent 386b863 commit 406e2d7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
print(
f"ASS-Generate-Progress:({'{:0>3d}'.format(current_count)}/{'{:0>3d}'.format(len(dial_list))})"
+ "{:>3d}%: ".format(percent),
"\033[33m▓\033[0m" * (percent // 2),
"" * (percent // 2),
end="",
)
print("\u0020", dial_event.Text, dial_event.Start, dial_event.End)
Expand Down
5 changes: 2 additions & 3 deletions src/frame.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import cv2, cv2.typing
import os, sys
import threading
import numpy as np
from src.read_ini import config
from src.match import to_binary_adaptive
from concurrent.futures import ThreadPoolExecutor, wait
Expand Down Expand Up @@ -36,15 +35,15 @@ def one_task(
]
image_path = f"{image_folder_path}/{name}.png"
binary = to_binary_adaptive(img, 11, 0)
kernel = np.ones((3, 3), np.uint8)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
binary_opn = cv2.morphologyEx(binary, cv2.MORPH_OPEN, kernel)
cv2.imwrite(image_path, binary_opn)
_lock.acquire()
_current_count += 1
percent = round(_current_count / total_fps * 100)
print(
f"\rPre-Progress:({_current_count}/{total_fps})" + "{}%: ".format(percent),
"" * (percent // 2),
"" * (percent // 2),
end="",
)
sys.stdout.flush()
Expand Down
5 changes: 3 additions & 2 deletions src/match.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import string
import cv2, cv2.typing
import numpy as np
from src.read_ini import config
Expand Down Expand Up @@ -29,7 +30,7 @@ def draw_text(
char_info: list[tuple[FreeTypeFont, int]] = []
text_height = int(0)
for char in text:
if char.encode("utf-8").isalpha():
if char.encode("utf-8").isalpha() or char in string.punctuation:
font = font_alpha
elif char.encode("utf-8").isdigit():
font = font_digit
Expand Down Expand Up @@ -60,7 +61,7 @@ def draw_text(
tmp_width = tmp_width + char_info[index][1] + kerning
binary: list[cv2.typing.MatLike] = []
mask: list[cv2.typing.MatLike] = []
kernel = np.ones((3, 3), np.uint8)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
if len(text) >= _half_split_length:
spilt_pixel = sum(
list(item[1] for item in char_info[: len(text) // 2]),
Expand Down

0 comments on commit 406e2d7

Please sign in to comment.