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
OpenCV uses machine learning algorithms to search for faces within a picture. Because faces are so complicated, there isn't one simple test that will tell you if it found a face or not. Instead, there are thousands of small patterns and features that must be matched.
face_detection_model/ : Contains a pre-trained Caffe deep learning model provided by OpenCV to detect faces. This model detects and localizes faces in an image.
When it comes to a good, all-purpose face detector, I suggest using OpenCV's DNN face detector: It achieves a nice balance of speed and accuracy. As a deep learning-based detector, it's more accurate than its Haar cascade and HOG + Linear SVM counterparts. It's fast enough to run real-time on CPUs.
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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With