From 2e4ea37ca6f9ab84b2b80edcc7cccb8f593cd95c Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Mon, 2 Oct 2023 16:34:05 +0800 Subject: [PATCH] Fix: Allow locking minimap init position --- tasks/map/minimap/minimap.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tasks/map/minimap/minimap.py b/tasks/map/minimap/minimap.py index 5fe623672..f0fd36252 100644 --- a/tasks/map/minimap/minimap.py +++ b/tasks/map/minimap/minimap.py @@ -47,11 +47,33 @@ class PositionPredictState: 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: - 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 + if locked: + self.position_locked = position + else: + self.position_locked = None + def _predict_position(self, image, scale=1.0): """ Args: @@ -65,8 +87,11 @@ class Minimap(MapResource): local = cv2.resize(image, None, fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC) size = np.array(image_size(image)) - if sum(self.position) > 0: - search_position = np.array(self.position, dtype=np.int64) + position = self.position + 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_size = np.array(image_size(local)) * self.POSITION_SEARCH_RADIUS search_half = (search_size // 2).astype(np.int64)