Skip to content

Commit a637aea

Browse files
Update largest face status (#116)
* add largest face status * add bbox info and have face order by the bbox area * update --------- Co-authored-by: openminddev <147775420+openminddev@users.noreply.github.com>
1 parent dd33d9d commit a637aea

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

src/om1_vlm/anonymizationSys/face_recog_stream/face_tracker.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def __init__(
120120
# Track IDs seen this frame (for cleanup)
121121
self._active_ids: set = set()
122122

123+
# Current frame faces (for status queries)
124+
self._current_faces: list = []
125+
123126
@staticmethod
124127
def _init_tracker(track_buffer: int, det_conf: float = 0.5):
125128
"""Initialize BoTSORT tracker with thresholds aligned to detection confidence."""
@@ -284,6 +287,22 @@ def update(
284287
# Cleanup stale tracks
285288
self._cleanup_stale()
286289

290+
# Build faces sorted by bbox area (largest = closest first)
291+
faces = []
292+
for r in results:
293+
x1, y1, x2, y2 = r.bbox
294+
area = (x2 - x1) * (y2 - y1)
295+
ident = self._identities.get(r.track_id)
296+
name = ident.name if ident and ident.status == "identified" else "unknown"
297+
faces.append(
298+
{
299+
"name": name,
300+
"bbox": r.bbox,
301+
"area": area,
302+
}
303+
)
304+
self._current_faces = sorted(faces, key=lambda f: f["area"], reverse=True)
305+
287306
return results
288307

289308
def _get_display_name(
@@ -525,6 +544,17 @@ def get_track_identities(self) -> Dict[int, dict]:
525544
if tid in self._active_ids
526545
}
527546

547+
def get_faces(self) -> list:
548+
"""Get all faces sorted by bbox area (largest first).
549+
550+
Returns
551+
-------
552+
list of dict
553+
Each dict has 'name' (str), 'bbox' (tuple), 'area' (int).
554+
Empty list if no faces in current frame.
555+
"""
556+
return self._current_faces
557+
528558
def reset(self) -> None:
529559
"""Reset all tracking state."""
530560
self._identities.clear()

src/om1_vlm/anonymizationSys/face_recog_stream/http_api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(
8585
frame_lock: threading.Lock,
8686
run_job_sync: Callable[[Callable[[], Any]], Any],
8787
logger: Optional[logging.Logger] = None,
88+
face_tracker=None,
8889
):
8990
"""Initialize the HTTP API wrapper."""
9091
self.who = who
@@ -100,6 +101,7 @@ def __init__(
100101
self.run_job_sync = run_job_sync
101102
self.log = logger or logging.getLogger("http_api")
102103
self.server = None
104+
self.face_tracker = face_tracker
103105

104106
def stop(self) -> None:
105107
"""Stop an attached HTTP server if present."""
@@ -148,7 +150,10 @@ def _handle(self, payload: Dict[str, Any], path: str) -> Dict[str, Any]:
148150
if payload
149151
else self.who.lookback_sec
150152
)
151-
return self.who.snapshot(sec)
153+
result = self.who.snapshot(sec)
154+
if self.face_tracker is not None:
155+
result["faces"] = self.face_tracker.get_faces()
156+
return result
152157

153158
if path == "/config":
154159
return self._handle_config(payload)

src/om1_vlm/anonymizationSys/face_recog_stream/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def main() -> None:
480480
if args.recognition and arc is not None:
481481
face_tracker = FaceTracker(
482482
arc=arc,
483-
recog_interval=0.2, # run AdaFace every 0.3s per unidentified track
483+
recog_interval=0.2, # run AdaFace every 0.2s per unidentified track
484484
vote_frames=3, # collect 3 votes before deciding
485485
vote_threshold=0.5, # majority vote (2/3)
486486
max_recog_attempts=10,
@@ -684,6 +684,7 @@ def run_job_sync(fn):
684684
frame_lock=frame_lock,
685685
run_job_sync=run_job_sync,
686686
logger=logger,
687+
face_tracker=face_tracker,
687688
)
688689

689690
# Run the server here

0 commit comments

Comments
 (0)