Move autotracker start to app.py

This commit is contained in:
Josh Hawkins 2023-07-02 10:52:38 -05:00
parent a5f407dba8
commit 98c161bdde
2 changed files with 20 additions and 7 deletions

View File

@ -40,6 +40,7 @@ from frigate.object_processing import TrackedObjectProcessor
from frigate.output import output_frames
from frigate.plus import PlusApi
from frigate.ptz import OnvifController
from frigate.ptz_autotrack import PtzAutoTrackerThread
from frigate.record.record import manage_recordings
from frigate.stats import StatsEmitter, stats_init
from frigate.storage import StorageMaintainer
@ -327,6 +328,15 @@ class FrigateApp:
detector_config,
)
def start_ptz_autotracker(self) -> None:
self.ptz_autotracker_thread = PtzAutoTrackerThread(
self.config,
self.dispatcher.onvif,
self.dispatcher.camera_metrics,
self.stop_event,
)
self.ptz_autotracker_thread.start()
def start_detected_frames_processor(self) -> None:
self.detected_frames_processor = TrackedObjectProcessor(
self.config,
@ -336,6 +346,7 @@ class FrigateApp:
self.event_processed_queue,
self.video_output_queue,
self.recordings_info_queue,
self.ptz_autotracker_thread,
self.stop_event,
)
self.detected_frames_processor.start()
@ -488,6 +499,7 @@ class FrigateApp:
sys.exit(1)
self.start_detectors()
self.start_video_output_processor()
self.start_ptz_autotracker()
self.start_detected_frames_processor()
self.start_camera_processors()
self.start_camera_capture_processes()
@ -531,6 +543,7 @@ class FrigateApp:
self.dispatcher.stop()
self.detected_frames_processor.join()
self.ptz_autotracker_thread.join()
self.event_processor.join()
self.event_cleanup.join()
self.stats_emitter.join()

View File

@ -240,7 +240,10 @@ class TrackedObject:
significant_change = True
# update autotrack every second? or fps?
if self.obj_data["frame_time"] - self.previous["frame_time"] > 1:
if (
self.obj_data["frame_time"] - self.previous["frame_time"]
> 0.5 # / self.camera_config.detect.fps
):
autotracker_update = True
self.obj_data.update(obj_data)
@ -619,7 +622,7 @@ class CameraState:
frame_time, current_detections[id]
)
if autotracker_update:
if autotracker_update or significant_update:
for c in self.callbacks["autotrack"]:
c(self.name, updated_obj, frame_time)
@ -763,6 +766,7 @@ class TrackedObjectProcessor(threading.Thread):
event_processed_queue,
video_output_queue,
recordings_info_queue,
ptz_autotracker_thread,
stop_event,
):
threading.Thread.__init__(self)
@ -778,9 +782,7 @@ class TrackedObjectProcessor(threading.Thread):
self.camera_states: dict[str, CameraState] = {}
self.frame_manager = SharedMemoryFrameManager()
self.last_motion_detected: dict[str, float] = {}
self.ptz_autotracker_thread = PtzAutoTrackerThread(
config, dispatcher.onvif, dispatcher.camera_metrics, self.stop_event
)
self.ptz_autotracker_thread = ptz_autotracker_thread
def start(camera, obj: TrackedObject, current_frame_time):
self.event_queue.put(
@ -1041,7 +1043,6 @@ class TrackedObjectProcessor(threading.Thread):
return self.camera_states[camera].current_frame_time
def run(self):
self.ptz_autotracker_thread.start()
while not self.stop_event.is_set():
try:
(
@ -1162,5 +1163,4 @@ class TrackedObjectProcessor(threading.Thread):
event_id, camera = self.event_processed_queue.get()
self.camera_states[camera].finished(event_id)
self.ptz_autotracker_thread.join()
logger.info("Exiting object processor...")