Add: Detect trailblazers

This commit is contained in:
LmeSzinc 2023-11-10 23:35:53 +08:00
parent e3c65ffa46
commit 725c78212e
8 changed files with 88 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@ -13,3 +13,53 @@ OCR_MAP_CHARACTERS = ButtonWrapper(
button=(1041, 142, 1205, 436),
),
)
TRAILBLAZER_SEARCH = ButtonWrapper(
name='TRAILBLAZER_SEARCH',
share=Button(
file='./assets/share/character/switch/TRAILBLAZER_SEARCH.png',
area=(1151, 142, 1205, 436),
search=(1131, 122, 1225, 456),
color=(131, 127, 137),
button=(1151, 142, 1205, 436),
),
)
TrailblazerDestructionFemale = ButtonWrapper(
name='TrailblazerDestructionFemale',
share=Button(
file='./assets/share/character/switch/TrailblazerDestructionFemale.png',
area=(1170, 233, 1188, 251),
search=(1150, 213, 1208, 271),
color=(198, 180, 170),
button=(1170, 233, 1188, 251),
),
)
TrailblazerDestructionMale = ButtonWrapper(
name='TrailblazerDestructionMale',
share=Button(
file='./assets/share/character/switch/TrailblazerDestructionMale.png',
area=(1169, 156, 1187, 174),
search=(1149, 136, 1207, 194),
color=(196, 179, 170),
button=(1169, 156, 1187, 174),
),
)
TrailblazerPreservationFemale = ButtonWrapper(
name='TrailblazerPreservationFemale',
share=Button(
file='./assets/share/character/switch/TrailblazerPreservationFemale.png',
area=(1166, 243, 1184, 261),
search=(1146, 223, 1204, 281),
color=(194, 169, 155),
button=(1166, 243, 1184, 261),
),
)
TrailblazerPreservationMale = ButtonWrapper(
name='TrailblazerPreservationMale',
share=Button(
file='./assets/share/character/switch/TrailblazerPreservationMale.png',
area=(1171, 394, 1189, 412),
search=(1151, 374, 1209, 432),
color=(191, 166, 153),
button=(1171, 394, 1189, 412),
),
)

View File

@ -12,3 +12,6 @@ class CharacterList(Keyword):
@cached_property
def is_trailblazer(self) -> bool:
return 'Trailblazer' in self.name
def __hash__(self) -> int:
return super().__hash__()

View File

@ -5,10 +5,10 @@ from scipy import signal
from module.base.timer import Timer
from module.base.utils import area_center, crop, rgb2luma
from module.logger import logger
from module.ocr.ocr import OcrResultButton, OcrWhiteLetterOnComplexBackground
from module.ocr.ocr import BoxedResult, OcrResultButton, OcrWhiteLetterOnComplexBackground
from tasks.base.ui import UI
from tasks.character.assets.assets_character_switch import OCR_MAP_CHARACTERS
from tasks.character.keywords import CharacterList, DICT_SORTED_RANGES
from tasks.character.assets.assets_character_switch import *
from tasks.character.keywords import CharacterList, DICT_SORTED_RANGES, KEYWORD_CHARACTER_LIST
class OcrCharacterName(OcrWhiteLetterOnComplexBackground):
@ -32,14 +32,45 @@ class CharacterSwitch(UI):
- self.characters
- self.character_current
- self.character_buttons
Pages:
in: page_main
"""
ocr = OcrCharacterName(OCR_MAP_CHARACTERS)
self.character_buttons = ocr.matched_ocr(self.device.image, keyword_classes=CharacterList)
buttons = ocr.matched_ocr(self.device.image, keyword_classes=CharacterList)
if trailblazer := self._get_character_trailblazer():
buttons.append(trailblazer)
buttons = sorted(buttons, key=lambda b: area_center(b.area)[1])
self.character_buttons = buttons
self.characters = [button.matched_keyword for button in self.character_buttons]
logger.attr('Characters', self.characters)
self.character_current = self._convert_selected_to_character(self._update_current_character())
return self.characters
def _get_character_trailblazer(self) -> OcrResultButton | None:
dict_template = {
KEYWORD_CHARACTER_LIST.TrailblazerDestruction: [
TrailblazerDestructionMale,
TrailblazerDestructionFemale,
],
KEYWORD_CHARACTER_LIST.TrailblazerPreservation: [
TrailblazerPreservationMale,
TrailblazerPreservationFemale,
],
}
for character, templates in dict_template.items():
for template in templates:
template.load_search(TRAILBLAZER_SEARCH.area)
if template.match_template(self.device.image):
logger.info(f'Found trailblazer: {template}')
# Create a fake OcrResultButton object
box = BoxedResult(box=template.button, text_img=None, ocr_text='', score=1.0)
button = OcrResultButton(boxed_result=box, matched_keyword=character)
return button
return None
def _update_current_character(self) -> list[int]:
"""
Returns: