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
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.
we need to convert 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.
Haar-cascade Detection in OpenCV
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.
*side angle picture (difficult to capture),
Here you can see, it is detecting some parts of the face falsely as an eye
Let’s combine all detection
Hope you like it, I will see you in the next blog until then bye from Sridhar…