Overview
OpenCV provides multiple approaches for face detection and recognition:- Haar Cascade Classifiers: Fast, CPU-friendly classical method
- DNN-based Detection: Modern deep learning approach with YuNet
- Face Recognition: Feature extraction and matching with SFace
- Facial Landmarks: Detect eyes, nose, and mouth positions
Haar Cascade Face Detection
- Python
- C++
DNN-based Face Detection with YuNet
Modern deep learning approach using the YuNet model for accurate face detection with facial landmarks.Face Recognition with SFace
Compare faces and determine if they belong to the same person.Key Parameters
Haar Cascade Detection
| Parameter | Description | Typical Value |
|---|---|---|
scaleFactor | Image scale reduction between scans | 1.1 - 1.3 |
minNeighbors | Minimum neighbors for detection | 3 - 6 |
minSize | Minimum object size | (30, 30) |
maxSize | Maximum object size | Image size |
YuNet Detection
| Parameter | Description | Typical Value |
|---|---|---|
score_threshold | Confidence threshold | 0.6 - 0.9 |
nms_threshold | Non-maximum suppression | 0.3 - 0.5 |
top_k | Max detections before NMS | 5000 |
Model Downloads: YuNet and SFace models can be downloaded from the OpenCV Zoo:
Performance Tips
Cascade Parameters
Tune
minNeighbors to balance speed vs accuracy:- Lower values = faster, more false positives
- Higher values = slower, fewer false positives
Next Steps
- Explore Object Detection for other detection methods
- Learn about DNN Module for deep learning models
- Check Video I/O for camera handling
- See Image Processing for preprocessing techniques
