Skip to content

Commit

Permalink
Bugfix: Make character name OCR not freeze program if fails, also imp…
Browse files Browse the repository at this point in the history
…roved read
  • Loading branch information
aliig authored Jun 23, 2022
1 parent ac05683 commit ad3f1a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/game.ini
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ shrine_check=500,50,350,100
character_select=1033, 44, 226, 554
character_online_status=1033, 19, 226, 25
; character_sub_roi is with respect to matched active character template
character_name_sub_roi=6, 22, 186, 18
character_name_sub_roi=2, 20, 194, 22
cube_area_roi=167,209,113,152
cube_btn_roi=160,368,125,57
xp_bar_text=369,630,554,34
Expand Down
35 changes: 20 additions & 15 deletions src/ui/character_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,26 @@ def save_char_template():
x, y, w, h = Config().ui_roi["character_name_sub_roi"]
x, y = x + match.region[0], y + match.region[1]
char_template = cut_roi(img, [x, y, w, h])
ocr_result = ocr.image_to_text(
images = char_template,
model = "hover-eng_inconsolata_inv_th_fast",
psm = 6,
scale = 1.2,
crop_pad = False,
erode = False,
invert = False,
threshold = 0,
digits_only = False,
fix_regexps = False,
check_known_errors = False,
correct_words = False,
)[0]
Logger.debug(f"Saved character template: {ocr_result.text.splitlines()[0]}")
msg=""
try:
ocr_result = ocr.image_to_text(
images = cut_roi(img, [x, y, w, h]),
model = "hover-eng_inconsolata_inv_th_fast",
psm = 6,
scale = 1.2,
crop_pad = False,
erode = False,
invert = False,
threshold = 0,
digits_only = False,
fix_regexps = False,
check_known_errors = False,
correct_words = False,
)[0]
msg += f": {ocr_result.text.splitlines()[0]}"
except:
pass
Logger.debug(f"Saved character template{msg}")
else:
Logger.error("save_char_template: Could not save character template")
return
Expand Down

0 comments on commit ad3f1a6

Please sign in to comment.