Face Detection with OpenCV for non frontal images

2020-05-18 16:52发布

问题:

I am trying to use opencv to detect faces. Faces are not frontal, the camera captured the faces from side so only one eye and part of the mouth is viewed. I tried HaarDetectObjects with multiple configurations without getting benefit. I changed the cascade and I tested: haarcascade_frontalface_default.xml, haarcascade_frontalface_alt.xml,haarcascade_profileface.xml with very bad results. Are there any other better cascades? Are there other suggestions?

Thanks

回答1:

Now you have in OpenCV the new LBP cascade for profile faces, created by Vadim Pisarevsky:

https://github.com/Itseez/opencv/blob/master/data/lbpcascades/lbpcascade_profileface.xml

Apparently, it only detects right profile faces, so to detect all profile faces one has to run a second step with the image flipped.



回答2:

The cascade files you referenced (e.g. aarcascade_frontalface_default.xml, haarcascade_frontalface_alt.xml, haarcascade_profileface.xml) are created using full frontal faces to detect full frontal faces. So, half of a face wouldn't obviously be correctly recognized as the correct shape to a computer.

What you may need to do in this situation is to train OpenCV to recognize your object of interest which is "half of a face_ in this case. In OpenCV jargon it is known as - 'HaarTraining'. Use this, this and this article as a starting point to start training.

Once you have trained OpenCV using your data (e.g. lots of different images of half of a face), you will have an XML cascade file ready which you can plug into your own code to detect half of a face.

Good luck!



回答3:

I had been dealing with the same problem of face detection for non-frontal images. Try using Multi Task CNN. It's the best solution for face detection and alignment. It is able to deal with problems like various poses, lighting, occlusion.

The paper is available at Link. The code is available on GitHub at Link. I used the python implementation and the results are outstanding. Although the code is a little slow if the image has a lot of faces.

Although if you want to stick to OpenCV, then a new deep learning model for face detection has been added to OpenCV. The results are not as good as Multi Task CNN. There's an implementation of OpenCV Deep Learning Model for Face Detection at pyimagesearch Link