mirror of
				https://github.com/blakeblackshear/frigate.git
				synced 2025-10-27 10:52:11 +01:00 
			
		
		
		
	Threaded motion estimator
This commit is contained in:
		
							parent
							
								
									80e77fb856
								
							
						
					
					
						commit
						3171801607
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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,9 +247,11 @@ class NorfairTracker(ObjectTracker):
 | 
			
		||||
            self.ptz_autotracker_enabled
 | 
			
		||||
            and self.camera_config.onvif.autotracking.motion_estimator
 | 
			
		||||
        ):
 | 
			
		||||
            coord_transformations = self.ptz_motion_estimator.motion_estimator(
 | 
			
		||||
            coord_transformations = (
 | 
			
		||||
                self.ptz_motion_estimator_thread.ptz_motion_estimator.motion_estimator(
 | 
			
		||||
                    detections, frame_time, self.camera_name
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        tracked_objects = self.tracker.update(
 | 
			
		||||
            detections=norfair_detections, coord_transformations=coord_transformations
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user