-1

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?

scrpy
  • 985
  • 6
  • 23
Ziniz
  • 65
  • 5
  • 1
    Most of the downvotes are usually due to a question being unclear. If you add more specifics of exactly what you want, what have you done, and what is wrong, you get better answers. Also, questions similar to: I need code for this? I try this, didn't work, what should I do? or Does anyone have a tutorial for blabla? are usually downvoted. In this case you already have 3 closing votes saying that is too broad. This means that it is not an specific question and it may have several solutions. It is better to describe what you did, put some code and say until what part works. – api55 Nov 15 '17 at 15:25
  • I think [this link](https://stackoverflow.com/help/asking) may help you ask better questions. Just go through several of the links there :) I may also try to answer your other question in a couple of hours, since I consider it follows the stackoverflow standards. – api55 Nov 15 '17 at 15:28
  • I was having bad days and was also desperate for an answer when I asked this question. Thank you very much for your suggestions. I will try to ask better question in future. – Ziniz Nov 15 '17 at 15:51

2 Answers2

2

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:

enter image description here

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)
scrpy
  • 985
  • 6
  • 23
0

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])
johncasey
  • 1,250
  • 8
  • 14