diff --git a/assets/share/combat/prepare/OCR_TRAILBLAZE_POWER.png b/assets/share/combat/prepare/OCR_TRAILBLAZE_POWER.png index 5ecfd9c55..8fe06b9b7 100644 Binary files a/assets/share/combat/prepare/OCR_TRAILBLAZE_POWER.png and b/assets/share/combat/prepare/OCR_TRAILBLAZE_POWER.png differ diff --git a/module/ocr/ocr.py b/module/ocr/ocr.py index bf3b69372..a0964e1a8 100644 --- a/module/ocr/ocr.py +++ b/module/ocr/ocr.py @@ -133,6 +133,12 @@ class Ocr: result = 'UID' return result + def format_result(self, result): + """ + Will be overriden. + """ + return result + def ocr_single_line(self, image): # pre process start_time = time.time() @@ -142,6 +148,7 @@ class Ocr: result, _ = self.model.ocr_single_line(image) # after proces result = self.after_process(result) + result = self.format_result(result) logger.attr(name='%s %ss' % (self.name, float2str(time.time() - start_time)), text=str(result)) return result @@ -211,7 +218,7 @@ class Digit(Ocr): def __init__(self, button: ButtonWrapper, lang='ch', name=None): super().__init__(button, lang=lang, name=name) - def after_process(self, result) -> int: + def format_result(self, result) -> int: """ Returns: int: @@ -231,7 +238,7 @@ class DigitCounter(Ocr): def __init__(self, button: ButtonWrapper, lang='ch', name=None): super().__init__(button, lang=lang, name=name) - def after_process(self, result) -> tuple[int, int, int]: + def format_result(self, result) -> tuple[int, int, int]: """ Do OCR on a counter, such as `14/15`, and returns 14, 1, 15 diff --git a/tasks/combat/assets/assets_combat_prepare.py b/tasks/combat/assets/assets_combat_prepare.py index d5d8f85a4..fd114f38f 100644 --- a/tasks/combat/assets/assets_combat_prepare.py +++ b/tasks/combat/assets/assets_combat_prepare.py @@ -17,10 +17,10 @@ OCR_TRAILBLAZE_POWER = ButtonWrapper( name='OCR_TRAILBLAZE_POWER', share=Button( file='./assets/share/combat/prepare/OCR_TRAILBLAZE_POWER.png', - area=(1043, 26, 1131, 48), - search=(1023, 6, 1151, 68), - color=(43, 46, 53), - button=(1043, 26, 1131, 48), + area=(998, 26, 1130, 48), + search=(978, 6, 1150, 68), + color=(77, 76, 87), + button=(998, 26, 1130, 48), ), ) OCR_WAVE_COUNT = ButtonWrapper( diff --git a/tasks/combat/prepare.py b/tasks/combat/prepare.py index 7224d3263..866bd22b1 100644 --- a/tasks/combat/prepare.py +++ b/tasks/combat/prepare.py @@ -1,3 +1,5 @@ +import re + from module.base.timer import Timer from module.ocr.ocr import Digit, DigitCounter from tasks.base.ui import UI @@ -9,6 +11,15 @@ from tasks.combat.assets.assets_combat_prepare import ( ) +class TrailblazePowerOcr(DigitCounter): + def after_process(self, result): + result = super().after_process(result) + # The trailblaze power icon is recognized as 买 + # OCR_TRAILBLAZE_POWER includes the icon because the length varies by value + result = re.sub(r'[买米装:()]', '', result) + return result + + class CombatPrepare(UI): def combat_set_wave(self, count=6): """ @@ -47,7 +58,7 @@ class CombatPrepare(UI): else: self.device.screenshot() - current, _, _ = DigitCounter(OCR_TRAILBLAZE_POWER).ocr_single_line(self.device.image) + current, _, _ = TrailblazePowerOcr(OCR_TRAILBLAZE_POWER).ocr_single_line(self.device.image) # Confirm if it is > 180, sometimes just OCR errors if current > 180 and timeout.reached(): break