Fix: Cropping outside of direction area

This commit is contained in:
LmeSzinc 2023-09-29 17:59:08 +08:00
parent 271bdc9e1c
commit 8648644c2f

View File

@ -6,6 +6,7 @@ import numpy as np
from scipy import signal
from module.base.utils import (
area_limit,
area_offset,
area_pad,
color_similarity_2d,
@ -46,7 +47,8 @@ class PositionPredictState:
class Minimap(MapResource):
def init_position(self, position: tuple[int | float, int | float]):
def init_position(self, position: tuple[int | float, int | float], show_log=True):
if show_log:
logger.info(f"init_position: {position}")
self.position = position
@ -211,6 +213,7 @@ class Minimap(MapResource):
image = color_similarity_2d(image, color=self.DIRECTION_ARROW_COLOR)
try:
area = area_pad(get_bbox(image, threshold=128), pad=-1)
area = area_limit(area, (0, 0, *image_size(image)))
except IndexError:
# IndexError: index 0 is out of bounds for axis 0 with size 0
logger.warning('No direction arrow on minimap')
@ -253,7 +256,7 @@ class Minimap(MapResource):
precise_loca = degree // 8 * 8 - 8 + precise_loca[0]
self.direction_similarity = round(precise_sim, 3)
self.direction = precise_loca % 360
self.direction = round(precise_loca % 360, 1)
def update_rotation(self, image):
"""