Face Detection Using HOG in python (DLIB)

           Face detection is a machine learning technique which detects face in a image.This is normally done by trianing a model and using it for later for face detection.We will provide images that has faces and train the model,such that it is able to learn what is a face and how it looks like?

There are many methods or algorithms used for face detection. One of the best method to detect a face is using HOG ,which creates a feature descriptor for images and feed into a classifier model. Mostly SVM is used for classifications.

In DLIB.we use HOG+SVM to detect a face in image.This all are done internally.DLIB already contains a pretrained model that detects face at the runtime .In this blog, we are going to use the pretrained model for face detection in a image.



STEP 1: IMPORT THE LIBRARIES

          

CV2 ->      to convert images to numpy array
dlib -> to use the pretrained model
matplotlib.pyplot -> to display the image
STEP 2:
             Specify the path of the image.

STEP 3:
             Use the DLIB Pretrained model for face detection.
STEP 4:     
             Convert the image to a numpy array.
STEP 5:  
               Convert the image from BGR to RGB.
STEP 6:  
               Get the locations of face in the image.
STEP 7: 
               Get the first index value of the locations and print it.
 STEP 8:  
              Get the top , right , bottom , left values from the locations and store it to the variables named top, right, bottom, left.

STEP 9:
               By using the top, left, right and bottom values , draw an rectangle on the image.
STEP 10:
                Display the image with the rectangle which indicates the face.


EXAMPLE IMAGE:
 

AFTER DETECTIONS: