Face detection using dlib HOG

srujan jack
MLCrunch
Published in
3 min readJul 17, 2020

If this is your first face identification story, I would recommend taking a look at this free course to learn the basics of face identification and deep learning.

This is based on the HOG (Histogram of Oriented Gradients) feature descriptor with a linear SVM machine learning algorithm to perform face detection.

HOG is a simple and powerful feature descriptor. It is not only used for face detection but also it is widely used for object detection like cars, pets, and fruits. HOG is robust for object detection because object shape is characterized using the local intensity gradient distribution and edge direction.

Step1: The basic idea of HOG is dividing the image into small connected cells

Divide the image into small cells

Step2: Computes histogram for each cell. Click here to learn more about the histogram

Compute the histogram of each cell

Step3: Bring all histograms together to form feature vector i.e., it forms one histogram from all small histograms which is unique for each face

Combines small histograms into one histogram which is a final feature vector

The only disadvantage with HOG based face detection is that it doesn’t work on faces at odd angles, it only works with straight and front faces. It is really useful if you use it to detect faces from scanned documents like driver’s license and passport but not a good fit for real-time video.

If you are looking for an algorithm to detect faces from real-time video streaming, following face detections are the best:

  1. CNN based face detection
  2. DNN face detector from opencv
  3. Face detection using cvlib

Let’s do coding to detect faces using HOG, dlib library has a straight forward method to return HOG face detector “dlib.get_frontal_face_detector()”

It displays the following output

Output

HOG is not good at detecting odd faces.

You can notice HOG missed few faces

Dlib has another algorithm based on CNN to detect faces which is powerful than HOG, click here to know more about it.

--

--