mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-19 02:33:34 +08:00
Fix: Handle new stage entrance icon
- Fix in_stage detection on slow pc
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
from module.base.button import Button
|
||||
from module.logger import logger
|
||||
from module.base.decorator import Config
|
||||
from module.campaign.campaign_ocr import CampaignOcr
|
||||
from module.exception import CampaignEnd, ScriptError, MapEnemyMoved
|
||||
from module.logger import logger
|
||||
from module.map.map import Map
|
||||
from module.map.map_base import CampaignMap
|
||||
from module.base.decorator import Config
|
||||
|
||||
|
||||
class CampaignBase(Map):
|
||||
class CampaignBase(Map, CampaignOcr):
|
||||
FUNCTION_NAME_BASE = 'battle_'
|
||||
ENTRANCE = Button(area=(), color=(), button=(), name='default_button')
|
||||
MAP: CampaignMap
|
||||
|
||||
@@ -2,12 +2,14 @@ import collections
|
||||
|
||||
import numpy as np
|
||||
|
||||
from module.base.base import ModuleBase
|
||||
from module.base.decorator import Config
|
||||
from module.base.utils import extract_letters, area_offset
|
||||
from module.base.utils import *
|
||||
from module.exception import CampaignNameError
|
||||
from module.logger import logger
|
||||
from module.map_detection.utils import Points
|
||||
from module.ocr.ocr import Ocr
|
||||
from module.template.assets import TEMPLATE_STAGE_CLEAR, TEMPLATE_STAGE_PERCENT, Button
|
||||
from module.template.assets import *
|
||||
|
||||
|
||||
def ensure_chapter_index(name):
|
||||
@@ -60,16 +62,17 @@ def separate_name(name):
|
||||
return name[0], name[1:]
|
||||
|
||||
|
||||
class CampaignOcr:
|
||||
class CampaignOcr(ModuleBase):
|
||||
stage_entrance = {}
|
||||
campaign_chapter = 0
|
||||
|
||||
def campaign_match_multi(self, template, image, name_offset=(75, 9), name_size=(60, 16),
|
||||
def campaign_match_multi(self, template, image, stage_image=None, name_offset=(75, 9), name_size=(60, 16),
|
||||
name_letter=(255, 255, 255), name_thresh=128):
|
||||
"""
|
||||
Args:
|
||||
template (Template):
|
||||
image: Screenshot
|
||||
stage_image: Screenshot to find stage entrance.
|
||||
name_offset (tuple[int]):
|
||||
name_size (tuple[int]):
|
||||
name_letter (tuple[int]):
|
||||
@@ -79,8 +82,9 @@ class CampaignOcr:
|
||||
list[Button]: Stage clear buttons.
|
||||
"""
|
||||
digits = []
|
||||
color = tuple(np.mean(np.mean(template.image, axis=0), axis=0))
|
||||
result = template.match_multi(image, similarity=0.95)
|
||||
stage_image = image if stage_image is None else stage_image
|
||||
result = template.match_multi(stage_image, similarity=0.85)
|
||||
result = Points(result, config=self.config).group()
|
||||
|
||||
for point in result:
|
||||
point = point[::-1]
|
||||
@@ -89,30 +93,44 @@ class CampaignOcr:
|
||||
name = image.crop(np.append(point, point + name_size))
|
||||
name = extract_letters(name, letter=name_letter, threshold=name_thresh)
|
||||
stage = self._extract_stage_name(name)
|
||||
digits.append(
|
||||
Button(area=area_offset(stage, point), color=color, button=button, name='stage'))
|
||||
|
||||
area = area_offset(stage, point)
|
||||
color = get_color(image, area)
|
||||
digits.append(Button(area=area, color=color, button=button, name='stage'))
|
||||
|
||||
return digits
|
||||
|
||||
@Config.when(SERVER='en')
|
||||
def campaign_extract_name_image(self, image):
|
||||
digits = []
|
||||
digits += self.campaign_match_multi(TEMPLATE_STAGE_CLEAR, image, name_offset=(70, 12), name_size=(60, 14))
|
||||
digits += self.campaign_match_multi(TEMPLATE_STAGE_PERCENT, image, name_offset=(45, 3), name_size=(60, 14))
|
||||
|
||||
if len(digits) == 0:
|
||||
logger.warning('No stage found.')
|
||||
if 'normal' in self.config.STAGE_ENTRANCE:
|
||||
digits += self.campaign_match_multi(TEMPLATE_STAGE_CLEAR, image, name_offset=(70, 12), name_size=(60, 14))
|
||||
digits += self.campaign_match_multi(TEMPLATE_STAGE_PERCENT, image, name_offset=(45, 3), name_size=(60, 14))
|
||||
if 'blue' in self.config.STAGE_ENTRANCE:
|
||||
digits += self.campaign_match_multi(
|
||||
TEMPLATE_STAGE_BLUE_PERCENT, image, extract_letters(image, letter=(255, 255, 255), threshold=153),
|
||||
name_offset=(55, 0), name_size=(60, 16))
|
||||
digits += self.campaign_match_multi(
|
||||
TEMPLATE_STAGE_BLUE_CLEAR, image, extract_letters(image, letter=(99, 223, 239), threshold=153),
|
||||
name_offset=(60, 12), name_size=(60, 16))
|
||||
|
||||
return digits
|
||||
|
||||
@Config.when(SERVER=None)
|
||||
def campaign_extract_name_image(self, image):
|
||||
digits = []
|
||||
digits += self.campaign_match_multi(TEMPLATE_STAGE_CLEAR, image, name_offset=(75, 9), name_size=(60, 16))
|
||||
digits += self.campaign_match_multi(TEMPLATE_STAGE_PERCENT, image, name_offset=(48, 0), name_size=(60, 16))
|
||||
|
||||
if len(digits) == 0:
|
||||
logger.warning('No stage found.')
|
||||
if 'normal' in self.config.STAGE_ENTRANCE:
|
||||
digits += self.campaign_match_multi(TEMPLATE_STAGE_CLEAR, image, name_offset=(75, 9), name_size=(60, 16))
|
||||
digits += self.campaign_match_multi(TEMPLATE_STAGE_PERCENT, image, name_offset=(48, 0), name_size=(60, 16))
|
||||
if 'blue' in self.config.STAGE_ENTRANCE:
|
||||
digits += self.campaign_match_multi(
|
||||
TEMPLATE_STAGE_BLUE_PERCENT, image, extract_letters(image, letter=(255, 255, 255), threshold=153),
|
||||
name_offset=(55, 0), name_size=(60, 16))
|
||||
digits += self.campaign_match_multi(
|
||||
TEMPLATE_STAGE_BLUE_CLEAR, image, extract_letters(image, letter=(99, 223, 239), threshold=153),
|
||||
name_offset=(60, 12), name_size=(60, 16))
|
||||
|
||||
return digits
|
||||
|
||||
@@ -165,8 +183,10 @@ class CampaignOcr:
|
||||
def _get_stage_name(self, image):
|
||||
self.stage_entrance = {}
|
||||
buttons = self.campaign_extract_name_image(image)
|
||||
if len(buttons) == 0:
|
||||
logger.warning('No stage found.')
|
||||
|
||||
ocr = Ocr(buttons, name='campaign', letter=(255, 255, 255), threshold=128, alphabet='0123456789ABCDEFSP-')
|
||||
ocr = Ocr(buttons, name='campaign', letter=(255, 255, 255), threshold=128, alphabet='0123456789ABCDEFSPHT-')
|
||||
result = ocr.ocr(image)
|
||||
if not isinstance(result, list):
|
||||
result = [result]
|
||||
|
||||
Reference in New Issue
Block a user