I am using Dlib's 68 point face landmark predictor, which has 68 points that are marked on various regions of the face shown in the picture below:
I have managed to access particular points from the predicted landmarks, for example, I can select a point that is at the corner of the lip which is the 48th point in the facial landmark predictor by the following ' import cv2 import dlib from google.colab.patches import cv2_imshow
p = "path_to_shape_predictor_68_face_landmarks.dat"
img= cv2.imread('Obama.jpg')
gray=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(p)
face = detector(gray)
# Get the shape using the predictor
landmarks=predictor(gray, face)
# Defining x and y coordinates of a specific point
x=landmarks.part(48).x
y=landmarks.part(48).y
# Drawing a circle
cv2.circle(img, (x, y), 6, (0, 0, 255), -1)
cv2_imshow(img)'
It results in an image with a red small circle drawn on the specified region. However; if I want to select a point that is not a part of the 68 points of the landmark's model, how can I obtain it?
This picture will elaborate it more:
The red circle indicates the point that I have accessed using the code and the blue circle shows the desired point.
There are several solutions I may suggest to you:
1- The easy way is to use trigonometry and geometry, for instance to calculate pupil of left eye:
Full code:
2- Other solution is to use larger facial landmarks model, check this on: 81 Facial Landmarks Shape Predictor
3- The hard way is to retrain and customize your own shape detector: Train a face landmarking model
For landmarks index I used the following reference: Face reference points