mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Ability to configure min frames for zone presence (#6680)
* Objects need to be in zones multiple times to be considered present in the zone * Add a field to configure inertia per zone * Formatting * Use correct default method * Clarify zone presence behavior Co-authored-by: Blake Blackshear <blakeb@blakeshome.com> --------- Co-authored-by: Blake Blackshear <blakeb@blakeshome.com>
This commit is contained in:
parent
fd6eb78f41
commit
b160abac0d
@ -467,6 +467,8 @@ cameras:
|
|||||||
# Required: List of x,y coordinates to define the polygon of the zone.
|
# Required: List of x,y coordinates to define the polygon of the zone.
|
||||||
# NOTE: Presence in a zone is evaluated only based on the bottom center of the objects bounding box.
|
# NOTE: Presence in a zone is evaluated only based on the bottom center of the objects bounding box.
|
||||||
coordinates: 545,1077,747,939,788,805
|
coordinates: 545,1077,747,939,788,805
|
||||||
|
# Optional: Number of consecutive frames required for object to be considered present in the zone. Allowed values are 1-10 (default: shown below)
|
||||||
|
inertia: 3
|
||||||
# Optional: List of objects that can trigger this zone (default: all tracked objects)
|
# Optional: List of objects that can trigger this zone (default: all tracked objects)
|
||||||
objects:
|
objects:
|
||||||
- person
|
- person
|
||||||
|
@ -330,6 +330,12 @@ class ZoneConfig(BaseModel):
|
|||||||
coordinates: Union[str, List[str]] = Field(
|
coordinates: Union[str, List[str]] = Field(
|
||||||
title="Coordinates polygon for the defined zone."
|
title="Coordinates polygon for the defined zone."
|
||||||
)
|
)
|
||||||
|
inertia: int = Field(
|
||||||
|
default=3,
|
||||||
|
title="Number of consecutive frames required for object to be considered present in the zone.",
|
||||||
|
gt=0,
|
||||||
|
le=10,
|
||||||
|
)
|
||||||
objects: List[str] = Field(
|
objects: List[str] = Field(
|
||||||
default_factory=list,
|
default_factory=list,
|
||||||
title="List of objects that can trigger the zone.",
|
title="List of objects that can trigger the zone.",
|
||||||
|
@ -73,6 +73,7 @@ class TrackedObject:
|
|||||||
self.colormap = colormap
|
self.colormap = colormap
|
||||||
self.camera_config = camera_config
|
self.camera_config = camera_config
|
||||||
self.frame_cache = frame_cache
|
self.frame_cache = frame_cache
|
||||||
|
self.zone_presence = {}
|
||||||
self.current_zones = []
|
self.current_zones = []
|
||||||
self.entered_zones = []
|
self.entered_zones = []
|
||||||
self.false_positive = True
|
self.false_positive = True
|
||||||
@ -144,13 +145,24 @@ class TrackedObject:
|
|||||||
if len(zone.objects) > 0 and obj_data["label"] not in zone.objects:
|
if len(zone.objects) > 0 and obj_data["label"] not in zone.objects:
|
||||||
continue
|
continue
|
||||||
contour = zone.contour
|
contour = zone.contour
|
||||||
|
zone_score = self.zone_presence.get(name, 0)
|
||||||
# check if the object is in the zone
|
# check if the object is in the zone
|
||||||
if cv2.pointPolygonTest(contour, bottom_center, False) >= 0:
|
if cv2.pointPolygonTest(contour, bottom_center, False) >= 0:
|
||||||
# if the object passed the filters once, dont apply again
|
self.zone_presence[name] = zone_score + 1
|
||||||
if name in self.current_zones or not zone_filtered(self, zone.filters):
|
|
||||||
current_zones.append(name)
|
# an object is only considered present in a zone if it has a zone inertia of 3+
|
||||||
if name not in self.entered_zones:
|
if zone_score >= zone.inertia:
|
||||||
self.entered_zones.append(name)
|
# 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 < zone.inertia:
|
||||||
|
self.zone_presence[name] = zone_score - 1
|
||||||
|
|
||||||
if not self.false_positive:
|
if not self.false_positive:
|
||||||
# if the zones changed, signal an update
|
# if the zones changed, signal an update
|
||||||
|
Loading…
Reference in New Issue
Block a user