fix: face_tracker.py now supports list format for frames

This commit is contained in:
Accusys
2026-09-27 01:14:28 +08:00
parent 921bcba43a
commit 696ede8696
4 changed files with 618 additions and 4 deletions
+18 -1
View File
@@ -315,6 +315,19 @@ def track_faces(
print("No frames found in face.json")
return face_data
# Support both list and dict formats
if isinstance(frames, list):
# List format: [{frame: 0, faces: [...]}, ...]
sorted_frames = sorted(frames, key=lambda x: x.get("frame", 0))
# Convert to dict format for consistency
frames_dict = {}
for frame_data in sorted_frames:
frame_num = frame_data.get("frame")
if frame_num is not None:
frames_dict[str(frame_num)] = {"faces": frame_data.get("faces", [])}
frames = frames_dict
face_data["frames"] = frames
sorted_frames = sorted(frames.items(), key=lambda x: int(x[0]))
next_trace_id = 0
@@ -439,7 +452,7 @@ def track_faces(
"start_frame": path[0]["frame"],
"end_frame": path[-1]["frame"],
"duration_frames": duration_frames,
"duration_seconds": duration_frames / face_data["metadata"]["fps"],
"duration_seconds": duration_frames / face_data.get("metadata", {}).get("fps", face_data.get("fps", 30.0)),
"total_appearances": len(path),
"avg_confidence": avg_confidence,
"pose_angles": pose_angles,
@@ -449,6 +462,10 @@ def track_faces(
"path": path,
}
# Ensure metadata exists
if "metadata" not in face_data:
face_data["metadata"] = {}
face_data["metadata"]["trace_stats"] = {
"total_traces": next_trace_id,
"active_traces": len(traces),
+21 -3
View File
@@ -210,10 +210,28 @@ def update_trace_ids(
payload = point.get("payload", {})
frame = payload.get("frame")
# Support two bbox formats:
# 1. Nested bbox field
# 2. Direct x, y, width, height fields
bbox = payload.get("bbox", {})
bbox_key = (
f"{bbox.get('x')}_{bbox.get('y')}_{bbox.get('width')}_{bbox.get('height')}"
)
if bbox:
# Format 1: has bbox field
x = bbox.get('x')
y = bbox.get('y')
width = bbox.get('width')
height = bbox.get('height')
else:
# Format 2: direct fields
x = payload.get('x')
y = payload.get('y')
width = payload.get('width')
height = payload.get('height')
if x is None or y is None or width is None or height is None:
continue
bbox_key = f"{x}_{y}_{width}_{height}"
trace_id = trace_mapping.get(frame, {}).get(bbox_key)
if trace_id is None: