From eb16de7395d750c0299c36b165cd4c46193d61b4 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sun, 31 Oct 2021 11:48:49 -0500 Subject: [PATCH] config option for stationary detection interval --- docs/docs/configuration/index.md | 2 ++ docs/docs/configuration/record.md | 2 +- frigate/config.py | 8 ++++++++ frigate/video.py | 9 ++++++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/docs/configuration/index.md b/docs/docs/configuration/index.md index 49b468143..7cad6fa23 100644 --- a/docs/docs/configuration/index.md +++ b/docs/docs/configuration/index.md @@ -159,6 +159,8 @@ 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: 10x the frame rate) + stationary_interval: 50 # Optional: Object configuration # NOTE: Can be overridden at the camera level diff --git a/docs/docs/configuration/record.md b/docs/docs/configuration/record.md index 23189d1af..d59530e07 100644 --- a/docs/docs/configuration/record.md +++ b/docs/docs/configuration/record.md @@ -22,4 +22,4 @@ record: This configuration will retain recording segments that overlap with events for 10 days. Because multiple events can reference the same recording segments, this avoids storing duplicate footage for overlapping events and reduces overall storage needs. -When `retain_days` is set to `0`, events will have up to `max_seconds` (defaults to 5 minutes) of recordings retained. Increasing `retain_days` to `1` will allow events to exceed the `max_seconds` limitation of up to 1 day. +When `retain_days` is set to `0`, segments will be deleted from the cache if no events are in progress diff --git a/frigate/config.py b/frigate/config.py index 6ff88dc00..e3db81a68 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -162,6 +162,9 @@ class DetectConfig(FrigateBaseModel): max_disappeared: Optional[int] = Field( title="Maximum number of frames the object can dissapear before detection ends." ) + stationary_interval: Optional[int] = Field( + title="Frame interval for checking stationary objects." + ) class FilterConfig(FrigateBaseModel): @@ -745,6 +748,11 @@ class FrigateConfig(FrigateBaseModel): if camera_config.detect.max_disappeared is None: camera_config.detect.max_disappeared = max_disappeared + # Default stationary_interval configuration + stationary_interval = camera_config.detect.fps * 10 + if camera_config.detect.stationary_interval is None: + camera_config.detect.stationary_interval = stationary_interval + # FFMPEG input substitution for input in camera_config.ffmpeg.inputs: input.path = input.path.format(**FRIGATE_ENV_VARS) diff --git a/frigate/video.py b/frigate/video.py index 9c4ba9e61..8a66f9f6c 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -14,7 +14,7 @@ import numpy as np from cv2 import cv2 from setproctitle import setproctitle -from frigate.config import CameraConfig +from frigate.config import CameraConfig, DetectConfig from frigate.edgetpu import RemoteObjectDetector from frigate.log import LogPipe from frigate.motion import MotionDetector @@ -367,6 +367,7 @@ def track_camera( frame_queue, frame_shape, model_shape, + config.detect, frame_manager, motion_detector, object_detector, @@ -448,6 +449,7 @@ def process_frames( frame_queue: mp.Queue, frame_shape, model_shape, + detect_config: DetectConfig, frame_manager: FrameManager, motion_detector: MotionDetector, object_detector: RemoteObjectDetector, @@ -502,12 +504,13 @@ def process_frames( motion_boxes = motion_detector.detect(frame) # get stationary object ids - # check every 10th frame for stationary objects + # check every Nth frame for stationary objects + # disappeared objects are not stationary 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 obj["motionless_count"] % detect_config.stationary_interval != 0 and object_tracker.disappeared[obj["id"]] == 0 ]