Face detection is a specific area of computer vision and image processing. It is not a new technology but only in the recent years has it been commercially acceptable due to the significant advances in processing speed of microchips and GPUs. Face detection can be used in many ways such as tagging friends in images, focus in a face or even unlock our smartphones.
But facial detection is not 100% flawless, there is a lot of differences present across human faces such as pose, expression, position and orientation and concerning the picture itself there is the lighting and image resolution.
Real-time face detection The first real-time face detector was introduced with the Viola-Jones algorithm in 2001 and it segments the photo in multiple subsections and tries to find haar-like features inside each subarea. Performance can be improved by using cascade and adaptative boosting. Although this algorithm reveals a very high accuracy detecting faces, it still contains a lot of false positives and fortunately today there are better alternatives such as Support Vector Machines, Naïve Bayes Classifiers, Deep Neural Networks (DNN), etc. We explored the DNN for facial recognition using the OpenCV library.
OpenCV’s DNN Module OpenCV is an open source computer vision and machine learning library made in C++, but you can easily find wrappers in Python, Java or C# and in this case we chose the Python wrapper. It contains out-of-the-box Haar cascades, but since version 3.3 there is pre-trained deep learning face detector. The DNN face detector is based on the Single Shot Detector (SSD) framework using a ResNet-10 like base Network.
In practice In order to use DNN face detector in OpenCV, you first need to download the Caffe files from the OpenCV repository, the deploy.prototxt file defines the network architecture and res10_300x300_ssd_iter_140000.caffemodel has the weights of the layers.
Finally, we run the input through our network, check if there are any detections and for each detection the correspondent confidence is extracted; if the confidence of the detections meets the confidence threshold (in this case we set the threshold to 0.5) the detection is accepted and the (x, y) coordinates are extracted from the box object and draw a box around the detected faces and show it.
In conclusion, the DNN face detector from OpenCV is highly accurate and easy to use.
Real-time algorithm can be used in almost every scenario despite of the conditions of the source, the lighting and image resolution, face pose, position, and facial expressions.
OpenCV is a state-of-the-art library with the latest computer vision and machine learning algorithms and it is backed by a strong an active community.
Cookies make our website work properly and better for you