Published in


Face detection using dlib HOG

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

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

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

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

HOG is not good at detecting odd faces.

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



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store