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

44 lines
1.0 KiB
Python
Raw Permalink Normal View History

2020-06-13 19:26:09 +08:00
import os
import time
2020-07-28 16:34:21 +08:00
2020-06-13 19:26:09 +08:00
import module.config.server as server
from module.base.utils import *
2020-06-13 19:26:09 +08:00
server.server = 'cn' # Don't need to edit, it's used to avoid error.
from module.config.config import AzurLaneConfig
2022-04-15 03:37:54 +08:00
from module.map_detection.view import View
from module.base.utils import load_image
2020-06-13 19:26:09 +08:00
class Config:
"""
Paste the config of map file here
"""
2024-06-28 03:19:37 +08:00
pass
2020-06-13 19:26:09 +08:00
from module.os.config import OSConfig
2024-06-28 03:19:37 +08:00
cfg = AzurLaneConfig('alas').merge(OSConfig())
2020-06-13 19:26:09 +08:00
# Folder to save temp images
folder = './screenshots/relative_crop'
2020-06-13 19:26:09 +08:00
# Put Screenshot here
2024-06-28 03:19:37 +08:00
file = ''
2020-06-13 19:26:09 +08:00
i = load_image(file)
2020-07-28 16:34:21 +08:00
grids = View(cfg)
grids.load(np.array(i))
2020-06-13 19:26:09 +08:00
grids.predict()
grids.show()
os.makedirs(folder, exist_ok=True)
2020-06-13 19:26:09 +08:00
for grid in grids:
# Find more relative_crop area in module/map/grid_predictor.py
# This one is for `predict_enemy_genre`
2024-06-28 03:19:37 +08:00
piece = rgb2gray(grid.relative_crop((-0.5, -1, 0.5, 0), shape=(60, 60)))
2020-06-13 19:26:09 +08:00
file = '%s_%s_%s.png' % (int(time.time()), grid.location[0], grid.location[1])
file = os.path.join(folder, file)
2020-07-28 16:34:21 +08:00
Image.fromarray(piece).save(file)