This post documents a reproducible mini-project: a real-time “face gate” prototype built with OpenCV for camera capture and OpenVINO for inference.
Source code:<CashStolen/rpi-myriad-face-reg>
1)pipeline overview
The core pipeline is:
- Capture a frame (BGR) with OpenCV.
- Run face detection to get one or more bounding boxes.
- For each face ROI:
- Crop the face region (optionally with padding).
- Run emotion recognition on the face ROI.
- Select a corresponding emoji PNG (e.g., happy/sad/angry/neutral/surprise).
- Overlay the emoji sticker above the face (or centered on the forehead).
This design keeps the code modular and makes it easy to swap models or tune thresholds.
2)environment
- OS: Debian 13 Rpi4
- Python: 3.10 (my project uses a dedicated environment)
- Key dependencies:
opencv-python4.10.0.844openvino2022.3.2numpy1.24.4
Install dependencies:(the requirement.txt lies in my git project)
pip install -r requirements.txt3)models
This project uses two OpenVINO IR models (.xml + .bin):
face-detection-adas-0001emotions-recognition-retail-0003
The expected path after your download:
models/intel/face-detection-adas-0001/FP16/face-detection-adas-0001.xml
models/intel/face-detection-adas-0001/FP16/face-detection-adas-0001.bin
models/intel/emotions-recognition-retail-0003/FP16/emotions-recognition-retail-0003.xml
models/intel/emotions-recognition-retail-0003/FP16/emotions-recognition-retail-0003.bin4)quick start
First of all, get the index of your camera
Then, after finishing the necessary connection and settings of your Rpi4 or 5 and camera device, it’s time to run our project.
Example command:(your can also write in a line)
python <ENTRY_SCRIPT>.py \
--cam 1 \
--device MYRIAD \
--fd_model "models/intel/face-detection-adas-0001/FP16/face-detection-adas-0001.xml" \
--emo_model "models/intel/emotions-recognition-retail-0003/FP16/emotions-recognition-retail-0003.xml" \
--emojis_dir "emojis" \
--conf 0.6--cam: camera index (USB camera often 1)
--device: MYRIAD (default) or another OpenVINO target(maybe CPU?)
--conf: face confidence threshold (higher = fewer false positives)
5)how does it work?
a.How the Emoji Overlay Works
A clean overlay uses alpha blending:
- Load emoji PNG with alpha channel (RGBA).
- Resize emoji to match face size (or a fixed ratio of face width).
- Compute the overlay position (usually above the face box):
emoji_w ≈ face_w * 1.0(or slightly larger)emoji_hscaled with aspect ratiox = face_center_x - emoji_w/2y = face_top_y - emoji_h * 0.9(place it above the head)
- Alpha blend the emoji onto the BGR frame region.
Recommended placement styles:
- Above head (like “campus gate terminal” look)
- Centered on forehead (more comedic, but can cover facial features)
b.Accuracy and Threshold Tuning
If the emoji feels “wrong” too often:
- Increase face detection threshold, e.g.
--conf 0.7 - Crop with padding (too tight crops can hurt emotion recognition)
- Ensure the emotion model receives the correct input format:
- correct resize (model input H×W)
- correct channel order (usually BGR)
- correct normalization (depends on model)
Also note:
- Emotion recognition is sensitive to lighting, pose, occlusion, and resolution.
- For small faces in the frame, results will be unstable (this is normal).
c.Performance Tips (Lower Latency)
Our FPS is a bit low(about 10)using MYRIAD and lower(only 5)with CPU on RPi4.
If you see lag:
- Reduce camera resolution (e.g., 640×360)
- Run emotion inference every N frames (e.g., every 2–4 frames)
- Limit processing to the largest face (optional)
- Avoid expensive per-frame image conversions
A practical configuration is:
- Face detection every frame or every 2 frames
- Emotion recognition every 2–4 frames per face
ooo. Troubleshooting
The window opens but feels delayed
- Lower camera resolution / FPS
- Reduce inference frequency
- Ensure you are not buffering too many frames
Face boxes exist but no emoji appears
- Check
emojis_dirpath - Verify PNG files have alpha channel (RGBA)
- Confirm overlay coordinates are clamped within image bounds
Emojis appear but are tiny or off-screen
- Increase scale ratio (use face width as reference)
- Clamp
(x, y)so the emoji stays within the frame
Summary
This project demonstrates a complete real-time CV demo using OpenVINO:
- robust face detection
- emotion classification per face
- a fun and readable UI via emoji overlay
In the mean time, I have to emphasize that I cannot upload any photos related to our project for the reason that they are too private for my friends and I. And I believe that all of you can understand my project easily!^_^
And just feel free to exchange the project into your better one!<CashStolen/rpi-myriad-face-reg>
