From 75c85709132c9ecffbbe9d0db8b82379f8a2fda1 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sat, 30 Oct 2021 14:01:31 -0500 Subject: [PATCH] reduce detection rate for stationary objects --- frigate/objects.py | 10 +++++++++- frigate/video.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/frigate/objects.py b/frigate/objects.py index 4da7f12d4..dc2b1b55e 100644 --- a/frigate/objects.py +++ b/frigate/objects.py @@ -13,7 +13,7 @@ import numpy as np from scipy.spatial import distance as dist from frigate.config import DetectConfig -from frigate.util import draw_box_with_label +from frigate.util import intersection_over_union class ObjectTracker: @@ -27,6 +27,7 @@ class ObjectTracker: id = f"{obj['frame_time']}-{rand_id}" obj["id"] = id obj["start_time"] = obj["frame_time"] + obj["motionless_count"] = 0 self.tracked_objects[id] = obj self.disappeared[id] = 0 @@ -36,6 +37,13 @@ class ObjectTracker: def update(self, id, new_obj): self.disappeared[id] = 0 + if ( + intersection_over_union(self.tracked_objects[id]["box"], new_obj["box"]) + > 0.9 + ): + self.tracked_objects[id]["motionless_count"] += 1 + else: + self.tracked_objects[id]["motionless_count"] = 0 self.tracked_objects[id].update(new_obj) def match_and_update(self, frame_time, new_objects): diff --git a/frigate/video.py b/frigate/video.py index 2e46bc590..0d6bf201e 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -498,9 +498,21 @@ def process_frames( # look for motion motion_boxes = motion_detector.detect(frame) - # only get the tracked object boxes that intersect with motion + # get stationary object ids + # check every 10th frame for stationary objects + stationary_object_ids = [ + obj["id"] + for obj in object_tracker.tracked_objects.values() + if obj["motionless_count"] >= 10 + and obj["motionless_count"] % 10 != 0 + and object_tracker.disappeared[obj["id"]] == 0 + ] + + # get tracked object boxes that aren't stationary tracked_object_boxes = [ - obj["box"] for obj in object_tracker.tracked_objects.values() + obj["box"] + for obj in object_tracker.tracked_objects.values() + if not obj["id"] in stationary_object_ids ] # combine motion boxes with known locations of existing objects @@ -513,7 +525,18 @@ def process_frames( ] # resize regions and detect - detections = [] + # seed with stationary objects + detections = [ + ( + obj["label"], + obj["score"], + obj["box"], + obj["area"], + obj["region"], + ) + for obj in object_tracker.tracked_objects.values() + if obj["id"] in stationary_object_ids + ] for region in regions: detections.extend( detect(