1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-09 16:19:03 +08:00
AzurLaneAutoScript/dev_tools/relative_record_gif.py

60 lines
1.8 KiB
Python
Raw Permalink Normal View History

2020-07-24 11:13:23 +08:00
import os
import imageio
from PIL import Image
import module.config.server as server
server.server = 'cn' # Don't need to edit, it's used to avoid error.
2022-04-15 03:37:54 +08:00
from dev_tools.relative_record import FOLDER, NAME
2020-07-24 11:13:23 +08:00
from module.base.utils import *
from module.map_detection.utils import *
"""
Usage:
See relative_record.py
Arguments:
FOLDER: Save folder from relative_record.
NAME: Siren name from relative_record.
Save gif file to <FOLDER>/TEMPLATE_SIREN_<NAME>.gif
2020-07-24 11:13:23 +08:00
AREA: Area to crop, such as (32, 32, 54, 52).
Choose an area where things don't rotate too much.
THRESHOLD: If the similarity between a template and existing templates greater than THRESHOLD,
this template will be dropped.
Threshold in real detection is 0.85, for higher accuracy, threshold here should higher than 0.85.
"""
# FOLDER = ''
# NAME = 'Deutschland'
2024-06-28 03:19:37 +08:00
AREA = (32, 32, 54, 52)
THRESHOLD = 0.92
2020-07-24 11:13:23 +08:00
if __name__ == '__main__':
images = [np.array(Image.open(os.path.join(FOLDER, NAME, file))) for file in os.listdir(os.path.join(FOLDER, NAME))
if file[-4:] == '.png']
templates = [crop(images[0], area=AREA)]
2020-07-24 11:13:23 +08:00
def match(im):
max_sim = 0
max_loca = (0, 0)
for template in templates:
res = cv2.matchTemplate(im, template, cv2.TM_CCOEFF_NORMED)
_, sim, _, loca = cv2.minMaxLoc(res)
if sim > max_sim:
max_sim = sim
max_loca = loca
2020-07-24 11:13:23 +08:00
return max_sim, max_loca
2020-07-24 11:13:23 +08:00
for n, image in enumerate(images):
sim, loca = match(image)
if sim > THRESHOLD:
continue
print(f'New template: {n}')
templates.append(crop(image, area=area_offset(AREA, np.subtract(loca, AREA[:2]))))
2020-07-24 11:13:23 +08:00
imageio.mimsave(os.path.join(FOLDER, f'TEMPLATE_SIREN_{NAME}.gif'), templates, fps=3)