Implementing Computer Vision – Face Detection

Andre Last Updated : 09 Dec, 2021
5 min read

This article was published as a part of the Data Science Blogathon

Overview

Computational Vision is the part of Artificial Intelligence, which aims to design intelligent algorithms that have the ability to see as if it were a human vision.

In this article, we’ll cover three of the main scopes.

  • Face Detection
  • Object Detection
  • Facial Recognition
  • Object Tracking

In this first article, we will focus on the introduction of computer vision, and the face identification application based on the Python OpenCV library. In future articles, we will demonstrate the applications of object identification, face recognition, and object tracking in real-time video.

Face Detection cv
https://github.com/DataScience-2021/Analytics-Vidhya/blob/main/_Computer_Vision/Computer_Vision/Slide3.PNG

Table of Contents

  1. 1. Introduction
  2. 2. Face Detection Algorithm
  3. 3. Face Detection Implementation
  4. 4  Alternative to OpenCV
  5. 5  Conclusions
  6. 6 References

Introduction

The reader of this article will be able to understand the functioning of several visual computing applications, their operation in the background and architecture, and what are the necessary steps to implement an application for real use.

Face Detection application
https://github.com/DataScience-2021/Analytics-Vidhya/blob/main/_Computer_Vision/Computer_Vision/Slide4.PNG

Let’s now look at some of the other applications that can be developed in this area that we’ve already discussed earlier.

Face detection will put a little square when it finds faces and face recognition will put a name for those people. We’re going to do an implementation somewhat similar to this one. We have this image of Kinect from Microsoft which is integrated with the Xbox video game which is motion detection.

You can use computer vision to detect the person controlling the car while moving the steering wheel. Computer vision techniques for image recognition are needed, that is, the robot needs to see what is in front of it to make a decision.

Another example is autonomous cars. You can notice that there is a series of sensors in this car, for example, it needs to detect pedestrians to avoid hitting a person.

You need to detect traffic signs or if you have a traffic light.

If the signal is red it has to stop if the signal is green it has to continue. For this, computer vision techniques are used, including those used. This face detection technology is also used for object detection.

If he identifies the object on the track he has to take a certain action. The idea of ​​augmented reality virtual reality uses computer vision techniques. We have this image of the SD beams are people who do not exist. The algorithm generated these people and a technique called Gan is used, which is the adversary network to the active general, which is a super area within the deep learning artificial neural networks.

Finally, we have this other example which is called deep Durin which is an image generated by a neural network. These are hallucinogenic images you can see that it has some characteristics some animal traces in parts of this image ie algorithms already have information about the animals about these images of animals are very similar to that idea of ​​evolutionary neural networks and there is an algorithm that will combine the characteristics of an image with that image of the landscape, for example.

An example of application is the deep faces, which are faces of people created by artificial intelligence.

deep faces Face Detection
https://github.com/DataScience-2021/Analytics-Vidhya/blob/main/_Computer_Vision/Computer_Vision/Slide5.PNG

 

Face Detection Algorithm

The Cascade Classifier is an algorithm you will learn to classify a certain object to start training. We need two sets of images the first set with faces with the positive images you want to detect and the second set of images are called the images negative that are images of anything but ease.

Face Detection algo
https://github.com/DataScience-2021/Analytics-Vidhya/blob/main/_Computer_Vision/Computer_Vision/Slide6.PNG

If you for example want to detect cars you will have as positive images the cars various models and types of vehicles as negative images.

Any other type of image and you need to have these two sets of images for you to submit to the algorithm to train.

There is training with this algorithm called Ada boost in the machine learning area. I won’t go into details of how this algorithm works, but basically, you apply this algorithm to both positive and negative images and the idea is to make the selection of features.

We have several features or these little squares with these black and white colors and the idea for you to classify a face and apply those features.

These little squares are for each subwindow of an image.

This window concept indicates that it moves from left to right and top to bottom.

Face Detection Implementation

We will use the Python OpenCV Library, which is one of the main tools on the market for developing Visual Computing applications.

Face Detection Implementation
https://opencv.org/

 

Download training screenshot, and Cascade Classifier.XLM training with face identification training.

Let’s now show our code in Python:

 

import cv2 # OpenCV Import
img = cv2.imread('/content/imagem-computer-vision.jpg', cv2.IMREAD_UNCHANGED) # Import Image with Peoples
cv2_imshow(img)

 


detector_face = cv2.CascadeClassifier('/content/haarcascade_frontalface_default.xml')
imagem_cinza = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

cv2_imshow(imagem_cinza)

 


deteccoes = detector_face.detectMultiScale(imagem_cinza, scaleFactor=1.3, minSize=(30,30))
deteccoes
array([[1635,  156,  147,  147],
       [ 284,  262,  114,  114],
       [1149,  260,  129,  129],
       [ 928,  491,  171,  171],
       [ 222,  507,  151,  151]], dtype=int32)
for (x, y, l, a) in deteccoes:

  #print(x, y, l, a)

  cv2.rectangle(img, (x, y), (x + l, y + a), (0,255,0), 2)

cv2_imshow(img)


We visualized the processing for the identification of faces through the Google Colab notebook:

Arrests he will return the number 5 indicates that he detected seven faces and we have these points that indicate each of the faces for you to understand better and let’s use this last face.
len(deteccoes) # Fotal Faces= 5
5

Alternative to OpenCV

 

In selecting the alternatives to OpenCV, we adopted the following criteria:

  • Ease of adoption of the technology
  • Usability
  • Scalability,
  • Robustness
  • Flexibility

 

Below is a list of my alternatives, following the criteria above:

1) Microsoft Computer Vision API

2) AWS Rekognition

3) Google Cloud Vision API

4) Scikit-Image

5) SimpleCV

6) Azure Face API

7) DeepDream

8) IBM Watson Visual Recognition

9) Clarifi

10) DeepPy

Conclusions

In this article, we use the Python OpenCV library, as a tool that speeds up the identification of Face, in an agile and efficient way.

With the help of this article, the Data Scientist will be able to implement other Visual Computing applications, such as identification of the use of masks, body temperature, social distance in supermarkets, object identification, facial recognition, real-time object tracking.

Reference

  • https://opencv.org/
  • https://newbedev.com/how-to-download-haarcascade-frontalface-default-xml-code-example
  • https://www.pyimagesearch.com/start-here/
  • https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/
  • https://rekognition-immersionday.workshop.aws/en/
  • https://www.ibm.com/br-pt/cloud/watson-visual-recognition

Author Reference:

  1. Github
  2. Twitter
  3. Medium

The media shown in this article is not owned by Analytics Vidhya and are used at the Author’s discretion.

Responses From Readers

Clear

Srinu
Srinu

Bro I need free project for my final sem,so any are there.

Congratulations, You Did It!
Well Done on Completing Your Learning Journey. Stay curious and keep exploring!

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details