Implementing Computer Vision – Face Detection
This article was published as a part of the Data Science Blogathon
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.
Table of Contents
- 1. Introduction
- 2. Face Detection Algorithm
- 3. Face Detection Implementation
- 4 Alternative to OpenCV
- 5 Conclusions
- 6 References
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.
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.
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.
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.
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
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))
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:
len(deteccoes) # Fotal Faces= 5
Alternative to OpenCV
In selecting the alternatives to OpenCV, we adopted the following criteria:
- Ease of adoption of the technology
Below is a list of my alternatives, following the criteria above:
1) Microsoft Computer Vision API
2) AWS Rekognition
3) Google Cloud Vision API
6) Azure Face API
8) IBM Watson Visual Recognition
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.
The media shown in this article is not owned by Analytics Vidhya and are used at the Author’s discretion.
Leave a Reply Your email address will not be published. Required fields are marked *