mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-09 05:47:30 +08:00
Dev: Fix button_extract.py
This commit is contained in:
parent
b54b2fe036
commit
d646d6b79a
@ -2,10 +2,9 @@ import os
|
||||
|
||||
import imageio
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
from tqdm.contrib.concurrent import process_map
|
||||
|
||||
from module.base.button import get_color
|
||||
from module.base.utils import get_color, load_image, get_bbox, image_size
|
||||
from module.config.config_manual import ManualConfig as AzurLaneConfig
|
||||
from module.logger import logger
|
||||
|
||||
@ -54,7 +53,6 @@ class ImageExtractor:
|
||||
mean = None
|
||||
for image in imageio.mimread(file):
|
||||
image = image[:, :, :3] if len(image.shape) == 3 else image
|
||||
image = Image.fromarray(image)
|
||||
new_bbox, new_mean = self._extract(image, file)
|
||||
if bbox is None:
|
||||
bbox = new_bbox
|
||||
@ -64,14 +62,15 @@ class ImageExtractor:
|
||||
mean = new_mean
|
||||
return bbox, mean
|
||||
else:
|
||||
image = Image.open(file).convert('RGB')
|
||||
image = load_image(file)
|
||||
return self._extract(image, file)
|
||||
|
||||
@staticmethod
|
||||
def _extract(image, file):
|
||||
if image.size != (1280, 720):
|
||||
logger.warning(f'{file} has wrong resolution: {image.size}')
|
||||
bbox = image.getbbox()
|
||||
size = image_size(image)
|
||||
if size != (1280, 720):
|
||||
logger.warning(f'{file} has wrong resolution: {size}')
|
||||
bbox = get_bbox(image)
|
||||
mean = get_color(image=image, area=bbox)
|
||||
mean = tuple(np.rint(mean).astype(int))
|
||||
return bbox, mean
|
||||
@ -121,8 +120,8 @@ class TemplateExtractor(ImageExtractor):
|
||||
# self.config = config
|
||||
@staticmethod
|
||||
def extract(file):
|
||||
image = Image.open(file).convert('RGB')
|
||||
bbox = image.getbbox()
|
||||
image = load_image(file)
|
||||
bbox = get_bbox(image)
|
||||
mean = get_color(image=image, area=bbox)
|
||||
mean = tuple(np.rint(mean).astype(int))
|
||||
return bbox, mean
|
||||
|
@ -492,6 +492,23 @@ def get_color(image, area):
|
||||
return color[:3]
|
||||
|
||||
|
||||
def get_bbox(image):
|
||||
"""
|
||||
A numpy implementation of the getbbox() in pillow.
|
||||
|
||||
Args:
|
||||
image (np.ndarray): Screenshot.
|
||||
|
||||
Returns:
|
||||
tuple: (upper_left_x, upper_left_y, bottom_right_x, bottom_right_y)
|
||||
"""
|
||||
if image_channel(image) == 3:
|
||||
image = np.max(image, axis=2)
|
||||
x = np.where(np.max(image, axis=0) > 0)[0]
|
||||
y = np.where(np.max(image, axis=1) > 0)[0]
|
||||
return (x[0], y[0], x[-1] + 1, y[-1] + 1)
|
||||
|
||||
|
||||
def color_similarity(color1, color2):
|
||||
"""
|
||||
Args:
|
||||
|
@ -17,7 +17,7 @@ MEOWFFICER_FORT_GET_XP_1 = Button(area={'cn': (371, 198, 453, 278), 'en': (371,
|
||||
MEOWFFICER_FORT_GET_XP_2 = Button(area={'cn': (320, 314, 422, 412), 'en': (320, 314, 422, 412), 'jp': (302, 318, 414, 393), 'tw': (320, 314, 422, 412)}, color={'cn': (221, 189, 148), 'en': (221, 189, 148), 'jp': (227, 192, 151), 'tw': (221, 189, 148)}, button={'cn': (320, 314, 422, 412), 'en': (320, 314, 422, 412), 'jp': (302, 318, 414, 393), 'tw': (320, 314, 422, 412)}, file={'cn': './assets/cn/meowfficer/MEOWFFICER_FORT_GET_XP_2.png', 'en': './assets/en/meowfficer/MEOWFFICER_FORT_GET_XP_2.png', 'jp': './assets/jp/meowfficer/MEOWFFICER_FORT_GET_XP_2.png', 'tw': './assets/tw/meowfficer/MEOWFFICER_FORT_GET_XP_2.png'})
|
||||
MEOWFFICER_FORT_RED_DOT = Button(area={'cn': (938, 655, 958, 676), 'en': (938, 655, 958, 676), 'jp': (938, 654, 957, 676), 'tw': (939, 659, 956, 683)}, color={'cn': (244, 131, 117), 'en': (244, 131, 117), 'jp': (244, 132, 118), 'tw': (242, 133, 120)}, button={'cn': (938, 655, 958, 676), 'en': (938, 655, 958, 676), 'jp': (938, 654, 957, 676), 'tw': (939, 659, 956, 683)}, file={'cn': './assets/cn/meowfficer/MEOWFFICER_FORT_RED_DOT.png', 'en': './assets/en/meowfficer/MEOWFFICER_FORT_RED_DOT.png', 'jp': './assets/jp/meowfficer/MEOWFFICER_FORT_RED_DOT.png', 'tw': './assets/tw/meowfficer/MEOWFFICER_FORT_RED_DOT.png'})
|
||||
MEOWFFICER_STATUS = Button(area={'cn': (987, 44, 1035, 104), 'en': (987, 44, 1035, 104), 'jp': (987, 44, 1035, 104), 'tw': (987, 44, 1035, 104)}, color={'cn': (252, 244, 232), 'en': (252, 244, 232), 'jp': (252, 244, 232), 'tw': (252, 244, 232)}, button={'cn': (987, 44, 1035, 104), 'en': (987, 44, 1035, 104), 'jp': (987, 44, 1035, 104), 'tw': (987, 44, 1035, 104)}, file={'cn': './assets/cn/meowfficer/MEOWFFICER_STATUS.png', 'en': './assets/en/meowfficer/MEOWFFICER_STATUS.png', 'jp': './assets/jp/meowfficer/MEOWFFICER_STATUS.png', 'tw': './assets/tw/meowfficer/MEOWFFICER_STATUS.png'})
|
||||
MEOWFFICER_TRAIN_CLICK_SAFE_AREA = Button(area={'cn': (224, 184, 242, 347), 'en': (234, 191, 244, 523), 'jp': (224, 184, 242, 347), 'tw': (224, 184, 242, 347)}, color={'cn': (242, 237, 237), 'en': (243, 239, 238), 'jp': (242, 237, 237), 'tw': (242, 237, 237)}, button={'cn': (224, 184, 242, 347), 'en': (234, 191, 244, 523), 'jp': (224, 184, 242, 347), 'tw': (224, 184, 242, 347)}, file={'cn': './assets/cn/meowfficer/MEOWFFICER_TRAIN_CLICK_SAFE_AREA.png', 'en': './assets/en/meowfficer/MEOWFFICER_TRAIN_CLICK_SAFE_AREA.png', 'jp': './assets/jp/meowfficer/MEOWFFICER_TRAIN_CLICK_SAFE_AREA.png', 'tw': './assets/tw/meowfficer/MEOWFFICER_TRAIN_CLICK_SAFE_AREA.png'})
|
||||
MEOWFFICER_TRAIN_CLICK_SAFE_AREA = Button(area={'cn': (224, 184, 242, 347), 'en': (234, 191, 244, 523), 'jp': (224, 184, 242, 347), 'tw': (224, 184, 242, 347)}, color={'cn': (242, 237, 237), 'en': (243, 239, 239), 'jp': (242, 237, 237), 'tw': (242, 237, 237)}, button={'cn': (224, 184, 242, 347), 'en': (234, 191, 244, 523), 'jp': (224, 184, 242, 347), 'tw': (224, 184, 242, 347)}, file={'cn': './assets/cn/meowfficer/MEOWFFICER_TRAIN_CLICK_SAFE_AREA.png', 'en': './assets/en/meowfficer/MEOWFFICER_TRAIN_CLICK_SAFE_AREA.png', 'jp': './assets/jp/meowfficer/MEOWFFICER_TRAIN_CLICK_SAFE_AREA.png', 'tw': './assets/tw/meowfficer/MEOWFFICER_TRAIN_CLICK_SAFE_AREA.png'})
|
||||
MEOWFFICER_TRAIN_COMPLETE = Button(area={'cn': (255, 188, 353, 215), 'en': (253, 187, 357, 216), 'jp': (247, 186, 348, 216), 'tw': (261, 196, 365, 222)}, color={'cn': (134, 216, 154), 'en': (179, 215, 163), 'jp': (151, 213, 154), 'tw': (132, 213, 149)}, button={'cn': (255, 188, 353, 215), 'en': (253, 187, 357, 216), 'jp': (247, 186, 348, 216), 'tw': (261, 196, 365, 222)}, file={'cn': './assets/cn/meowfficer/MEOWFFICER_TRAIN_COMPLETE.png', 'en': './assets/en/meowfficer/MEOWFFICER_TRAIN_COMPLETE.png', 'jp': './assets/jp/meowfficer/MEOWFFICER_TRAIN_COMPLETE.png', 'tw': './assets/tw/meowfficer/MEOWFFICER_TRAIN_COMPLETE.png'})
|
||||
MEOWFFICER_TRAIN_ENTER = Button(area={'cn': (1142, 581, 1258, 651), 'en': (1178, 616, 1266, 648), 'jp': (1140, 579, 1262, 644), 'tw': (1148, 601, 1246, 653)}, color={'cn': (193, 167, 113), 'en': (212, 175, 96), 'jp': (196, 171, 119), 'tw': (199, 166, 99)}, button={'cn': (1142, 581, 1258, 651), 'en': (1178, 616, 1266, 648), 'jp': (1140, 579, 1262, 644), 'tw': (1148, 601, 1246, 653)}, file={'cn': './assets/cn/meowfficer/MEOWFFICER_TRAIN_ENTER.png', 'en': './assets/en/meowfficer/MEOWFFICER_TRAIN_ENTER.png', 'jp': './assets/jp/meowfficer/MEOWFFICER_TRAIN_ENTER.png', 'tw': './assets/tw/meowfficer/MEOWFFICER_TRAIN_ENTER.png'})
|
||||
MEOWFFICER_TRAIN_FILL_QUEUE = Button(area={'cn': (780, 548, 859, 567), 'en': (772, 544, 866, 568), 'jp': (779, 547, 859, 569), 'tw': (778, 545, 863, 571)}, color={'cn': (205, 179, 89), 'en': (222, 198, 100), 'jp': (204, 176, 82), 'tw': (213, 187, 95)}, button={'cn': (780, 548, 859, 567), 'en': (772, 544, 866, 568), 'jp': (779, 547, 859, 569), 'tw': (778, 545, 863, 571)}, file={'cn': './assets/cn/meowfficer/MEOWFFICER_TRAIN_FILL_QUEUE.png', 'en': './assets/en/meowfficer/MEOWFFICER_TRAIN_FILL_QUEUE.png', 'jp': './assets/jp/meowfficer/MEOWFFICER_TRAIN_FILL_QUEUE.png', 'tw': './assets/tw/meowfficer/MEOWFFICER_TRAIN_FILL_QUEUE.png'})
|
||||
|
Loading…
Reference in New Issue
Block a user