From 3e90f3032c7765410ce6cbe6440576872bba983b Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Tue, 8 Feb 2022 07:40:45 -0600 Subject: [PATCH] make stationary_threshold configurable --- docs/docs/configuration/index.md | 4 +++- frigate/config.py | 5 +++++ frigate/objects.py | 6 +++--- frigate/video.py | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/docs/configuration/index.md b/docs/docs/configuration/index.md index 2bf28024b..49164b44c 100644 --- a/docs/docs/configuration/index.md +++ b/docs/docs/configuration/index.md @@ -159,9 +159,11 @@ detect: enabled: True # Optional: Number of frames without a detection before frigate considers an object to be gone. (default: 5x the frame rate) max_disappeared: 25 - # Optional: Frequency for running detection on stationary objects (default: 0) + # Optional: Frequency for running detection on stationary objects (default: shown below) # When set to 0, object detection will never be run on stationary objects. If set to 10, it will be run on every 10th frame. stationary_interval: 0 + # Optional: Number of frames without a position change for an object to be considered stationary (default: shown below) + stationary_threshold: 10 # Optional: Object configuration # NOTE: Can be overridden at the camera level diff --git a/frigate/config.py b/frigate/config.py index 50da2c561..f7f82e91d 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -177,6 +177,11 @@ class DetectConfig(FrigateBaseModel): title="Frame interval for checking stationary objects.", ge=0, ) + stationary_threshold: Optional[int] = Field( + default=10, + title="Number of frames without a position change for an object to be considered stationary", + ge=1, + ) class FilterConfig(FrigateBaseModel): diff --git a/frigate/objects.py b/frigate/objects.py index 3a5ae1171..640130043 100644 --- a/frigate/objects.py +++ b/frigate/objects.py @@ -48,7 +48,7 @@ class ObjectTracker: del self.tracked_objects[id] del self.disappeared[id] - # tracks the current position of the object based on the last 10 bounding boxes + # tracks the current position of the object based on the last N bounding boxes # returns False if the object has moved outside its previous position def update_position(self, id, box): position = self.positions[id] @@ -78,9 +78,9 @@ class ObjectTracker: } return False - # if there are less than 10 entries for the position, add the bounding box + # if there are less than stationary_threshold entries for the position, add the bounding box # and recompute the position box - if len(position["xmins"]) < 10: + if len(position["xmins"]) < self.detect_config.stationary_threshold: position["xmins"].append(xmin) position["ymins"].append(ymin) position["xmaxs"].append(xmax) diff --git a/frigate/video.py b/frigate/video.py index cb201fd22..2d419cc1d 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -507,8 +507,8 @@ def process_frames( stationary_object_ids = [ obj["id"] for obj in object_tracker.tracked_objects.values() - # if there hasn't been motion for 10 frames - if obj["motionless_count"] >= 10 + # if there hasn't been motion for N frames + if obj["motionless_count"] >= detect_config.stationary_threshold # and it isn't due for a periodic check and ( detect_config.stationary_interval == 0