diff --git a/frigate/ptz/autotrack.py b/frigate/ptz/autotrack.py index 94f3860bb7..88afb207dd 100644 --- a/frigate/ptz/autotrack.py +++ b/frigate/ptz/autotrack.py @@ -1191,9 +1191,10 @@ class PtzAutoTracker(threading.Thread): # absolute zooming separately from pan/tilt if camera_config.onvif.autotracking.zooming == ZoomingModeEnum.absolute: - # don't zoom on initial move + # don't zoom on initial move. the stored zoom level can still be + # the previous track's if this one starts right after a preset return if "target_box" not in tom: - zoom = current_zoom_level + zoom = 0 else: if ( result := self._should_zoom_in( @@ -1421,9 +1422,6 @@ class PtzAutoTracker(threading.Thread): autotracker_config.return_preset.lower(), ) - # update stored zoom level from preset - await self._wait_until_stopped(camera) - self.dispatcher.publish( f"{camera}/ptz_autotracker/active", "OFF", retain=False ) diff --git a/frigate/test/test_ptz_autotrack.py b/frigate/test/test_ptz_autotrack.py index a20e7c2f64..bc16a7bb20 100644 --- a/frigate/test/test_ptz_autotrack.py +++ b/frigate/test/test_ptz_autotrack.py @@ -267,6 +267,22 @@ class TestAutotrackerMoveQueue(unittest.IsolatedAsyncioTestCase): ) +class TestAutotrackerInitialZoom(unittest.TestCase): + def test_initial_absolute_move_does_not_zoom(self) -> None: + tracker = _make_tracker() + tracker.config.cameras[ + CAMERA + ].onvif.autotracking.zooming = ZoomingModeEnum.absolute + # stale level from the previous track, not yet read back from the preset + tracker.ptz_metrics[CAMERA].zoom_level.value = 0.55 + tracker.tracked_object_metrics = {CAMERA: {}} + box = (900, 400, 1000, 600) + obj = MagicMock() + obj.obj_data = {"box": box} + + self.assertEqual(tracker._get_zoom_amount(CAMERA, obj, box, 0), 0) + + class TestMaxTargetBox(unittest.TestCase): def test_follows_zoom_factor(self) -> None: self.assertAlmostEqual(calculate_max_target_box(0.5), 0.6**2)