Skip to main content

Face Detection with Cascade Classifiers

Learn how to detect faces, eyes, and other facial features in images and video using OpenCV’s pre-trained Haar cascade classifiers.

Introduction to Face Detection

Face detection is one of the most common applications of computer vision. OpenCV provides robust pre-trained models that can detect faces in various conditions.

Why Haar Cascades?

  • Pre-trained models available for immediate use
  • Fast enough for real-time detection
  • No GPU required
  • Works well for frontal faces
  • Lightweight and easy to deploy

Basic Face Detection

Single Face Detection

Complete Face and Eye Detection

Based on OpenCV’s facedetect.cpp sample:

Smile Detection

Profile Face Detection

Improving Detection Accuracy

1

Preprocessing

2

Parameter Tuning

3

Multi-scale Detection

Try multiple scale factors and combine results:
4

Temporal Filtering

For video, track faces across frames:
Best practices for face detection:
  • Always convert to grayscale first
  • Use histogram equalization for better contrast
  • Start with scaleFactor=1.1 and minNeighbors=5
  • Adjust minSize based on expected face sizes
  • For video, resize frames for faster processing
  • Use nested detection (face → eyes) to verify results
Limitations of Haar cascades:
  • Works best with frontal faces
  • Struggles with occlusions (sunglasses, masks, hands)
  • Sensitive to lighting conditions
  • Less accurate than deep learning methods
  • Can produce false positives
For production applications requiring high accuracy, consider using deep learning-based face detection (see Deep Learning tutorial).

Next Steps

  • Learn about Deep Learning face detection for better accuracy
  • Explore Object Detection for detecting other objects
  • Try face recognition and facial landmarks detection