From 5a2e395352257567f1b0fc8e87c123b104b5e832 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Wed, 9 Feb 2022 21:27:33 -0600 Subject: [PATCH] selectively increment position changes --- docs/docs/integrations/mqtt.md | 2 +- frigate/objects.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/docs/integrations/mqtt.md b/docs/docs/integrations/mqtt.md index c868d7e3c..b048abacb 100644 --- a/docs/docs/integrations/mqtt.md +++ b/docs/docs/integrations/mqtt.md @@ -57,7 +57,7 @@ Message published for each changed event. The first message is published when th "has_snapshot": false, "has_clip": false, "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 moved from a stationary position }, "after": { "id": "1607123955.475377-mxklsc", diff --git a/frigate/objects.py b/frigate/objects.py index 640130043..1711ed4f4 100644 --- a/frigate/objects.py +++ b/frigate/objects.py @@ -99,8 +99,16 @@ class ObjectTracker: if self.update_position(id, new_obj["box"]): self.tracked_objects[id]["motionless_count"] += 1 else: + # register the first position change and then only increment if + # the object was previously stationary + if ( + self.tracked_objects[id]["position_changes"] == 0 + or self.tracked_objects[id]["motionless_count"] + >= self.detect_config.stationary_threshold + ): + self.tracked_objects[id]["position_changes"] += 1 self.tracked_objects[id]["motionless_count"] = 0 - self.tracked_objects[id]["position_changes"] += 1 + self.tracked_objects[id].update(new_obj) def update_frame_times(self, frame_time):