Skip to content

Face detection using Haar Cascades and Deep Neural Network (DNN) module in OpenCV.

Notifications You must be signed in to change notification settings

basista21/face-detection

Repository files navigation

Face Detection

Face detection using Haar Cascades (frontal face and profile face) and Deep Neural Network (DNN) module in OpenCV.

Haar Cascade Classifiers

Haar Cascade files can be downloaded from the OpenCV repository.

Deep Neural Network

The file for the pre-trained Caffe model can be found here.

Usage

Usage (using haar cascades): python face-detect-haar.py [optional.jpg]
Usage (using dnn) : python face-detect-dnn.py [optional.jpg]

If only one command line argument is supplied (the program itself e.g. face-detect-haar.py), video stream from the webcam will be used as input. If there are exactly two command line arguments and an image is provided as the second command line argument, the image will be used as input.

Examples

Running python face-detect-haar.py dominic.jpg:

Image of Dominic with Face Detection Using Haar Cascades

Running python face-detect-dnn.py dominic.jpg:

Image of Dominic with Face Detection Using DNN

The DNN detector successfully detected the third face, but with only 30.02% confidence.

Comparison

Haar cascades vs DNN:

image

A false positive and a false negative for the haar face detector. DNN successfully detected the face.



image

A true positive and a false positive for each.