mirror of
https://github.com/sui-feng-cb/AzurLaneAutoScript1.git
synced 2026-08-16 20:10:29 +08:00
Fix: IslandReversedDigitCounter safe after_process
This commit is contained in:
@@ -85,31 +85,32 @@ class IslandReversedDigitCounter(Ocr):
|
|||||||
sub_image = extract_letters(image, letter=self.sub_letter, threshold=self.sub_threshold)
|
sub_image = extract_letters(image, letter=self.sub_letter, threshold=self.sub_threshold)
|
||||||
cv2.bitwise_and(main_image, sub_image, dst=main_image)
|
cv2.bitwise_and(main_image, sub_image, dst=main_image)
|
||||||
|
|
||||||
|
main_image = cv2.copyMakeBorder(main_image, 2, 4, 0, 0, cv2.BORDER_CONSTANT, value=(255, 255, 255))
|
||||||
|
|
||||||
return main_image
|
return main_image
|
||||||
|
|
||||||
def after_process(self, result):
|
def after_process(self, result):
|
||||||
result = super().after_process(result)
|
result = super().after_process(result)
|
||||||
result = result.replace('I', '1').replace('D', '0').replace('S', '5')
|
result = result.replace('I', '1').replace('D', '0').replace('S', '5')
|
||||||
result = result.replace('B', '8')
|
result = result.replace('B', '8')
|
||||||
if re.fullmatch(r'\d+/?', result):
|
if re.fullmatch(r'[0-9]+/?', result):
|
||||||
normalized = f'{result.rstrip("/")}/0'
|
normalized = f'{result.rstrip("/")}/0'
|
||||||
logger.warning(f'Unexpected ocr result: {result}, normalized to {normalized}')
|
logger.warning(f'Unexpected ocr result: {result}, normalized to {normalized}')
|
||||||
result = normalized
|
result = normalized
|
||||||
result = re.search(r'(\d+)/([\d+\-\*\(\)]+)', result)
|
# Accept only "total/current" or "total/(current+bonus)". The last
|
||||||
if result:
|
# capture handles a direct current value; the middle two are summed.
|
||||||
numerator = int(result.group(1))
|
match = re.fullmatch(r'([0-9]+)/(?:\(([0-9]+)\+([0-9]+)\)|([0-9]+))', result)
|
||||||
denominator_str = result.group(2)
|
if not match:
|
||||||
try:
|
|
||||||
denominator = eval(denominator_str)
|
|
||||||
current, total = denominator, numerator
|
|
||||||
return total, current, total - current
|
|
||||||
except (ValueError, SyntaxError):
|
|
||||||
logger.warning(f'Unexpected ocr result: {result.group(0)}')
|
|
||||||
return 0, 0, 0
|
|
||||||
else:
|
|
||||||
logger.warning(f'Unexpected ocr result: {result}')
|
logger.warning(f'Unexpected ocr result: {result}')
|
||||||
return 0, 0, 0
|
return 0, 0, 0
|
||||||
|
|
||||||
|
total = int(match.group(1))
|
||||||
|
if match.group(4) is not None:
|
||||||
|
current = int(match.group(4))
|
||||||
|
else:
|
||||||
|
current = int(match.group(2)) + int(match.group(3))
|
||||||
|
return total, current, total - current
|
||||||
|
|
||||||
|
|
||||||
RECIPE_INGREDIENT_COUNTER_OCR = IslandReversedDigitCounter(
|
RECIPE_INGREDIENT_COUNTER_OCR = IslandReversedDigitCounter(
|
||||||
[], lang='cnocr', letter=(255, 255, 255), sub_letter=(253, 171, 34),
|
[], lang='cnocr', letter=(255, 255, 255), sub_letter=(253, 171, 34),
|
||||||
|
|||||||
Reference in New Issue
Block a user