Face-Recognition using python

Sending emails and WhatsApp messages …

If you have ever wandered around the apps like face-lock, then this is a short self practical that can do a similar kind of job for you. The task is to create a code that will recognize your face and then send an email to you or a WhatsApp text or launch an instance over AWS cloud.

To start with we must have a little knowledge of how things are executed and what are the pre-requisites for performing this practical. Starting with face recognition. In the 1960s, Woody Bledsoe, Helen Chan Wolf, and Charles Bisson began work using computers to recognize the human face. Ever since then this idea has bloomed the market and has a hold on uncounted use cases.

How did it come to play?

The idea that a machine can recognize a face originated from the fact that a machine can do wonders if set correctly. The biometric area in face recognition grew from rotating a face, detecting the distance between facial features to completely recognizing the face. Linear algebra, matrices played a vital role in every aspect of this technology.

In 1988, a system Eigenface attested that feature analysis on a collection of facial pictures could form a set of basic features. They were also able to show that fewer values could also, accurately code a normalized facial image.

The biggest change knocked this industry in the year 2010 when Apple launched their iPhone which had a feature of locking unlocking using face-id.

What is computer vision?

Computer-Vision thus became a domain that aims at training the machines to interpret not only data but also visuals. This could thus, help the computer to do many amazingly brilliant things.

The computer understands only numbers. It is necessary to acknowledge the fact that every piece of data be it an image or visual is also a combination of numbers behind the scene. The computer understands these numbers and henceforth, holds the ability to tell when and where a change in the number is encountered.

Therefore, I would quote that Computer vision, an AI technology that permits computers to interpret and label images. It is used in convenience stores, driverless car testing, daily medical diagnostics, and monitoring the health of crops and livestock.

The Computer and Mind

For predicting, or coming to a conclusion you must know what is the right answer. For example, if you have an exam and in order to score well, you must learn. Also, you should know what exactly is to be learned. The teacher would assign you a grade of A if your answer matches completely, what has been taught. It works similarly to the human mind.

Similarly to recognize a face you require :

  1. Dataset: A dataset will contain thousands of images of a face or object that you want a computer to recognize for you.
  2. Data model: Once the data has been created you need to make the computer learn and understand it. The computer will interpret the data before predicting it. This requires a model which helps in this process.
  3. Data training: The next step is to train the machine with the dataset and ask it for output when a similar photograph is encountered.

How does computer vision work?

Computer vision algorithms are based on pattern identification. The systems are trained on a massive amount of visual data. The computers process images, label objects on them and find patterns in those objects. For example, if we send a million images of dogs, the computer will analyze them, identify patterns that are similar and important to call a thing a dog.

Similarly, we train our face by sending a lot of data to the computer so that it could create a pattern and identify us. For identification, the foremost thing to identify edges. The edges of features are distinguished when a change in the number using certain formulas and methods is obtained. We also use a pre-created model, which when loaded helps to identity edges.

So, let's begin with the task.

Step 1: Collect the dataset

For creating a good dataset we collect pictures of the same size and pixels of us. To reduce your manual work, we use the OpenCV-python library. The cv2 module in this helps us to take around 100 pictures at a time through the internal(0) or external(1) webcam. The enter key stops the webcam after data has been collected. The collected images are stored in the directories.

Step 2: The next step is to train the data collected.

Load the collected dataset and create training data and labels. The images are appended in the array and it is trained.

Step3: Running the facial recognization Model

In this step, we have used the pre-created model which will help to recognize the face based on its algorithms. Here we load the Har Cascade model, making sure you download it into the same directory. After the model has been loaded we will check it for our face and based upon how well the prediction has been made we will execute the steps.

Confidence is the result or accuracy of prediction. It tells how confidently the machine is able to recognize a user. Nevertheless, it is also necessary to acknowledge that a machine can never give 100% confidence. A confidence of 80 and above is believed to be good enough.

Hence, we set the confidence value at 80. That is while testing the model if it predicts the image with 80+ confidence we will send an email, WhatsApp text, or launch an instance.

Sending Mail

The following code sends an email attached to it is the file it took a capture of. Since mail works SMTP( Simple Mail Transfer Protocol). Export the required libraries as follows. Then connect to the Gmail SMTP server to send mail.

Sending WhatsApp message

There are many ways by which python can send messages through WhatsApp. Here, we use the method of API.

Similarly, Many datasets can be trained and a lot of things can be done. For the joint code visit the Github link provided below.