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

43 lines
949 B
Python
Raw Normal View History

2020-06-13 19:26:09 +08:00
import os
import time
2020-07-28 16:34:21 +08:00
from PIL import Image
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
2020-06-13 19:26:09 +08:00
class Config:
"""
Paste the config of map file here
"""
pass
cfg = AzurLaneConfig().merge(Config())
# Folder to save temp images
folder = ''
2020-06-13 19:26:09 +08:00
# Put Screenshot here
file = ''
2020-06-13 19:26:09 +08:00
i = Image.open(file).convert('RGB')
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()
for grid in grids:
# Find more relative_crop area in module/map/grid_predictor.py
# This one is for `predict_enemy_genre`
2020-07-28 16:34:21 +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)