From 6d3f34ef488a6138d5fb99b3f67b35989a974e49 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sat, 17 Jun 2023 16:19:13 +0800 Subject: [PATCH] Fix: OCR_TRAILBLAZE_POWER length varies by value --- .../combat/prepare/OCR_TRAILBLAZE_POWER.png | Bin 8498 -> 10207 bytes module/ocr/ocr.py | 11 +++++++++-- tasks/combat/assets/assets_combat_prepare.py | 8 ++++---- tasks/combat/prepare.py | 13 ++++++++++++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/assets/share/combat/prepare/OCR_TRAILBLAZE_POWER.png b/assets/share/combat/prepare/OCR_TRAILBLAZE_POWER.png index 5ecfd9c558aede7e0e23cc3c0c487b13a7d4f75d..8fe06b9b76b95459ffbeb20606f92b1877e26ddb 100644 GIT binary patch delta 4921 zcmX9>d05g}+h*Qo^n0_(u}#a;H>IpJNps7MNiii;%iI^N%-u9s6qMi0_*pKg1BQks zj1`*UlH#sNi%aH0F1RbXAa1yWf&w4C-}&=A=Q`K*T+jX7OO*x7;XUmjaOMykcHJp% zY-KY3y_ajE#yX2eL(;88)oV?Lqg8$<6=jr_aj75gy&U=X75z6K-0wM_d|^bmb%{{& z=Da>W@9P`?ce=o>Cw~uupC3?qF#G!v%l}+IFB2Mn^nV~#=iDiNa0gTf9kEsbRk`yF z+^wshS|&&kqt>RPR<9)r#eKi9%!?Tr+4mLi1HE{qe}O=8`kK#|SnOM3vt@0ilcFzc zm;`n|bJ;(qU6q>;HPZD+@rS5#$(Ew2k!U^RJEvhVh-N`>mU$HFvtgrVQHYMNu3J+h zvMYmZaS^W8No__NWu$13ruJl2={wZ?|riDEdNy- zPk+B2T{!{IzJ9I5X|pic#bF>LNY^7X#pa+6^gv_W$NmcQEvK9}vk-1#+t0*j&z>EU zm)C&zFY|gm@5TK%^^PUmdm=3~*~rY))YRB`>_@58P3uH@TgsO$VC#^5jmMdjCrex? ztTMb~iJtUDpk9loE2qPh@r!ua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W=LFF(Q%GKJlQ~bDKZB_gpl&Hz}{B0;Ji{JSbxG0JQ5b~ z|1Rcbq-}Dj87W_loFa;^(hpQ-6rrn 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