Compare commits

..

10 Commits

Author SHA1 Message Date
Blake Blackshear
e5714f5fbc add missing optional comment in docs 2022-02-13 10:27:58 -06:00
Blake Blackshear
3be0b915ad deregister based on max_frames setting 2022-02-13 10:21:24 -06:00
Blake Blackshear
304ffa86e8 refactor stationary config into section 2022-02-13 10:21:24 -06:00
Nicolas Mowen
889835a59b Always show recording link even if recordings are currently disabled (#2787)
* Always show recording link even if recordings are currently disabled

* Fix test to consider all cameras to have recording link
2022-02-12 13:51:28 -06:00
Blake Blackshear
ee01396b36 update birdseye to handle stationary objects 2022-02-12 06:59:10 -06:00
Blake Blackshear
334e28fe54 use second stream in docs example 2022-02-12 06:43:46 -06:00
Blake Blackshear
6b2bae040c stop forcing detection all the way to stationary_threshold 2022-02-11 07:34:42 -06:00
Blake Blackshear
95ab22d411 bump default stationary_threshold to 10s 2022-02-11 07:30:47 -06:00
Blake Blackshear
4e52461aa9 set stationary_threshold default to 5x fps 2022-02-11 07:12:51 -06:00
Blake Blackshear
7934f8699f fix the bounding box calculation position at 10 2022-02-11 06:54:42 -06:00
10 changed files with 95 additions and 36 deletions

View File

@@ -159,11 +159,23 @@ detect:
enabled: True enabled: True
# Optional: Number of frames without a detection before frigate considers an object to be gone. (default: 5x the frame rate) # Optional: Number of frames without a detection before frigate considers an object to be gone. (default: 5x the frame rate)
max_disappeared: 25 max_disappeared: 25
# Optional: Frequency for running detection on stationary objects (default: shown below) # Optional: Configuration for stationary object tracking
# 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:
stationary_interval: 0 # Optional: Frequency for running detection on stationary objects (default: shown below)
# Optional: Number of frames without a position change for an object to be considered stationary (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_threshold: 10 interval: 0
# Optional: Number of frames without a position change for an object to be considered stationary (default: 10x the frame rate or 10s)
threshold: 50
# Optional: Define a maximum number of frames for tracking a stationary object (default: not set, track forever)
# This can help with false positives for objects that should only be stationary for a limited amount of time.
# It can also be used to disable stationary object tracking. For example, you may want to set a value for person, but leave
# car at the default.
max_frames:
# Optional: Default for all object types (default: not set, track forever)
default: 3000
# Optional: Object specific values
objects:
person: 1000
# Optional: Object configuration # Optional: Object configuration
# NOTE: Can be overridden at the camera level # NOTE: Can be overridden at the camera level

View File

@@ -167,13 +167,17 @@ cameras:
roles: roles:
- detect - detect
- rtmp - rtmp
- record # <----- Add role - path: rtsp://10.0.10.10:554/high_res_stream # <----- Add high res stream
roles:
- record
detect: ... detect: ...
record: # <----- Enable recording record: # <----- Enable recording
enabled: True enabled: True
motion: ... motion: ...
``` ```
If you don't have separate streams for detect and record, you would just add the record role to the list on the first input.
By default, Frigate will retain video of all events for 10 days. The full set of options for recording can be found [here](/configuration/index#full-configuration-reference). By default, Frigate will retain video of all events for 10 days. The full set of options for recording can be found [here](/configuration/index#full-configuration-reference).
### Step 8: Enable snapshots (optional) ### Step 8: Enable snapshots (optional)

View File

@@ -56,6 +56,7 @@ Message published for each changed event. The first message is published when th
"thumbnail": null, "thumbnail": null,
"has_snapshot": false, "has_snapshot": false,
"has_clip": false, "has_clip": false,
"stationary": false, // whether or not the object is considered stationary
"motionless_count": 0, // number of frames the object has been motionless "motionless_count": 0, // number of frames the object has been motionless
"position_changes": 2 // number of times the object has moved from a stationary position "position_changes": 2 // number of times the object has moved from a stationary position
}, },
@@ -78,6 +79,7 @@ Message published for each changed event. The first message is published when th
"thumbnail": null, "thumbnail": null,
"has_snapshot": false, "has_snapshot": false,
"has_clip": false, "has_clip": false,
"stationary": false, // whether or not the object is considered stationary
"motionless_count": 0, // number of frames the object has been motionless "motionless_count": 0, // number of frames the object has been motionless
"position_changes": 2 // number of times the object has changed position "position_changes": 2 // number of times the object has changed position
} }

View File

@@ -162,6 +162,29 @@ class RuntimeMotionConfig(MotionConfig):
extra = Extra.ignore extra = Extra.ignore
class StationaryMaxFramesConfig(FrigateBaseModel):
default: Optional[int] = Field(title="Default max frames.", ge=1)
objects: Dict[str, int] = Field(
default_factory=dict, title="Object specific max frames."
)
class StationaryConfig(FrigateBaseModel):
interval: Optional[int] = Field(
default=0,
title="Frame interval for checking stationary objects.",
ge=0,
)
threshold: Optional[int] = Field(
title="Number of frames without a position change for an object to be considered stationary",
ge=1,
)
max_frames: StationaryMaxFramesConfig = Field(
default_factory=StationaryMaxFramesConfig,
title="Max frames for stationary objects.",
)
class DetectConfig(FrigateBaseModel): class DetectConfig(FrigateBaseModel):
height: int = Field(default=720, title="Height of the stream for the detect role.") height: int = Field(default=720, title="Height of the stream for the detect role.")
width: int = Field(default=1280, title="Width of the stream for the detect role.") width: int = Field(default=1280, title="Width of the stream for the detect role.")
@@ -172,15 +195,9 @@ class DetectConfig(FrigateBaseModel):
max_disappeared: Optional[int] = Field( max_disappeared: Optional[int] = Field(
title="Maximum number of frames the object can dissapear before detection ends." title="Maximum number of frames the object can dissapear before detection ends."
) )
stationary_interval: Optional[int] = Field( stationary: StationaryConfig = Field(
default=0, default_factory=StationaryConfig,
title="Frame interval for checking stationary objects.", title="Stationary objects config.",
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,
) )
@@ -771,6 +788,11 @@ class FrigateConfig(FrigateBaseModel):
if camera_config.detect.max_disappeared is None: if camera_config.detect.max_disappeared is None:
camera_config.detect.max_disappeared = max_disappeared camera_config.detect.max_disappeared = max_disappeared
# Default stationary_threshold configuration
stationary_threshold = camera_config.detect.fps * 10
if camera_config.detect.stationary.threshold is None:
camera_config.detect.stationary.threshold = stationary_threshold
# FFMPEG input substitution # FFMPEG input substitution
for input in camera_config.ffmpeg.inputs: for input in camera_config.ffmpeg.inputs:
input.path = input.path.format(**FRIGATE_ENV_VARS) input.path = input.path.format(**FRIGATE_ENV_VARS)

View File

@@ -161,7 +161,7 @@ class TrackedObject:
# if the motionless_count reaches the stationary threshold # if the motionless_count reaches the stationary threshold
if ( if (
self.obj_data["motionless_count"] self.obj_data["motionless_count"]
== self.camera_config.detect.stationary_threshold == self.camera_config.detect.stationary.threshold
): ):
significant_change = True significant_change = True
@@ -193,6 +193,8 @@ class TrackedObject:
"box": self.obj_data["box"], "box": self.obj_data["box"],
"area": self.obj_data["area"], "area": self.obj_data["area"],
"region": self.obj_data["region"], "region": self.obj_data["region"],
"stationary": self.obj_data["motionless_count"]
> self.camera_config.detect.stationary.threshold,
"motionless_count": self.obj_data["motionless_count"], "motionless_count": self.obj_data["motionless_count"],
"position_changes": self.obj_data["position_changes"], "position_changes": self.obj_data["position_changes"],
"current_zones": self.current_zones.copy(), "current_zones": self.current_zones.copy(),

View File

@@ -78,9 +78,9 @@ class ObjectTracker:
} }
return False return False
# if there are less than stationary_threshold entries for the position, add the bounding box # if there are less than 10 entries for the position, add the bounding box
# and recompute the position box # and recompute the position box
if len(position["xmins"]) < self.detect_config.stationary_threshold: if len(position["xmins"]) < 10:
position["xmins"].append(xmin) position["xmins"].append(xmin)
position["ymins"].append(ymin) position["ymins"].append(ymin)
position["xmaxs"].append(xmax) position["xmaxs"].append(xmax)
@@ -93,18 +93,40 @@ class ObjectTracker:
return True return True
def is_expired(self, id):
obj = self.tracked_objects[id]
# get the max frames for this label type or the default
max_frames = self.detect_config.stationary.max_frames.objects.get(
obj["label"], self.detect_config.stationary.max_frames.default
)
# if there is no max_frames for this label type, continue
if max_frames is None:
return False
# if the object has exceeded the max_frames setting, deregister
if (
obj["motionless_count"] - self.detect_config.stationary.threshold
> max_frames
):
print(f"expired: {obj['motionless_count']}")
return True
def update(self, id, new_obj): def update(self, id, new_obj):
self.disappeared[id] = 0 self.disappeared[id] = 0
# update the motionless count if the object has not moved to a new position # update the motionless count if the object has not moved to a new position
if self.update_position(id, new_obj["box"]): if self.update_position(id, new_obj["box"]):
self.tracked_objects[id]["motionless_count"] += 1 self.tracked_objects[id]["motionless_count"] += 1
if self.is_expired(id):
self.deregister(id)
return
else: else:
# register the first position change and then only increment if # register the first position change and then only increment if
# the object was previously stationary # the object was previously stationary
if ( if (
self.tracked_objects[id]["position_changes"] == 0 self.tracked_objects[id]["position_changes"] == 0
or self.tracked_objects[id]["motionless_count"] or self.tracked_objects[id]["motionless_count"]
>= self.detect_config.stationary_threshold >= self.detect_config.stationary.threshold
): ):
self.tracked_objects[id]["position_changes"] += 1 self.tracked_objects[id]["position_changes"] += 1
self.tracked_objects[id]["motionless_count"] = 0 self.tracked_objects[id]["motionless_count"] = 0
@@ -112,9 +134,11 @@ class ObjectTracker:
self.tracked_objects[id].update(new_obj) self.tracked_objects[id].update(new_obj)
def update_frame_times(self, frame_time): def update_frame_times(self, frame_time):
for id in self.tracked_objects.keys(): for id in list(self.tracked_objects.keys()):
self.tracked_objects[id]["frame_time"] = frame_time self.tracked_objects[id]["frame_time"] = frame_time
self.tracked_objects[id]["motionless_count"] += 1 self.tracked_objects[id]["motionless_count"] += 1
if self.is_expired(id):
self.deregister(id)
def match_and_update(self, frame_time, new_objects): def match_and_update(self, frame_time, new_objects):
# group by name # group by name

View File

@@ -184,10 +184,7 @@ class BirdsEyeFrameManager:
if self.mode == BirdseyeModeEnum.continuous: if self.mode == BirdseyeModeEnum.continuous:
return True return True
if ( if self.mode == BirdseyeModeEnum.motion and motion_box_count > 0:
self.mode == BirdseyeModeEnum.motion
and object_box_count + motion_box_count > 0
):
return True return True
if self.mode == BirdseyeModeEnum.objects and object_box_count > 0: if self.mode == BirdseyeModeEnum.objects and object_box_count > 0:
@@ -418,7 +415,7 @@ def output_frames(config: FrigateConfig, video_output_queue):
): ):
if birdseye_manager.update( if birdseye_manager.update(
camera, camera,
len(current_tracked_objects), len([o for o in current_tracked_objects if not o["stationary"]]),
len(motion_boxes), len(motion_boxes),
frame_time, frame_time,
frame, frame,

View File

@@ -507,12 +507,12 @@ def process_frames(
stationary_object_ids = [ stationary_object_ids = [
obj["id"] obj["id"]
for obj in object_tracker.tracked_objects.values() for obj in object_tracker.tracked_objects.values()
# if there hasn't been motion for N frames # if there hasn't been motion for 10 frames
if obj["motionless_count"] >= detect_config.stationary_threshold if obj["motionless_count"] >= 10
# and it isn't due for a periodic check # and it isn't due for a periodic check
and ( and (
detect_config.stationary_interval == 0 detect_config.stationary.interval == 0
or obj["motionless_count"] % detect_config.stationary_interval != 0 or obj["motionless_count"] % detect_config.stationary.interval != 0
) )
# and it hasn't disappeared # and it hasn't disappeared
and object_tracker.disappeared[obj["id"]] == 0 and object_tracker.disappeared[obj["id"]] == 0

View File

@@ -29,12 +29,8 @@ function Camera({ name, conf }) {
const { payload: snapshotValue, send: sendSnapshots } = useSnapshotsState(name); const { payload: snapshotValue, send: sendSnapshots } = useSnapshotsState(name);
const href = `/cameras/${name}`; const href = `/cameras/${name}`;
const buttons = useMemo(() => { const buttons = useMemo(() => {
const result = [{ name: 'Events', href: `/events?camera=${name}` }]; return [{ name: 'Events', href: `/events?camera=${name}` }, { name: 'Recordings', href: `/recording/${name}` }];
if (conf.record.enabled) { }, [name]);
result.push({ name: 'Recordings', href: `/recording/${name}` });
}
return result;
}, [name, conf.record.enabled]);
const icons = useMemo( const icons = useMemo(
() => [ () => [
{ {

View File

@@ -46,7 +46,7 @@ describe('Cameras Route', () => {
expect(screen.queryByLabelText('Loading…')).not.toBeInTheDocument(); expect(screen.queryByLabelText('Loading…')).not.toBeInTheDocument();
expect(screen.queryAllByText('Recordings')).toHaveLength(1); expect(screen.queryAllByText('Recordings')).toHaveLength(2);
}); });
test('buttons toggle detect, clips, and snapshots', async () => { test('buttons toggle detect, clips, and snapshots', async () => {