Overview
Theobjdetect module provides tools for detecting objects in images, including:
- Cascade classifiers (Haar, LBP)
- HOG (Histogram of Oriented Gradients) detector
- QR code and barcode detection
- ArUco marker detection
- Face detection
Cascade Classifier
Overview
Cascade classifiers detect objects using Haar-like or LBP features trained with boosting algorithms.Basic Usage
Parameters
- scaleFactor: Image pyramid scale (typically 1.05-1.4)
- minNeighbors: Minimum neighbors for detection (3-6 typical)
- minSize/maxSize: Size constraints for detected objects
Pre-trained Models
OpenCV includes cascades for:- Face detection (frontal, profile)
- Eye detection
- Full body detection
- Upper body detection
- License plate detection
HOG Descriptor
Overview
Histogram of Oriented Gradients (HOG) is a feature descriptor used for object detection, particularly for pedestrian detection.Structure
Pedestrian Detection
Custom Training
QR Code Detection
QRCodeDetector
Multiple QR Codes
ArUco Marker Detection
Basic Detection
Face Detection
Modern DNN-based Detection
Complete Example: Face Detection
Performance Tips
Use Grayscale
Convert to grayscale before detection
Scale Down
Resize large images for faster processing
ROI Processing
Limit detection to region of interest
Adjust Parameters
Tune scaleFactor and minNeighbors for speed/accuracy
Algorithm Selection
| Method | Speed | Accuracy | Use Case |
|---|---|---|---|
| Cascade | Fast | Good | Real-time face/object |
| HOG | Medium | Good | Pedestrian detection |
| DNN | Slow | Best | High accuracy needed |
| QR Detector | Fast | High | QR/Barcode scanning |
Best Practices
Cascade Classifiers
- Preprocess images: Equalize histogram, reduce noise
- Adjust minNeighbors: Higher = fewer false positives
- Set size constraints: Filter by expected object size
- Use appropriate cascade: frontal vs profile faces
HOG Detector
- Standard window: Use 64x128 for pedestrians
- Multi-scale detection: Essential for varying sizes
- Non-maximum suppression: Remove overlapping detections
- GPU acceleration: Use cv::cuda::HOG for speed
See Also
- DNN Module - Deep learning based detection
- Features2D - Feature detection
- Face Recognition Tutorial
