mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-21 16:28:17 +00:00
Fix: [EN] OCR on SoulGladScorchsandAuditionVenue
This commit is contained in:
parent
be2655db6e
commit
4da677a084
@ -51,6 +51,47 @@ def _merge_boxed_result(left: BoxedResult, right: BoxedResult) -> BoxedResult:
|
|||||||
return left
|
return left
|
||||||
|
|
||||||
|
|
||||||
|
def merge_result_button(
|
||||||
|
results: list[BoxedResult],
|
||||||
|
left_func: callable,
|
||||||
|
right_func: callable,
|
||||||
|
text_func: callable
|
||||||
|
) -> list[BoxedResult]:
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
results:
|
||||||
|
left_func: Function that inputs ocr_text (str) and outputs bool
|
||||||
|
True means mark as left text
|
||||||
|
right_func:
|
||||||
|
text_func: Function that inputs left_text (str) right_text (str) and outputs text (str)
|
||||||
|
"""
|
||||||
|
left = None
|
||||||
|
right = None
|
||||||
|
for result in results:
|
||||||
|
if left_func(result.ocr_text):
|
||||||
|
left = result
|
||||||
|
elif right_func(result.ocr_text):
|
||||||
|
right = result
|
||||||
|
|
||||||
|
text = text_func(
|
||||||
|
left.ocr_text if left is not None else '',
|
||||||
|
right.ocr_text if right is not None else ''
|
||||||
|
)
|
||||||
|
if left is not None:
|
||||||
|
if right is not None:
|
||||||
|
results.remove(right)
|
||||||
|
left.box = _merge_area(left.box, right.box)
|
||||||
|
left.ocr_text = text
|
||||||
|
else:
|
||||||
|
left.ocr_text = text
|
||||||
|
else:
|
||||||
|
if right is not None:
|
||||||
|
right.ocr_text = text
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
def merge_buttons(buttons: list[BoxedResult], thres_x=20, thres_y=20) -> list[BoxedResult]:
|
def merge_buttons(buttons: list[BoxedResult], thres_x=20, thres_y=20) -> list[BoxedResult]:
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
|
@ -23,6 +23,10 @@ class OcrPlaneName(OcrWhiteLetterOnComplexBackground):
|
|||||||
result = result.replace('avatia', 'avalia')
|
result = result.replace('avatia', 'avalia')
|
||||||
# 苏乐达™热砂海选会场
|
# 苏乐达™热砂海选会场
|
||||||
result = re.sub(r'(苏乐达|蘇樂達|SoulGlad|スラーダ|FelizAlma)[rtT]*M*', r'\1', result)
|
result = re.sub(r'(苏乐达|蘇樂達|SoulGlad|スラーダ|FelizAlma)[rtT]*M*', r'\1', result)
|
||||||
|
# SoulGladtM Scorchsand Audition Ven
|
||||||
|
if 'Audition' in result:
|
||||||
|
right = result.find('Audition') + len('Audition')
|
||||||
|
result = result[:right] + ' Venue'
|
||||||
# 幽囚狱
|
# 幽囚狱
|
||||||
result = result.replace('幽因狱', '幽囚狱')
|
result = result.replace('幽因狱', '幽囚狱')
|
||||||
result = result.replace('幽因獄', '幽囚獄')
|
result = result.replace('幽因獄', '幽囚獄')
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
from copy import copy
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
from pponnxcr.predict_system import BoxedResult
|
from pponnxcr.predict_system import BoxedResult
|
||||||
@ -10,7 +11,7 @@ from module.base.timer import Timer
|
|||||||
from module.base.utils import area_center, area_limit, area_offset, crop, image_size
|
from module.base.utils import area_center, area_limit, area_offset, crop, image_size
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from module.ocr.ocr import Ocr, OcrResultButton
|
from module.ocr.ocr import Ocr, OcrResultButton
|
||||||
from module.ocr.utils import split_and_pair_button_attr, split_and_pair_buttons
|
from module.ocr.utils import merge_result_button, split_and_pair_button_attr, split_and_pair_buttons
|
||||||
from module.ui.draggable_list import DraggableList
|
from module.ui.draggable_list import DraggableList
|
||||||
from module.ui.switch import Switch
|
from module.ui.switch import Switch
|
||||||
from tasks.base.page import page_guide
|
from tasks.base.page import page_guide
|
||||||
@ -40,6 +41,7 @@ class OcrDungeonName(Ocr):
|
|||||||
# 苏乐达™热砂海选会场
|
# 苏乐达™热砂海选会场
|
||||||
result = re.sub(r'(苏乐达|蘇樂達|SoulGlad|スラーダ|FelizAlma)[rtT]*M*', r'\1', result)
|
result = re.sub(r'(苏乐达|蘇樂達|SoulGlad|スラーダ|FelizAlma)[rtT]*M*', r'\1', result)
|
||||||
result = re.sub(r'["\']', '', result)
|
result = re.sub(r'["\']', '', result)
|
||||||
|
result = re.sub('Aud[it]+on', 'Audition', result)
|
||||||
|
|
||||||
result = super().after_process(result)
|
result = super().after_process(result)
|
||||||
|
|
||||||
@ -106,6 +108,17 @@ class OcrDungeonList(OcrDungeonName):
|
|||||||
else:
|
else:
|
||||||
result.box = area_offset(result.box, offset=OCR_DUNGEON_NAME.area[:2])
|
result.box = area_offset(result.box, offset=OCR_DUNGEON_NAME.area[:2])
|
||||||
|
|
||||||
|
before = copy(results)
|
||||||
|
# Calyx_Crimson_The_Hunt_Penacony_SoulGladScorchsandAuditionVenue
|
||||||
|
merge_result_button(
|
||||||
|
results,
|
||||||
|
left_func=lambda x: 'Audition' in x,
|
||||||
|
right_func=lambda x: 'Venue' in x,
|
||||||
|
text_func=lambda l, r: f'SoulGladScorchsandAuditionVenue'
|
||||||
|
)
|
||||||
|
if results != before:
|
||||||
|
logger.attr(name=self.name,
|
||||||
|
text=str([result.ocr_text for result in results]))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _match_result(self, *args, **kwargs):
|
def _match_result(self, *args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user