From 6dbc96e13dbca86ca01e767401ae5698c92302f9 Mon Sep 17 00:00:00 2001 From: ThatOneGuyScripts <125089137+ThatOneGuyScripts@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:42:02 -0500 Subject: [PATCH] issue found with certain texts using bold12 Issues found when searching text using bold12 limiting the cropping to 1 for all texts other than plain_12 which will crop 2 rows of pixels. --- src/utilities/ocr.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utilities/ocr.py b/src/utilities/ocr.py index 5ff8bc71..69c0bf07 100644 --- a/src/utilities/ocr.py +++ b/src/utilities/ocr.py @@ -36,7 +36,7 @@ def __load_font(font: str) -> Dict[str, cv2.Mat]: QUILL_8 = __load_font("Quill8") # Small quest text -def extract_text(rect: Rectangle, font: dict, color: Union[clr.Color, List[clr.Color]], exclude_chars: Union[List[str], str] = "") -> str: +def extract_text(rect: Rectangle, font: dict, color, exclude_chars: Union[List[str], str] = "") -> str: """ Extracts text from a Rectangle. Args: @@ -54,8 +54,12 @@ def extract_text(rect: Rectangle, font: dict, color: Union[clr.Color, List[clr.C for key in font: if key == " " or key in exclude_chars: continue + if font is PLAIN_12: + correlation = cv2.matchTemplate(image, font[key][2:], cv2.TM_CCOEFF_NORMED) + else: + correlation = cv2.matchTemplate(image, font[key][1:], cv2.TM_CCOEFF_NORMED) # Template match the character in the image - correlation = cv2.matchTemplate(image, font[key][2:], cv2.TM_CCOEFF_NORMED) + #correlation = cv2.matchTemplate(image, font[key][2:], cv2.TM_CCOEFF_NORMED) # Locate the start point for each instance of this character y_mins, x_mins = np.where(correlation >= 0.98) # For each instance of this character, add it to the list @@ -91,7 +95,10 @@ def find_text( char_list = [] for char in chars: try: - template = font[char][2:] + if font is PLAIN_12: + template = font[char][2:] + else: + template = font[char][1:] except KeyError: text = text.replace(char, "") # Remove characters that aren't in the font print(f"Font does not contain character: {char}. Omitting from search.")