mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-17 08:35:21 +03:00
backend object speed tracking
This commit is contained in:
parent
ae797a5c7c
commit
f191dfc597
@ -21,6 +21,7 @@ from frigate.util.image import (
|
||||
is_better_thumbnail,
|
||||
)
|
||||
from frigate.util.object import box_inside
|
||||
from frigate.util.velocity import calculate_real_world_speed
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -57,6 +58,9 @@ class TrackedObject:
|
||||
self.frame = None
|
||||
self.active = True
|
||||
self.pending_loitering = False
|
||||
self.estimated_speed = 0
|
||||
self.max_estimated_speed = 0
|
||||
self.velocity_angle = 0
|
||||
self.previous = self.to_dict()
|
||||
|
||||
def _is_false_positive(self):
|
||||
@ -107,6 +111,7 @@ class TrackedObject:
|
||||
"region": obj_data["region"],
|
||||
"score": obj_data["score"],
|
||||
"attributes": obj_data["attributes"],
|
||||
"estimated_speed": self.estimated_speed,
|
||||
}
|
||||
thumb_update = True
|
||||
|
||||
@ -152,6 +157,26 @@ class TrackedObject:
|
||||
if 0 < zone_score < zone.inertia:
|
||||
self.zone_presence[name] = zone_score - 1
|
||||
|
||||
# update speed
|
||||
if zone.distances and name in self.entered_zones:
|
||||
self.estimated_speed, self.velocity_angle = (
|
||||
calculate_real_world_speed(
|
||||
zone.contour,
|
||||
zone.distances,
|
||||
self.obj_data["estimate_velocity"],
|
||||
bottom_center,
|
||||
self.camera_config.detect.fps,
|
||||
)
|
||||
if self.active
|
||||
else 0
|
||||
)
|
||||
logger.debug(
|
||||
f"Camera: {self.camera_config.name}, zone: {name}, tracked object ID: {self.obj_data['id']}, estimated speed: {self.estimated_speed:.1f}"
|
||||
)
|
||||
|
||||
if self.estimated_speed > self.max_estimated_speed:
|
||||
self.max_estimated_speed = self.estimated_speed
|
||||
|
||||
# update loitering status
|
||||
self.pending_loitering = in_loitering_zone
|
||||
|
||||
@ -232,6 +257,14 @@ class TrackedObject:
|
||||
"attributes": self.attributes,
|
||||
"current_attributes": self.obj_data["attributes"],
|
||||
"pending_loitering": self.pending_loitering,
|
||||
"pixel_velocity": str(
|
||||
tuple(
|
||||
np.round(self.obj_data["estimate_velocity"]).flatten().astype(int)
|
||||
)
|
||||
),
|
||||
"estimated_speed": self.estimated_speed,
|
||||
"max_estimated_speed": self.max_estimated_speed,
|
||||
"velocity_angle": self.velocity_angle,
|
||||
}
|
||||
|
||||
if include_thumbnail:
|
||||
@ -316,7 +349,8 @@ class TrackedObject:
|
||||
box[2],
|
||||
box[3],
|
||||
self.obj_data["label"],
|
||||
f"{int(self.thumbnail_data['score']*100)}% {int(self.thumbnail_data['area'])}",
|
||||
f"{int(self.thumbnail_data['score']*100)}% {int(self.thumbnail_data['area'])}"
|
||||
+ (f" {self.estimated_speed:.1f}" if self.estimated_speed != 0 else ""),
|
||||
thickness=thickness,
|
||||
color=color,
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user