1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-09 18:39:04 +08:00

Upd: resize and change similarity for 1920x1080 images in campaign

bonus
This commit is contained in:
sui-feng-cb 2025-12-03 13:46:26 +08:00
parent 49085b3e35
commit fa44b728bc
3 changed files with 35 additions and 9 deletions

View File

@ -15,12 +15,12 @@ class BonusItem(Item):
class CampaignBonusStatistics(GetItemsStatistics):
bonus_button: Button = CAMPAIGN_BONUS
def appear_on(self, image):
if CAMPAIGN_BONUS_STRATEGY_CHECK.match(image, offset=(200, 500)):
def appear_on(self, image, similarity=0.85):
if CAMPAIGN_BONUS_STRATEGY_CHECK.match(image, offset=(200, 500), similarity=similarity):
return False
if AUTO_SEARCH_MENU_EXIT.match(image, offset=(200, 20)) \
and (CAMPAIGN_BONUS.match(image, offset=(200, 500)) \
and CAMPAIGN_BONUS_SINGLE.match(image, offset=(200, 500))):
if AUTO_SEARCH_MENU_EXIT.match(image, offset=(200, 20), similarity=similarity) \
and (CAMPAIGN_BONUS.match(image, offset=(200, 500), similarity=similarity) \
and CAMPAIGN_BONUS_SINGLE.match(image, offset=(200, 500), similarity=similarity)):
return True
return False

View File

@ -82,11 +82,13 @@ class DropStatistics:
Extract template from a single file.
New templates will be given an auto-increased ID.
"""
images = unpack(load_image(file))[-1::]
image = load_image(file)
similarity = get_similarity(image)
images = unpack(image)[-1::]
for image in images:
# if self.get_items.appear_on(image):
# self.get_items.extract_template(image, folder=self.template_folder)
if self.campaign_bonus.appear_on(image):
if self.campaign_bonus.appear_on(image, similarity=similarity):
for button in [CAMPAIGN_BONUS_SINGLE, CAMPAIGN_BONUS]:
self.campaign_bonus.bonus_button = button
self.campaign_bonus.extract_template(image, folder=self.template_folder)
@ -105,7 +107,9 @@ class DropStatistics:
"""
ts = os.path.splitext(os.path.basename(file))[0]
campaign = os.path.basename(os.path.abspath(os.path.join(file, '../')))
images = unpack(load_image(file))[-1::]
image = load_image(file)
similarity = get_similarity(image)
images = unpack(image)[-1::]
enemy_name = 'unknown'
for image in images:
# if self.battle_status.appear_on(image):
@ -113,7 +117,7 @@ class DropStatistics:
# if self.get_items.appear_on(image):
# for item in self.get_items.stats_get_items(image):
# yield [ts, campaign, enemy_name, 'GET_ITEMS', item.name, item.amount]
if self.campaign_bonus.appear_on(image):
if self.campaign_bonus.appear_on(image, similarity=similarity):
for button in [CAMPAIGN_BONUS_SINGLE, CAMPAIGN_BONUS]:
self.campaign_bonus.bonus_button = button
for item in self.campaign_bonus.stats_get_items(image):

View File

@ -68,7 +68,29 @@ def unpack(image):
size = image_size(image)
if size == (1280, 720):
return [image]
elif size[0] / 1280 == size[1] / 720:
return [cv2.resize(image, (1280, 720), interpolation=cv2.INTER_LANCZOS4)]
else:
if size[0] != 1280 or size[1] % 720 != 0:
raise ImageInvalidResolution(f'Unexpected image size: {size}')
return [crop(image, (0, n * 720, 1280, (n + 1) * 720)) for n in range(size[1] // 720)]
def get_similarity(image):
"""
Get similarity to.
Args:
image:
Returns:
float: 0-1. Similarity.
"""
size = image_size(image)
if size == (1280, 720):
return 0.85
elif size[0] / 1280 == size[1] / 720:
return 0.7
else:
if size[0] != 1280 or size[1] % 720 != 0:
raise ImageInvalidResolution(f'Unexpected image size: {size}')
return 0.85