Skip to main content

Overview

The objdetect 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

MethodSpeedAccuracyUse Case
CascadeFastGoodReal-time face/object
HOGMediumGoodPedestrian detection
DNNSlowBestHigh accuracy needed
QR DetectorFastHighQR/Barcode scanning

Best Practices

Cascade Classifiers

  1. Preprocess images: Equalize histogram, reduce noise
  2. Adjust minNeighbors: Higher = fewer false positives
  3. Set size constraints: Filter by expected object size
  4. Use appropriate cascade: frontal vs profile faces

HOG Detector

  1. Standard window: Use 64x128 for pedestrians
  2. Multi-scale detection: Essential for varying sizes
  3. Non-maximum suppression: Remove overlapping detections
  4. GPU acceleration: Use cv::cuda::HOG for speed

See Also