mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-27 03:48:21 +08:00
Upd: resize image in campaign bonus
This commit is contained in:
@@ -25,8 +25,8 @@ class CampaignBonusStatistics(GetItemsStatistics):
|
|||||||
if CAMPAIGN_BONUS_STRATEGY_CHECK.match(image, offset=(200, 500), similarity=similarity):
|
if CAMPAIGN_BONUS_STRATEGY_CHECK.match(image, offset=(200, 500), similarity=similarity):
|
||||||
return False
|
return False
|
||||||
if AUTO_SEARCH_MENU_EXIT.match(image, offset=(200, 20), similarity=similarity) \
|
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, 100), similarity=similarity) \
|
||||||
and CAMPAIGN_BONUS_SINGLE.match(image, offset=(200, 500), similarity=similarity)):
|
and CAMPAIGN_BONUS.match(image, offset=(200, 500), similarity=similarity):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class DropStatistics:
|
|||||||
TEMPLATE_FOLDER = 'item_templates'
|
TEMPLATE_FOLDER = 'item_templates'
|
||||||
TEMPLATE_BASIC = './assets/stats_basic'
|
TEMPLATE_BASIC = './assets/stats_basic'
|
||||||
SKIP_IMAGE_FOLDER = 'skip_images'
|
SKIP_IMAGE_FOLDER = 'skip_images'
|
||||||
|
IMAGE_EXTENSION = '.png'
|
||||||
CNOCR_CONTEXT = 'cpu'
|
CNOCR_CONTEXT = 'cpu'
|
||||||
CSV_FILE = 'drop_result.csv'
|
CSV_FILE = 'drop_result.csv'
|
||||||
CSV_OVERWRITE = True
|
CSV_OVERWRITE = True
|
||||||
@@ -94,6 +95,8 @@ class DropStatistics:
|
|||||||
"""
|
"""
|
||||||
Move a image file to {SKIP_IMAGE_FOLDER}/{CAMPAIGN}.
|
Move a image file to {SKIP_IMAGE_FOLDER}/{CAMPAIGN}.
|
||||||
"""
|
"""
|
||||||
|
if not self.SKIP_IMAGE_FOLDER:
|
||||||
|
return False
|
||||||
campaign = os.path.basename(os.path.abspath(os.path.join(file, '../')))
|
campaign = os.path.basename(os.path.abspath(os.path.join(file, '../')))
|
||||||
folder = self.skip_file_folder(campaign)
|
folder = self.skip_file_folder(campaign)
|
||||||
os.makedirs(folder, exist_ok=True)
|
os.makedirs(folder, exist_ok=True)
|
||||||
@@ -104,10 +107,10 @@ class DropStatistics:
|
|||||||
Extract template from a single file.
|
Extract template from a single file.
|
||||||
New templates will be given an auto-increased ID.
|
New templates will be given an auto-increased ID.
|
||||||
"""
|
"""
|
||||||
image = load_image(file)
|
images = unpack(load_image(file))[-1::]
|
||||||
similarity = get_similarity(image)
|
similarities = [get_similarity(image) for image in images]
|
||||||
images = unpack(image)[-1::]
|
images = [resize_image(image) for image in images]
|
||||||
for image in images:
|
for image, similarity in zip(images, similarities):
|
||||||
# if self.get_items.appear_on(image):
|
# if self.get_items.appear_on(image):
|
||||||
# self.get_items.extract_template(image, folder=self.template_folder)
|
# self.get_items.extract_template(image, folder=self.template_folder)
|
||||||
if self.campaign_bonus.appear_on(image, similarity=similarity):
|
if self.campaign_bonus.appear_on(image, similarity=similarity):
|
||||||
@@ -129,11 +132,11 @@ class DropStatistics:
|
|||||||
"""
|
"""
|
||||||
ts = os.path.splitext(os.path.basename(file))[0]
|
ts = os.path.splitext(os.path.basename(file))[0]
|
||||||
campaign = os.path.basename(os.path.abspath(os.path.join(file, '../')))
|
campaign = os.path.basename(os.path.abspath(os.path.join(file, '../')))
|
||||||
image = load_image(file)
|
images = unpack(load_image(file))[-1::]
|
||||||
similarity = get_similarity(image)
|
similarities = [get_similarity(image) for image in images]
|
||||||
images = unpack(image)[-1::]
|
images = [resize_image(image) for image in images]
|
||||||
enemy_name = 'unknown'
|
enemy_name = 'unknown'
|
||||||
for image in images:
|
for image, similarity in zip(images, similarities):
|
||||||
# if self.battle_status.appear_on(image):
|
# if self.battle_status.appear_on(image):
|
||||||
# enemy_name = self.battle_status.stats_battle_status(image)
|
# enemy_name = self.battle_status.stats_battle_status(image)
|
||||||
# if self.get_items.appear_on(image):
|
# if self.get_items.appear_on(image):
|
||||||
@@ -157,7 +160,8 @@ class DropStatistics:
|
|||||||
print('')
|
print('')
|
||||||
logger.hr(f'Extract templates from {campaign}', level=1)
|
logger.hr(f'Extract templates from {campaign}', level=1)
|
||||||
self.check_server(campaign)
|
self.check_server(campaign)
|
||||||
for ts, file in tqdm(load_folder(self.drop_folder(campaign), ext=['.png', '.jpg']).items()):
|
drop_folder = load_folder(self.drop_folder(campaign), ext=DropStatistics.IMAGE_EXTENSION)
|
||||||
|
for ts, file in tqdm(drop_folder.items()):
|
||||||
try:
|
try:
|
||||||
self.parse_template(file)
|
self.parse_template(file)
|
||||||
except ImageError as e:
|
except ImageError as e:
|
||||||
@@ -184,7 +188,8 @@ class DropStatistics:
|
|||||||
|
|
||||||
with open(self.csv_file, 'a', newline='', encoding=DropStatistics.CSV_ENCODING) as csv_file:
|
with open(self.csv_file, 'a', newline='', encoding=DropStatistics.CSV_ENCODING) as csv_file:
|
||||||
writer = csv.writer(csv_file)
|
writer = csv.writer(csv_file)
|
||||||
for ts, file in tqdm(load_folder(self.drop_folder(campaign), ext=['.png', '.jpg']).items()):
|
drop_folder = load_folder(self.drop_folder(campaign), ext=DropStatistics.IMAGE_EXTENSION)
|
||||||
|
for ts, file in tqdm(drop_folder.items()):
|
||||||
try:
|
try:
|
||||||
rows = list(self.parse_drop(file))
|
rows = list(self.parse_drop(file))
|
||||||
writer.writerows(rows)
|
writer.writerows(rows)
|
||||||
@@ -210,6 +215,8 @@ if __name__ == '__main__':
|
|||||||
# This will save images {DROP_FOLDER}/{SKIP_IMAGE_FOLDER}/{CAMPAIGN}.
|
# This will save images {DROP_FOLDER}/{SKIP_IMAGE_FOLDER}/{CAMPAIGN}.
|
||||||
# If folder doesn't exist, auto create
|
# If folder doesn't exist, auto create
|
||||||
DropStatistics.SKIP_IMAGE_FOLDER = 'skip_images'
|
DropStatistics.SKIP_IMAGE_FOLDER = 'skip_images'
|
||||||
|
# image file extension suck as '.png', '.jpg'
|
||||||
|
DropStatistics.IMAGE_EXTENSION = ['.png', '.jpg', '.PNG']
|
||||||
# 'cpu' or 'gpu', default to 'cpu'.
|
# 'cpu' or 'gpu', default to 'cpu'.
|
||||||
# Use 'gpu' for faster prediction, but you must have the gpu version of mxnet installed.
|
# Use 'gpu' for faster prediction, but you must have the gpu version of mxnet installed.
|
||||||
DropStatistics.CNOCR_CONTEXT = 'cpu'
|
DropStatistics.CNOCR_CONTEXT = 'cpu'
|
||||||
|
|||||||
@@ -66,18 +66,48 @@ def unpack(image):
|
|||||||
list: List of np.ndarray.
|
list: List of np.ndarray.
|
||||||
"""
|
"""
|
||||||
size = image_size(image)
|
size = image_size(image)
|
||||||
if size == (1280, 720):
|
if size == (1280, 720) or size[0] == round(size[1] * 16 / 9) \
|
||||||
|
or size[0] != 1280 or size[1] % 720 != 0:
|
||||||
return [image]
|
return [image]
|
||||||
elif size[0] / 1280 == size[1] / 720:
|
|
||||||
return [cv2.resize(image, (1280, 720), interpolation=cv2.INTER_LANCZOS4)]
|
|
||||||
else:
|
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)]
|
return [crop(image, (0, n * 720, 1280, (n + 1) * 720)) for n in range(size[1] // 720)]
|
||||||
|
|
||||||
|
|
||||||
|
def resize_image(image):
|
||||||
|
"""
|
||||||
|
Crop and resize to 1280x720.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
image:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
np.ndarray:
|
||||||
|
"""
|
||||||
|
size = image_size(image)
|
||||||
|
width, height = size
|
||||||
|
if size == (1280, 720):
|
||||||
|
return image
|
||||||
|
elif width == round(height * 16 / 9):
|
||||||
|
return cv2.resize(image, (1280, 720), interpolation=cv2.INTER_LANCZOS4)
|
||||||
|
elif width != 1280 or height % 720 != 0:
|
||||||
|
if width / height < 16 / 9:
|
||||||
|
crop_height = width * 9 / 16
|
||||||
|
y1 = round(height / 2 - crop_height / 2)
|
||||||
|
y2 = round(height / 2 + crop_height / 2)
|
||||||
|
crop_img = crop(image, (0, y1, width, y2))
|
||||||
|
else:
|
||||||
|
crop_width = height * 16 / 9
|
||||||
|
x1 = round(width / 2 - crop_width / 2)
|
||||||
|
x2 = round(width / 2 + crop_width / 2)
|
||||||
|
crop_img = crop(image, (x1, 0, x2, height))
|
||||||
|
return cv2.resize(crop_img, (1280, 720), interpolation=cv2.INTER_LANCZOS4)
|
||||||
|
else:
|
||||||
|
raise ImageInvalidResolution(f'Unexpected image size: {size}')
|
||||||
|
|
||||||
|
|
||||||
def get_similarity(image):
|
def get_similarity(image):
|
||||||
"""
|
"""
|
||||||
Get similarity to.
|
Get similarity from a image.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
image:
|
image:
|
||||||
@@ -88,9 +118,7 @@ def get_similarity(image):
|
|||||||
size = image_size(image)
|
size = image_size(image)
|
||||||
if size == (1280, 720):
|
if size == (1280, 720):
|
||||||
return 0.85
|
return 0.85
|
||||||
elif size[0] / 1280 == size[1] / 720:
|
elif size[0] == round(size[1] * 16 / 9) or size[0] != 1280 or size[1] % 720 != 0:
|
||||||
return 0.7
|
return 0.69
|
||||||
else:
|
else:
|
||||||
if size[0] != 1280 or size[1] % 720 != 0:
|
|
||||||
raise ImageInvalidResolution(f'Unexpected image size: {size}')
|
|
||||||
return 0.85
|
return 0.85
|
||||||
|
|||||||
Reference in New Issue
Block a user