Member-only story

OpenCV Series — 6— Face Alignment

Rajathithan Rajasekar
4 min readMay 28, 2020

--

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 ).

Picture with slanted face image

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.

main 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.

--

--

Rajathithan Rajasekar
Rajathithan Rajasekar

Written by Rajathithan Rajasekar

I like to write code in Python . Interested in cloud , dataAnalysis, computerVision, ML and deepLearning. https://rajathithanrajasekar.medium.com/membership

No responses yet