diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 83d55cb0..96514be0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.9.2 + rev: v0.9.3 hooks: - id: ruff args: [--fix] diff --git a/dependencies/tesserocr-2.7.1-cp313-cp313-win_amd64.whl b/dependencies/tesserocr-2.7.1-cp313-cp313-win_amd64.whl index f7d9ffb5..851921b5 100644 Binary files a/dependencies/tesserocr-2.7.1-cp313-cp313-win_amd64.whl and b/dependencies/tesserocr-2.7.1-cp313-cp313-win_amd64.whl differ diff --git a/src/main.py b/src/main.py index 1b6dfa02..b15bea10 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ import tesserocr # noqa # Note: Somehow needed, otherwise the binary has an issue with tesserocr +from PIL import Image # noqa # Note: Somehow needed, otherwise the binary has an issue with tesserocr import logging import os import sys @@ -7,7 +8,6 @@ import keyboard from beautifultable import BeautifulTable -from PIL import Image # noqa # Note: Somehow needed, otherwise the binary has an issue with tesserocr import src.logger from src import __version__ diff --git a/src/utils/ocr/read.py b/src/utils/ocr/read.py index a7070d26..c8af0898 100644 --- a/src/utils/ocr/read.py +++ b/src/utils/ocr/read.py @@ -4,7 +4,7 @@ import cv2 import numpy as np -from tesserocr import OEM, RIL, PyTessBaseAPI +import tesserocr from src.config import BASE_DIR from src.config.data import COLORS @@ -24,13 +24,15 @@ def __init__(self): self._apis = [] self._lock = threading.Lock() - def get_api(self, user: uuid.UUID) -> PyTessBaseAPI: + def get_api(self, user: uuid.UUID) -> tesserocr.PyTessBaseAPI: with self._lock: for api in self._apis: if not api["user"]: api["user"] = user return api["api"] - new_api = PyTessBaseAPI(psm=3, oem=OEM.LSTM_ONLY, path=str(self.tessdata_path), lang=IniConfigLoader().general.language) + new_api = tesserocr.PyTessBaseAPI( + psm=3, oem=tesserocr.OEM.LSTM_ONLY, path=str(self.tessdata_path), lang=IniConfigLoader().general.language + ) new_api.SetVariable("debug_file", "/dev/null") self._apis.append({"api": new_api, "user": user}) return new_api @@ -69,7 +71,7 @@ def image_to_text(img: np.ndarray, line_boxes: bool = False, do_pre_proc: bool = text = api.GetUTF8Text().strip() res = OcrResult(original_text=text, text=text, word_confidences=api.AllWordConfidences(), mean_confidence=api.MeanTextConf()) if line_boxes: - line_boxes_res = api.GetComponentImages(RIL.TEXTLINE, True) + line_boxes_res = api.GetComponentImages(tesserocr.RIL.TEXTLINE, True) _APILoader().release_api(my_id) return res, line_boxes_res _APILoader().release_api(my_id) diff --git a/tests/assets/item/season5/1080p_small_read_descr_3.png b/tests/assets/item/season5/1080p_small_read_descr_3.png deleted file mode 100644 index 844240de..00000000 Binary files a/tests/assets/item/season5/1080p_small_read_descr_3.png and /dev/null differ diff --git a/tests/assets/item/season6/1440p_small_read_descr_2.png b/tests/assets/item/season6/1440p_small_read_descr_2.png deleted file mode 100644 index 80b9c6e2..00000000 Binary files a/tests/assets/item/season6/1440p_small_read_descr_2.png and /dev/null differ diff --git a/tests/item/read_descr_season5_test.py b/tests/item/read_descr_season5_test.py index 176d1e79..4b3e8624 100644 --- a/tests/item/read_descr_season5_test.py +++ b/tests/item/read_descr_season5_test.py @@ -263,23 +263,6 @@ rarity=ItemRarity.Mythic, ), ), - ( - (1920, 1080), - f"{BASE_PATH}/1080p_small_read_descr_3.png", - Item( - affixes=[ - Affix(name="maximum_life", value=950), - Affix(name="cooldown_reduction", value=9.1, type=AffixType.rerolled), - Affix(name="to_conjuration_mastery", value=2), - Affix(name="unstable_currents_cooldown_reduction", value=16.1, type=AffixType.tempered), - Affix(name="overpower_damage", value=80.5, type=AffixType.tempered), - ], - inherent=[Affix(name="resistance_to_all_elements", value=25, type=AffixType.inherent)], - item_type=ItemType.Amulet, - power=925, - rarity=ItemRarity.Legendary, - ), - ), ( (1920, 1080), f"{BASE_PATH}/1080p_small_read_descr_4.png", diff --git a/tests/item/read_descr_season6_test.py b/tests/item/read_descr_season6_test.py index b8b92ca3..40e44f97 100644 --- a/tests/item/read_descr_season6_test.py +++ b/tests/item/read_descr_season6_test.py @@ -59,23 +59,6 @@ rarity=ItemRarity.Unique, ), ), - ( - (2160, 1440), - f"{BASE_PATH}/1440p_small_read_descr_2.png", - Item( - affixes=[ - Affix(name="maximum_resource", value=8), - Affix(name="critical_strike_damage", value=76), - Affix(name="chance_for_core_skills_to_hit_twice", value=24), - Affix(name="to_velocity", value=3), - ], - aspect=Aspect(name="rod_of_kepeleke", value=2.2), - inherent=[Affix(name="block_chance", value=40, type=AffixType.inherent)], - item_type=ItemType.Quarterstaff, - power=750, - rarity=ItemRarity.Unique, - ), - ), ( (2160, 1440), f"{BASE_PATH}/1440p_small_read_descr_3.png",