Artists Face Detection using OpenCV

Automatically Detecting Faces of Artists in Images.

Yash Sharma
StarClinch Blog
6 min readJul 21, 2018

--

Introduction

Creating Artist Profiles at StarClinch is a very tedious and troublesome task which can take hours and sometimes even a whole day to create a single profile and is semi-manual at the moment. There are four separate processes for building an artist profile and making it live on the StarClinch website. The first step is information gathering, where a member of the business team contacts the artists via phone call or email and tries to gather as much information as he/she can from the artist or the manager of that particular artist. In this step business team also asks for videos, images (and link to SoundCloud playlist if the artist is a Singer, DJ or Live Band). Then, the information captured in the first step gets added to the database and profile gets forwarded to the graphics team and content writing team. The responsibility of the graphics team is to make sure that neither the images nor videos contain a phone number, email address or any links to other websites whereas content writing team writes the biography and tagline for the artist profile. After that, the artist profile from the graphics team and content writing team are merged together into one complete profile. The last step is to review the profile as a whole and make it live on the website.

Problem

Can we improve the process of creating an artist profile using Machine Learning?

The most time-consuming task is for the graphics team to check whether the pictures are suitable to be used at the website that is whether the face of the artist is visible or not. The other time-consuming task also falls under the graphics team which is to check whether the images and videos contain a phone number, email address or any other text in it. Both of these tasks are manual at the moment where the member of the graphics team has to go through each image (or video) one by one to make sure it is suitable to display it on the website.

Machine Learning especially ML in Computer Vision can be used to improve these two tedious processes. Let’s define the problem statement for this article.

Problem Statement

Automate the process of detecting artist’s faces in Images.

Given, an image of an artist automatically detects whether it contains the face (or faces) in it. If yes, then pass it to the next stage otherwise issue an alert to the user (member of the graphics team) to check the image and make the final decision as to whether discard the image or keep it.

Face Detection on the image of Sunny Leone. Image Source

Detecting Faces

There are many libraries, algorithms, and pre-trained models available on the internet that can be used to detect faces.

OpenCV

Open Source Computer Vision Library is as the name suggests an open source library to perform tasks related to computer vision. It contains many pre-trained machine learning models for different use-cases one such model is to detect faces in images (or videos) using the Cascades.

A cascade is a series of classifiers that are applied one-by-one on any given image to detect whether the image contains a face or not. In practice, these are just XML files which comprise of some OpenCV data and rules that help in accomplishing the task.

For more detail information on how OpenCV works and how to use it check out this tutorial by sentdex and this article by superdatascience.

Let’s detect artist faces using Harr Cascade Classifier which is a machine learning based approach developed by Paul Viola and Michael Jones which uses Harr-like features.

Initialize the Classifier by passing the XML file. Load the image in memory and convert it into grayscale as most of the operations in OpenCV are done in grayscale.

deteMultiScale() function is used to detect objects in images, which is being called by the face_cascade to detect faces. Parameters of detectMultiScale() function are:

  1. The image in grayscale.
  2. scaleFactor is used to specify how much the image size is to be reduced at each image scale to compensate for the false perception of the face size that occurs when one face appears to be bigger than the other because it was closer to the camera.
  3. minNeighbors: As the algorithm uses a moving window to detect objects (in this case faces), minNeighbor specifies how many neighbors each candidate rectangle should have to retain it in other words it defines how many objects get detected near the current box before declaring the face found.
  4. minSize defines the size of the window that is, objects smaller than minSize gets ignored.
Faces Found using default values. Image Source

Algorithm detected the face of Sunny Leone correctly but also labeled other parts of the image as faces which is not correct. Let’s see one more example.

Wrong Faces Detected. Image Source

Again the same problem of false face detection by the algorithm. A simple tweak to scaleFactor can increase the accuracy of detecting only actual faces. After tweaking the value of scaleFactor, I found that scaleFactor = 1.6 got rid of all the wrong faces.

Sunny Leone Face Detected. Image Source

Result

Harr Cascade Classifier was successful in detecting faces 96 times out of 100. The four times it failed in discovering face were where either the face was covered or not visible. One such example of the classifier not able to detect the face is when the face is horizontal instead of being vertical.

Failed to Detect Face. Image Source

In the above image, the face is visible but doesn’t get detected by the classifier. The fact that the face is horizontal rather than being vertical in the picture causes the classifier to think it’s not an actual face. Let’s try rotating the image and running the algorithm once again.

Image Source

Bingo

NOTE: OpenCV 3.3 included a more powerful model for detecting faces. The model uses the power of Deep Neural Networks to improve the accuracy. The model supports caffe, tensorflow and even PyTorch. Those who are interested in learning about it more check out the tutorial by Adrian Rosebrock link in the references below.

END

This article was about detecting faces one of the two time-consuming tasks in creating-artist-profiles. Next article would be about how to automatically capture text like phone number, email address and website URLs in pictures.

Thank you

References

  1. OpenCV Playlist by sentdex.
  2. Face Detection using Haar Cascades
  3. Machine Learning is Fun! Part 4 by Adam Geitgey.
  4. Face Detection (PyImageSearch) by Adrian Rosebrock

--

--