From 4015b5836af1bc7a232d17639ead56108274132e Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Thu, 1 Jun 2023 10:56:08 -0600 Subject: [PATCH] Objects need to be in zones multiple times to be considered present in the zone --- frigate/object_processing.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/frigate/object_processing.py b/frigate/object_processing.py index f9046d0ab..ca210e6db 100644 --- a/frigate/object_processing.py +++ b/frigate/object_processing.py @@ -73,6 +73,7 @@ class TrackedObject: self.colormap = colormap self.camera_config = camera_config self.frame_cache = frame_cache + self.zone_presence = {} self.current_zones = [] self.entered_zones = [] self.false_positive = True @@ -144,13 +145,22 @@ class TrackedObject: if len(zone.objects) > 0 and obj_data["label"] not in zone.objects: continue contour = zone.contour + zone_score = self.zone_presence.get(name, 0) # check if the object is in the zone if cv2.pointPolygonTest(contour, bottom_center, False) >= 0: - # if the object passed the filters once, dont apply again - if name in self.current_zones or not zone_filtered(self, zone.filters): - current_zones.append(name) - if name not in self.entered_zones: - self.entered_zones.append(name) + self.zone_presence[name] = zone_score + 1 + + # an object is only considered present in a zone if it has a zone inertia of 3+ + if zone_score >= 3: + # if the object passed the filters once, dont apply again + if name in self.current_zones or not zone_filtered(self, zone.filters): + current_zones.append(name) + if name not in self.entered_zones: + self.entered_zones.append(name) + else: + # once an object has a zone inertia of 3+ it is not checked anymore + if 0 < zone_score < 3: + self.zone_presence[name] = zone_score - 1 if not self.false_positive: # if the zones changed, signal an update