Improve object tracking (#17671)

* Save initial frame of new objects to frame cache
Objects that move quickly through the frame and are only seen briefly may not have the update() method called to save thumbnail_data, and may not have the initial frame saved to the tracked object frame cache. This caused a "Frame missing from frame cache" message that was patched by #7313 but this sometimes caused the wrong frame to be chosen for the thumb/snapshot.

* Tracking tweaks
- When registering new objects, use the past detections from Norfair to populate self.positions and self.stationary_box_history. This prevents the first call of update_position() from triggering a +1 on the object's stationary count (because the iou would be 1.0).
- Add a specific tracker for dedicated LPR cam license_plate objects using a lower R value and higher distance threshold to account for fast moving plates.
- Add helpful debug messages and keep them disabled with `if False:`
This commit is contained in:
Josh Hawkins
2025-04-13 12:10:35 -06:00
committed by GitHub
parent e09f0a6b11
commit da62c41e87
3 changed files with 68 additions and 9 deletions
+21
View File
@@ -263,6 +263,27 @@ class CameraState:
current_detections[id],
)
# add initial frame to frame cache
self.frame_cache[frame_time] = np.copy(current_frame)
# save initial thumbnail data and best object
thumbnail_data = {
"frame_time": frame_time,
"box": new_obj.obj_data["box"],
"area": new_obj.obj_data["area"],
"region": new_obj.obj_data["region"],
"score": new_obj.obj_data["score"],
"attributes": new_obj.obj_data["attributes"],
"current_estimated_speed": 0,
"velocity_angle": 0,
"path_data": [],
"recognized_license_plate": None,
"recognized_license_plate_score": None,
}
new_obj.thumbnail_data = thumbnail_data
tracked_objects[id].thumbnail_data = thumbnail_data
self.best_objects[new_obj.obj_data["label"]] = new_obj
# call event handlers
for c in self.callbacks["start"]:
c(self.name, new_obj, frame_name)