video_helper.faces.recognize module
video_helper.faces.recognize
Face-recognition embeddings via OpenCV’s SFace (cv2.FaceRecognizerSF),
Apache-2.0, HuggingFace-free. SFace emits a 128-d embedding (not 512-d);
downstream stores must size themselves from FaceRecognizer.emb_dim, not a
hard-coded constant.
Alignment is delegated to cv2.FaceRecognizerSF.alignCrop, which consumes the
raw YuNet detector row (5 landmarks) to similarity-transform each face to the
canonical 112×112 template — so detection and recognition share one landmark
source and there is no second alignment implementation to keep in sync.
- class video_helper.faces.recognize.FaceRecognizer[source]
Bases:
objectLazy, reusable SFace embedder.
- embed(frame_bgr, face)[source]
Return the L2-normalised 128-d embedding for one face, or None.
The face is aligned+cropped from
frame_bgrusing its raw YuNet row, then run through SFace. ReturnsNoneon any failure so callers can skip a bad crop rather than poison an average.- Parameters:
frame_bgr (ndarray)
face (Face)
- Return type:
ndarray | None
- embed_track(frames, faces, *, top_k=12)[source]
Aggregate one persistent embedding for a face track.
Quality-gates the crops (highest detector score first — the face analogue of picking the longest, most-confident turns for a voiceprint), embeds up to
top_kof them, and returns the L2-normalised mean.Noneif no crop yields a usable embedding.