From 689a93a3f7caa2a8e989e27f6e176df8764fb7bb Mon Sep 17 00:00:00 2001 From: Gleed Date: Thu, 23 Jun 2022 17:01:45 -0400 Subject: [PATCH] Bugfix: Make character name OCR not freeze program if fails, also improved read --- config/game.ini | 2 +- src/ui/character_select.py | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/config/game.ini b/config/game.ini index 211869a..3e6a288 100644 --- a/config/game.ini +++ b/config/game.ini @@ -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 diff --git a/src/ui/character_select.py b/src/ui/character_select.py index 6c5ebd0..b46df69 100644 --- a/src/ui/character_select.py +++ b/src/ui/character_select.py @@ -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