From 0b858419d1d7060bb452cd3d68007fb704768d27 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 23 Oct 2023 18:50:22 -0600 Subject: [PATCH] re-enable init delay (#8283) --- frigate/track/centroid_tracker.py | 1 + frigate/track/norfair_tracker.py | 17 +++++++++++------ frigate/video.py | 5 +++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/frigate/track/centroid_tracker.py b/frigate/track/centroid_tracker.py index fd4a293f9..36d780cdf 100644 --- a/frigate/track/centroid_tracker.py +++ b/frigate/track/centroid_tracker.py @@ -13,6 +13,7 @@ from frigate.util import intersection_over_union class CentroidTracker(ObjectTracker): def __init__(self, config: DetectConfig): self.tracked_objects = {} + self.untracked_object_boxes = [] self.disappeared = {} self.positions = {} self.max_disappeared = config.max_disappeared diff --git a/frigate/track/norfair_tracker.py b/frigate/track/norfair_tracker.py index d5a55c052..e11a38d44 100644 --- a/frigate/track/norfair_tracker.py +++ b/frigate/track/norfair_tracker.py @@ -1,3 +1,4 @@ +import logging import random import string @@ -11,6 +12,8 @@ from frigate.track import ObjectTracker from frigate.types import PTZMetricsTypes from frigate.util.image import intersection_over_union +logger = logging.getLogger(__name__) + # Normalizes distance from estimate relative to object size # Other ideas: @@ -62,6 +65,7 @@ class NorfairTracker(ObjectTracker): ptz_metrics: PTZMetricsTypes, ): self.tracked_objects = {} + self.untracked_object_boxes: list[list[int]] = [] self.disappeared = {} self.positions = {} self.max_disappeared = config.detect.max_disappeared @@ -77,7 +81,7 @@ class NorfairTracker(ObjectTracker): self.tracker = Tracker( distance_function=frigate_distance, distance_threshold=2.5, - initialization_delay=0, + initialization_delay=self.detect_config.fps / 2, hit_counter_max=self.max_disappeared, ) if self.ptz_autotracker_enabled.value: @@ -106,11 +110,6 @@ class NorfairTracker(ObjectTracker): "ymax": self.detect_config.height, } - # start object with a hit count of `fps` to avoid quick detection -> loss - next( - (o for o in self.tracker.tracked_objects if o.global_id == track_id) - ).hit_counter = self.camera_config.detect.fps - def deregister(self, id, track_id): del self.tracked_objects[id] del self.disappeared[id] @@ -303,6 +302,12 @@ class NorfairTracker(ObjectTracker): for e_id in expired_ids: self.deregister(self.track_id_map[e_id], e_id) + # update list of object boxes that don't have a tracked object yet + tracked_object_boxes = [obj["box"] for obj in self.tracked_objects.values()] + self.untracked_object_boxes = [ + o[2] for o in detections if o[2] not in tracked_object_boxes + ] + def debug_draw(self, frame, frame_time): active_detections = [ Drawable(id=obj.id, points=obj.last_detection.points, label=obj.label) diff --git a/frigate/video.py b/frigate/video.py index 3d3c1d97e..7dab59bb3 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -614,14 +614,15 @@ def process_frames( for obj in object_tracker.tracked_objects.values() if obj["id"] not in stationary_object_ids ] + object_boxes = tracked_object_boxes + object_tracker.untracked_object_boxes # get consolidated regions for tracked objects regions = [ get_cluster_region( - frame_shape, region_min_size, candidate, tracked_object_boxes + frame_shape, region_min_size, candidate, object_boxes ) for candidate in get_cluster_candidates( - frame_shape, region_min_size, tracked_object_boxes + frame_shape, region_min_size, object_boxes ) ]