Fix: Getting the correct planner lang

This commit is contained in:
LmeSzinc 2024-07-02 04:05:11 +08:00
parent 4d4c65f9b5
commit 4ea4946a58

View File

@ -3,6 +3,7 @@ import re
import cv2 import cv2
from pponnxcr.predict_system import BoxedResult from pponnxcr.predict_system import BoxedResult
from module.base.decorator import cached_property
from module.base.utils import area_center, area_in_area from module.base.utils import area_center, area_in_area
from module.exception import GamePageUnknownError from module.exception import GamePageUnknownError
from module.logger import logger from module.logger import logger
@ -40,11 +41,27 @@ class OcrItemName(Ocr):
class OcrPlannerResult(OcrWhiteLetterOnComplexBackground, OcrItemName): class OcrPlannerResult(OcrWhiteLetterOnComplexBackground, OcrItemName):
min_box = (16, 20) min_box = (16, 20)
def __init__(self): def __init__(self, lang=None):
super().__init__(OCR_RESULT) super().__init__(OCR_RESULT, lang=lang)
self.limited_area = OCR_RESULT.area self.limited_area = OCR_RESULT.area
self.limit_y = 720 self.limit_y = 720
def _match_result(
self,
result: str,
keyword_classes,
lang: str = None,
ignore_punctuation=True,
ignore_digit=True):
lang = self.lang
return super()._match_result(
result,
keyword_classes,
lang,
ignore_punctuation,
ignore_digit,
)
def filter_detected(self, result: BoxedResult) -> bool: def filter_detected(self, result: BoxedResult) -> bool:
if not area_in_area(result.box, self.limited_area, threshold=0): if not area_in_area(result.box, self.limited_area, threshold=0):
return False return False
@ -77,12 +94,24 @@ class PlannerScan(SynthesizeUI, PlannerMixin):
return True return True
return False return False
@cached_property
def planner_lang(self) -> str:
if self.config.Emulator_PackageName in ['CN-Official', 'CN-Bilibili']:
lang = 'cn'
else:
lang = self.config.LANG
if lang == 'auto':
logger.error('Language was not set before planner scan, assume it is "cn"')
lang = 'cn'
logger.attr('PlannerLang', lang)
return lang
def parse_planner_result_page(self) -> list[PlannerResultRow]: def parse_planner_result_page(self) -> list[PlannerResultRow]:
""" """
Pages: Pages:
in: planner result in: planner result
""" """
ocr = OcrPlannerResult() ocr = OcrPlannerResult(lang=self.planner_lang)
results = ocr.detect_and_ocr(self.device.image) results = ocr.detect_and_ocr(self.device.image)
x_total = 842 x_total = 842