# Face Detection using Open CV(Google Colab)

--

Hey there,

In this blog, We are going to see how to detect the Google CEO eye, face, and smile using his picture.

Most people do not have higher-end laptops to run the program faster. So, I have used Google Colab which is completely free. You can write the program by using a chrome browser as well as you can get some virtual RAM to run the program.

Let's jump right in,

Face detection is a computer technology being used in a variety of applications that identifies human faces in digital images.

Let's see some code here,

Importing necessary libraries and images.

Plotting the image and its type

Converting a color image to Grayscale

# OpenCV TypeError: Expected cv:: UMat for argument ‘src’

You may wonder why this error occurs?

OpenCV images are stored as three-dimensional Numpy arrays.

When you read in digital images using the library, they are represented as Numpy arrays.

Solution:

we need to convert an image into a Numpy array.

# What is the need of converting an image into a NumPy array?

With Numpy you can make blazing fast operations on numerical arrays, no matter which dimension, shape, etc. they are.

Image processing libraries (OpenCV, PIL, Scikit-image) sometimes wrap images in some special format that already uses Numpy behind the scenes. If they are not already using Numpy in the background, the images can be converted to Numpy arrays explicitly. Then you can do speedy numerical calculations on them (convolution, FFT, blurry, filters, …).

Now, see the output

# why do we convert from RGB to Grayscale?

First of all, we should know the difference between both RGB and Grayscale Image.

An RGB image consists of 3 layers R, G, B as it is clearly see through its name. It’s a 3-dimensional matrix, for example, 3 consecutive pages in your book. where the grayscale image is of only 2 dimensions, and the values range between 0–255 (8-bit unsigned integers).

Therefore, some algorithms can only be applied on a 2-D image rather than 3-D, hence we convert an RGB image into a grayscale image, for instance, Black and White conversion of an image, convolution of an image, etc.

Here, I used the Haar-cascade classifier for the detection

Object Detection using Haar feature-based cascade classifiers is an effective object detection method proposed by Paul Viola and Michael Jones in their paper, “Rapid Object Detection using a Boosted Cascade of Simple Features” in 2001. It is a machine learning-based approach where a cascade function is trained from a lot of positive and negative images.

Detecting face

Detecting eye

False detection