I have used dlib library for facial landmark detection. But when the face is non frontal then dlib's "frontal_face_detector" can't detect the face.
Is there any other way to detect facial landmarks in a profile face?
I have used dlib library for facial landmark detection. But when the face is non frontal then dlib's "frontal_face_detector" can't detect the face.
Is there any other way to detect facial landmarks in a profile face?
In my experience, Dlib's default face detector (e.g. detector = dlib.get_frontal_face_detector()
in the Python API) works well on non-frontal faces, and can even detect faces close to profile.
According to the source code, that's because it's a HOG based detector which is actually built out of 5 different HOG filters:
It is built out of 5 HOG filters. A front looking, left looking, right looking, front looking but rotated left, and finally a front looking but rotated right one.
Here's an example detection:
And here's the Python 3 code I used (uses OpenCV to read/write the image and draw the rectangle):
import cv2
import dlib
img = cv2.imread('will.jpg')
detector = dlib.get_frontal_face_detector()
dets = detector(img, 1)
face = dets[0]
cv2.rectangle(img, (face.left(), face.top()), (face.right(), face.bottom()), (0, 255, 0), 2)
cv2.imwrite('out.jpg', img)
OpenCV's haar cascade is a legacy method. You should try deep learning based ones such as ssd or mtcnn. Herein, deepface wraps opencv, ssd, dlib and mtcnn to detect and align faces.
#!pip install deepface
from deepface import DeepFace
backends = ['opencv', 'ssd', 'dlib', 'mtcnn']
detected_face = DeepFace.detectFace("img.jpg", detector_backend = backends[3])