Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable init delay and use untracked object boxes for regions #8283

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frigate/track/centroid_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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
Expand Down
17 changes: 11 additions & 6 deletions frigate/track/norfair_tracker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import random
import string

Expand All @@ -11,6 +12,8 @@
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:
Expand Down Expand Up @@ -62,6 +65,7 @@ def __init__(
ptz_metrics: PTZMetricsTypes,
):
self.tracked_objects = {}
self.untracked_object_boxes: list[list[int]] = []
self.disappeared = {}
self.positions = {}
self.max_disappeared = config.detect.max_disappeared
Expand All @@ -77,7 +81,7 @@ def __init__(
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:
Expand Down Expand Up @@ -106,11 +110,6 @@ def register(self, track_id, obj):
"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]
Expand Down Expand Up @@ -303,6 +302,12 @@ def match_and_update(self, frame_time, detections):
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)
Expand Down
5 changes: 3 additions & 2 deletions frigate/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,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
)
]

Expand Down
Loading