From 2dd71a7d4895098488a93e068b275c1be7e63884 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Sun, 15 Oct 2023 12:07:37 -0500 Subject: [PATCH] recalc relative zoom value --- frigate/const.py | 6 ++--- frigate/ptz/autotrack.py | 49 ++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/frigate/const.py b/frigate/const.py index 453ebf94b..73465f355 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -57,6 +57,6 @@ INSERT_MANY_RECORDINGS = "insert_many_recordings" AUTOTRACKING_MOTION_MIN_DISTANCE = 20 AUTOTRACKING_MOTION_MAX_POINTS = 500 AUTOTRACKING_MAX_MOVE_METRICS = 500 -AUTOTRACKING_ZOOM_OUT_HYSTERESIS = 2.2 -AUTOTRACKING_ZOOM_IN_HYSTERESIS = 0.8 -AUTOTRACKING_ZOOM_EDGE_THRESHOLD = 0.02 +AUTOTRACKING_ZOOM_OUT_HYSTERESIS = 1.1 +AUTOTRACKING_ZOOM_IN_HYSTERESIS = 0.9 +AUTOTRACKING_ZOOM_EDGE_THRESHOLD = 0.05 diff --git a/frigate/ptz/autotrack.py b/frigate/ptz/autotrack.py index f5ff024d0..8fd0dc42f 100644 --- a/frigate/ptz/autotrack.py +++ b/frigate/ptz/autotrack.py @@ -630,9 +630,9 @@ class PtzAutoTracker: below_distance_threshold = self._below_distance_threshold(camera, obj) # ensure object isn't too big in frame - below_dimension_threshold = (bb_right - bb_left) / camera_width < min( - self.zoom_factor[camera], 0.6 - ) and (bb_bottom - bb_top) / camera_height < min(self.zoom_factor[camera], 0.6) + below_dimension_threshold = (bb_right - bb_left) / camera_width < 0.8 and ( + bb_bottom - bb_top + ) / camera_height < 0.8 # ensure object is not moving quickly below_velocity_threshold = ( @@ -703,7 +703,8 @@ class PtzAutoTracker: zoom_in_hysteresis and away_from_edge and below_velocity_threshold - and (below_distance_threshold or below_dimension_threshold) + and below_distance_threshold + and below_dimension_threshold and not at_max_zoom ): return True @@ -817,26 +818,26 @@ class PtzAutoTracker: # relative zooming concurrently with pan/tilt if camera_config.onvif.autotracking.zooming == ZoomingModeEnum.relative: if self.tracked_object_previous[camera] is None: - # start with a slightly altered box to encourage an initial zoom - self.previous_target_box[camera] = target_box * ( - AUTOTRACKING_ZOOM_OUT_HYSTERESIS - 0.05 - ) - - if ( - result := self._should_zoom_in( - camera, - obj, - predicted_box - if camera_config.onvif.autotracking.movement_weights - else obj.obj_data["box"], - ) - ) is not None: - # zoom in value - zoom = target_box ** (self.zoom_factor[camera] / 1.5) - - if not result: - # zoom out - zoom = -(1 - zoom) if zoom != 0 else 0 + zoom = target_box ** self.zoom_factor[camera] + else: + if ( + result := self._should_zoom_in( + camera, + obj, + predicted_box + if camera_config.onvif.autotracking.movement_weights + else obj.obj_data["box"], + ) + ) is not None: + # zoom value + zoom = ( + 2 + * ( + self.previous_target_box[camera] + / (target_box + self.previous_target_box[camera]) + ) + - 1 + ) logger.debug(f"{camera}: Zooming: {result} Zoom amount: {zoom}")