Program for Recognizer to perform some Task

In this blog, I am going to explain how we can create a program to perform some tasks by recognizing someone’s face. For this purpose, we will train models which will recognize two person’s face and then it will send email and WhatsApp message when it recognizes first person’s face and will create EC2 instance and EBS Volume when it will recognize second persons face.

For face recognition, we will use LBPH Algorithm. We will train two different models with two different person’s faces. So let us first understand about LBPH algorithm.

Local Binary Patterns Histograms (LBPH)

Local Binary Pattern (LBP) is a simple yet very efficient texture operator which labels the pixels of an image by thresholding the neighborhood of each pixel and considers the result as a binary number.

It was first described in 1994 (LBP) and has since been found to be a powerful feature for texture classification. It has further been determined that when LBP is combined with histograms of oriented gradients (HOG) descriptors, it improves the detection performance considerably on some datasets.

Now let’s create code to collect the dataset, train the model and finally recognize the face to perform some task.

Step 1: Collect datasets of two-person and saves them in a folder.

In this step, we will create code which will collect 100 cropped image of one person and then it will save them in one folder.

Similarly, we can write code to collect the cropped image of the second person and saves them in a file.

Step 2: Train the model with the image.

In this step, we will train the model with the collected dataset which is stored in a folder. We will pass those images to the model to get trained. Here the complete folder is acting as a dataset so we need to treat the folder as a dataset.

This model is for person 1 whose face will be used to send Email and WhatsApp messages. Similarly, we can train another model for the second person face which will we use to create EC2 instance and EBS Volume.

Step 3: Create a function to send Mail and WhatsApp message.

Here we will use smtplib module to send the email and pywhatkit module to send the WhatsApp message.

Step 4: Recognize face to send mail and WhatsApp message.

In this step, we will write code which will recognize the face of person 1 to send mail and WhatsApp message. If the accuracy will be more than 90 percent then only it will perform those tasks.

Let’s see the output of the mail that was sent.

Step 5: Write a function to create EC2 instance and EBS Volume.

For this purpose, I am using terraform to create EC2 instance and EBS Volume and then attach them. Here is the terraform code which will create EC2 instance, will create EBS Volume, and then attach volume with the instance.

Now I will create one function in python which will run terraform code using the OS module.

This function will run terraform commands to apply the code.

Step 6: Recognize face to launch EC2 instance and EBS Volume.

Similar to the previous task we will write code that will recognize send persons face and then it will create EC2 instance and EBS Volume.

Let’s check if has created an EC2 instance and EBS Volume or not.

I had trained this model with my friend's image and while recognizing I had used his image and we can see that it had performed the task which we wanted.

You can refer to the complete code on my GitHub.

GitHub Link:

Thank You for reading!! 😇😇

I'm passionate learner diving into the concepts of computing 💻