Member-only story
OpenCV Series — 6— Face Alignment
In this post , we are going to see about how to do face alignment in images using dlib’s frontal face detector, dlib’s shape predictor — 5 point model , estimateAffinePartial2D and warpaffine, I have taken the below picture for face alignment , ( courtesy: pexels free stock photos ).
Load the below python libraries
import sys
import cv2
import dlib
import numpy as np
import math
Let’s start with the main function , define the Dlib’s shape predictor 5 point model file and the frontal face detector. Pass the facedetector , shape-predictor and image data to the getLandmarks function.
In the getLandmarks function, we resize the image and detect the number of faces in the image using faceDetector . From the detected face, we get the rectangular points around the face image , which are then passed on to landmark detection for landmark details.