Face Detection 60 FPS
π Overview
Face detection with OpenCV's built-in Haar cascade classifier runs at roughly 60 frames per second on an ordinary laptop.
Compared with deep-learning options such as MediaPipe, a Haar cascade is tiny and barely touches the CPU, which suits resource-constrained hardware or scenes that need maximum frame rate - and it is the best place to start understanding classic computer vision detection.
π§° What you need
- Computer + camera
- Python 3.7+ environment
- pip install: opencv-python
- Optional: image/video files for offline testing
π§ Step by step
Install OpenCV
pip install opencv-python
The Haar models ship with OpenCV, so there is nothing extra to download
Load the cascade classifier
Load the face detection xml model with CascadeClassifier
The common one: frontal face (haarcascade_frontalface_default)
Convert to grayscale and detect
detectMultiScale slides a window over the grayscale image
Working in grayscale speeds detection up considerably
Draw the boxes
Draw a rectangle for each returned (x, y, w, h)
You can add anti-aliased lines and text labels
Tune the parameters
scaleFactor, minNeighbors, and minSize trade missed detections against false positives
Raising minNeighbors reduces false positives; lowering it reduces misses
Compare frame rates and apply it
Measure and display the FPS on the frame
It can feed downstream work such as green screen, effects, or attendance
π‘ Tips
- Profile views and sunglasses will be missed - that is an inherent limit of the Haar approach
- Detecting on a downscaled frame raises the frame rate further; just scale the box coordinates back up
- Set minSize to 30x30 or more to avoid false detections in small windows