feat: use YuNet face detection with debug-only live boxes
This commit is contained in:
@@ -24,35 +24,38 @@ SHA-256: `db0898ae717b76b075d9bf563af315b29562e11f8df5027a1ef07b02bef6d81c`
|
||||
|
||||
# Capture face counting
|
||||
|
||||
The bundled `haarcascade_frontalface_alt2.xml` and
|
||||
`haarcascade_eye_tree_eyeglasses.xml` are OpenCV Haar cascades from
|
||||
https://github.com/opencv/opencv/tree/4.6.0/data/haarcascades.
|
||||
Each XML includes its upstream license notice. They are embedded in the binary;
|
||||
no model downloads or external model paths are needed at runtime.
|
||||
Faces are detected with OpenCV YuNet (`face_detection_yunet_2023mar.onnx`),
|
||||
replacing the Haar face and eye cascades. The 228 KiB ONNX model is embedded in
|
||||
the executable, loaded once, and run with OpenCV DNN on CPU. OpenCV 4.8 or newer
|
||||
with DNN and FaceDetectorYN buffer loading is required (tested with 4.10).
|
||||
|
||||
Detection runs once per capture and at most twice per second for the live preview,
|
||||
with the longest image edge capped at 640 px,
|
||||
using a frontal-face cascade with an optional eye-pair check. When fewer than two
|
||||
eyes are detected, the frontal-face result is accepted: missing eyes are not
|
||||
reliable evidence of a side view. When two or more eyes are detected, a roughly
|
||||
level, centered pair is required. Debug output includes the acceptance reason.
|
||||
Faces below 40 px may be missed, and some turned faces may still pass the frontal
|
||||
cascade. This is a best-effort side-view filter, not an exact gaze estimator. OpenCV is limited to
|
||||
two threads. Validate counts and timings with representative group photos on the
|
||||
kiosk before deployment; no accuracy or latency guarantee is implied.
|
||||
Source: https://github.com/opencv/opencv_zoo/tree/main/models/face_detection_yunet
|
||||
|
||||
The current capture is the clean mirrored 640×480 camera frame, before overlays.
|
||||
The app sends a JPEG to `lp -n COUNT -o fit-to-page` using the default CUPS printer
|
||||
and its configured paper/media settings. Install the CUPS client (`lp`) and set
|
||||
up the default printer on the kiosk. Zero accepted faces means no print job;
|
||||
detection/printing errors are logged without stopping the preview or retrying a
|
||||
possibly submitted job. Debug logs include candidate boxes, eye counts, rejected
|
||||
faces, accepted face/copy count, detection duration and CUPS submission result.
|
||||
Weights: https://media.githubusercontent.com/media/opencv/opencv_zoo/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx
|
||||
|
||||
Live preview rectangles show every frontal-face candidate: green (`#84bf65`)
|
||||
means accepted for printing; blue (`#4caee3`) means rejected by the eye-pair check.
|
||||
Rectangles use mirrored camera coordinates and share the preview cover crop.
|
||||
They are cached between samples and cleared by empty results or detection errors.
|
||||
They never appear in detector inputs or the printed photo. Live sampling is quiet;
|
||||
full per-face debug information is emitted for captures only. The preview is
|
||||
sampled separately from capture, so counts can change with movement or lighting.
|
||||
SHA-256: `8f2383e4dd3cfbb4553ea8718107fc0423210dc964f9f4280604804ed2552fa4`
|
||||
|
||||
License: MIT, reproduced in `YUNET_LICENSE`.
|
||||
|
||||
Images retain their aspect ratio, with the longest edge resized to 320 px and
|
||||
black padding to 320×320. Confidence threshold is 0.8, NMS threshold 0.3 and top K
|
||||
500. Predicted eye and nose landmarks filter strongly turned faces: the nose
|
||||
projection must fall within the central 70% of the eye line, with eye separation
|
||||
at least 23% of the face width. This tolerates roll and mirrored coordinates and
|
||||
does not depend on a separate eye detector. It estimates frontal head orientation,
|
||||
not eye gaze. Small, occluded or strongly tilted faces can still be missed;
|
||||
validate group-photo accuracy and timings on the target kiosk.
|
||||
|
||||
The clean mirrored camera frame is counted once after capture. Debug logs retain
|
||||
candidate boxes, confidence, accepted/rejected counts, intended copies and timing.
|
||||
The count is passed to an intentionally empty `print_picture` hook. There is no
|
||||
printer command, image encoding, file output or physical printing yet.
|
||||
|
||||
Face rectangles and live face inference are enabled only in debug builds
|
||||
(`cargo run`); release builds (`cargo run --release`) have neither. The debug
|
||||
worker samples at most twice per second, drops samples while busy, and expires
|
||||
results after 1.5 seconds. Green (`#84bf65`) means accepted; blue (`#4caee3`) means
|
||||
rejected for head orientation. Rectangles use mirrored camera coordinates and
|
||||
share the preview crop, but never enter capture or detector input. Counts are
|
||||
always recomputed on the captured frame and can differ from the last live sample.
|
||||
OpenCV remains limited to two threads; actual kiosk latency needs measurement.
|
||||
|
||||
Reference in New Issue
Block a user