Face Detection using Haar Features

What are Haar Features used in Face Detection ?

Darshan Adakane
Analytics Vidhya
4 min readNov 12, 2019

--

Face recognition means identifying the person and face verification means verify the person who is claimed to be (by matching it in certain database). Its applications are found in various fields like school, colleges, organisations, factories, public places, surveillance etc. These techniques are gaining momentum worldwide and extended with human emotion recognition, its applications are huge.

The key aspect in face recognition is detecting relevant features in human face like eyes, eyebrows, nose, lips. So how do we detect these features in real time/in an image ? The answer is Haar Wavelets or Haar Features. And the algorithm used is called as Viola-Jones Algorithm. In this article we will try to understand what is Haar features and how they are used in face detection.

Haar features are sequence of rescaled square shape functions proposed by Alfred Haar in 1909. They are similar to convolution kernels taught in the Convolution Neural Networks course. We will apply these haar features to all relevant parts of face so as to detect human face.

Example of Haar Features: Square shaped kernels. Source

As we see in the above image, there are edge features (1 and 2), line features (3). They are white and black pixels images (value 0 or value 1). But usually we have greyscale/colour image (pixel value range from 0 to 255). For now assume ideal scenario that we have black and white image.

Taget Image. Source

To detect eyebrow, we will use Haar feature (image (1)) because forehead and eyebrow form lighter pixels- darker pixel like image. Similarly, to detect lips we use similar to Haar like feature (image(3)) with lighter-darker-lighter pixels. To detect nose, we might use darker-lighter Harr like feature from (image(1)). And so on.

Haar features applied on relevant parts of face

Lets look at some computations that are required.

For black and white image (refer first box below), pixel values are 0 or 1 (ideal case) but in real cases we have normalised greyscale image as shown in bottom box containing pixel values.

Pixel values: 0 and 1 for ideal case (Top box), Normalised greyscale values for real cases (Bottom box)

According to Viola-Jonas algorithm, to detect Haar like feature present in an image, below formula should give result closer to 1. The closer the value is to 1, the greater the change of detecting Haar feature in image.

Ideal case : Delta = (1/8)*(8) — (1/8)*0 = 1

Real case: Delta = (1/8)*(5.9) — (1/8)*(1.3)=0.575

(For greyscale image, assume we have set White-Dark threshold to 0.3. Meaning pixels with value less than or equal to 0.3 are considered white and anything greater that 0.3 is considered as dark)

We can define another threshold parameter to detect edge or Haar feature.We are calling it Delta (this is different from White-Dark threshold). Assume here we have set threshold to 0.5. Any delta value greater than 0.5 detects Haar feature. In this fashion we can apply, get and detect most relevant features on a given image like eyebrow,lips,nose etc.

Next we will quickly see what are Haar Cascade Classifiers

They are series of classifiers or features (as we have seen above) used to identify object in an image. Using sliding windows and number of haar features (increases as number of stages increase), finally leading to detect face or not. There are total 38 stages defined for Viola Jonas Method. Depending upon the sliding windows size and face location, number of features, face can be detected at a certain stage.

Haar Cascade Classifiers method

Hopefully you got some intuition on understanding Haar Feature used in face detection. I have tried my best to simplify in terms. If you have any questions, please post in comments. I would be happy to answer.

Thank you for reading the article.

--

--