diff --git a/frigate/ptz_autotrack.py b/frigate/ptz_autotrack.py index 5761aa475..3e3bf29d6 100644 --- a/frigate/ptz_autotrack.py +++ b/frigate/ptz_autotrack.py @@ -17,6 +17,21 @@ from frigate.util import SharedMemoryFrameManager, intersection_over_union logger = logging.getLogger(__name__) +class PtzMotionEstimatorThread(threading.Thread): + def __init__(self, config: CameraConfig, ptz_moving, stop_event) -> None: + threading.Thread.__init__(self) + self.name = "frigate_ptz_motion_estimator" + self.ptz_moving = ptz_moving + self.config = config + self.stop_event = stop_event + self.ptz_motion_estimator = PtzMotionEstimator(self.config, self.ptz_moving) + + def run(self): + while not self.stop_event.is_set(): + pass + logger.info("Exiting motion estimator...") + + class PtzMotionEstimator: def __init__(self, config: CameraConfig, ptz_moving) -> None: self.frame_manager = SharedMemoryFrameManager() @@ -56,6 +71,10 @@ class PtzMotionEstimator: self.frame_manager.close(frame_id) + logger.debug( + f"frame time: {frame_time}, coord_transformations: {vars(self.coord_transformations)}" + ) + return self.coord_transformations return None diff --git a/frigate/track/norfair_tracker.py b/frigate/track/norfair_tracker.py index 48cc029ee..2683b05d1 100644 --- a/frigate/track/norfair_tracker.py +++ b/frigate/track/norfair_tracker.py @@ -6,7 +6,7 @@ from norfair import Detection, Drawable, Tracker, draw_boxes from norfair.drawing.drawer import Drawer from frigate.config import CameraConfig -from frigate.ptz_autotrack import PtzMotionEstimator +from frigate.ptz_autotrack import PtzMotionEstimatorThread from frigate.track import ObjectTracker from frigate.util import intersection_over_union @@ -55,7 +55,9 @@ def frigate_distance(detection: Detection, tracked_object) -> float: class NorfairTracker(ObjectTracker): - def __init__(self, config: CameraConfig, ptz_autotracker_enabled, ptz_moving): + def __init__( + self, config: CameraConfig, ptz_autotracker_enabled, ptz_moving, stop_event + ): self.tracked_objects = {} self.disappeared = {} self.positions = {} @@ -75,7 +77,9 @@ class NorfairTracker(ObjectTracker): hit_counter_max=self.max_disappeared, ) if self.ptz_autotracker_enabled: - self.ptz_motion_estimator = PtzMotionEstimator(config, self.ptz_moving) + self.ptz_motion_estimator_thread = PtzMotionEstimatorThread( + config, self.ptz_moving, stop_event + ) def register(self, track_id, obj): rand_id = "".join(random.choices(string.ascii_lowercase + string.digits, k=6)) @@ -243,8 +247,10 @@ class NorfairTracker(ObjectTracker): self.ptz_autotracker_enabled and self.camera_config.onvif.autotracking.motion_estimator ): - coord_transformations = self.ptz_motion_estimator.motion_estimator( - detections, frame_time, self.camera_name + coord_transformations = ( + self.ptz_motion_estimator_thread.ptz_motion_estimator.motion_estimator( + detections, frame_time, self.camera_name + ) ) tracked_objects = self.tracker.update( diff --git a/frigate/video.py b/frigate/video.py index 4dfcbedab..2eaa439c2 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -478,7 +478,9 @@ def track_camera( name, labelmap, detection_queue, result_connection, model_config, stop_event ) - object_tracker = NorfairTracker(config, ptz_autotracker_enabled, ptz_moving) + object_tracker = NorfairTracker( + config, ptz_autotracker_enabled, ptz_moving, stop_event + ) frame_manager = SharedMemoryFrameManager()