mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-15 22:19:18 +00:00
Fix: OCR_TRAILBLAZE_POWER length varies by value
This commit is contained in:
parent
7cfd305e15
commit
6d3f34ef48
Binary file not shown.
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 10 KiB |
@ -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
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user