recalc relative zoom value

This commit is contained in:
Josh Hawkins 2023-10-15 12:07:37 -05:00
parent 7868943dca
commit 2dd71a7d48
2 changed files with 28 additions and 27 deletions

View File

@ -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

View File

@ -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,11 +818,8 @@ 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
)
zoom = target_box ** self.zoom_factor[camera]
else:
if (
result := self._should_zoom_in(
camera,
@ -831,12 +829,15 @@ class PtzAutoTracker:
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 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}")