Fix: Allow locking minimap init position

This commit is contained in:
LmeSzinc 2023-10-02 16:34:05 +08:00
parent 2854232778
commit 2e4ea37ca6

View File

@ -47,11 +47,33 @@ class PositionPredictState:
class Minimap(MapResource): class Minimap(MapResource):
def init_position(self, position: tuple[int | float, int | float], show_log=True): position_locked = None
def init_position(
self,
position: tuple[int | float, int | float],
show_log=True,
locked=False,
):
"""
Args:
position:
show_log:
locked: If true, lock search area during detection
"""
if show_log: if show_log:
logger.info(f"init_position: {position}") if locked:
logger.info(f"init_position: {position}, locked")
else:
logger.info(f"init_position: {position}")
self.position = position self.position = position
if locked:
self.position_locked = position
else:
self.position_locked = None
def _predict_position(self, image, scale=1.0): def _predict_position(self, image, scale=1.0):
""" """
Args: Args:
@ -65,8 +87,11 @@ class Minimap(MapResource):
local = cv2.resize(image, None, fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC) local = cv2.resize(image, None, fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)
size = np.array(image_size(image)) size = np.array(image_size(image))
if sum(self.position) > 0: position = self.position
search_position = np.array(self.position, dtype=np.int64) if self.position_locked is not None:
position = self.position_locked
if sum(position) > 0:
search_position = np.array(position, dtype=np.int64)
search_position += self.POSITION_FEATURE_PAD search_position += self.POSITION_FEATURE_PAD
search_size = np.array(image_size(local)) * self.POSITION_SEARCH_RADIUS search_size = np.array(image_size(local)) * self.POSITION_SEARCH_RADIUS
search_half = (search_size // 2).astype(np.int64) search_half = (search_size // 2).astype(np.int64)