Facial recognition program using python and OpenCV.

Facial recognition program using python and OpenCV.

Basic overview

Our program is going to recognize 2 faces( Mine and the other one’s is of my teammate Vibhanshu) and then it is going to perform certain tasks on the basis of the face is detected.

When it detects Vibhanshu's Face it will:-

  • Send a message to me on WhatsApp.
  • Send an email to me.

When it recognizes my face:-

  • Create an ec2 instance with AWS CLI.
  • Create 5GB EBS volume and attach it.

Let’s Start Now:-

Step 1: Collect face samples on which our model will be trained.

Here we have used the Haarcascade model for face detection and made a function that will take collect images using cv2 and basic if-else statements. Here is the snapshot of the code.


Step 2: Now we train our datasets.

Here we trained two models namely sahilModel and vibhanshuModel with the help of certain python libraries like cv2, NumPy, listdir, and isfile.

Now as the samples are collected here we used the Local Binary Pattern Histogram algorithm to train our models as it can recognize faces under varying lighting conditions and low resolution which is required in our case.





Step 3: Functions which will send Mail, Whatsapp message and Launch EC2 instance.

We've used python libraries like cv2, pyautogui, time and os to automate this task.

Code to send Whatspp message and Mail:-


Code to Launch EC2 instance:-

image.png With this to attach the EBS we've written an extra file mappings.json

           "DeviceName": "/dev/sdh",
           "Ebs": {
               "VolumeSize": 1

Time to test the program….!!!

First I will show my face. image.png After recognizing my face it will launch an EC2 instance with attached 1GB EBS volume.

Then When I show Vibhanshu's face. image.png After recognizing Vibhanshu’s face the program will send a Whatsapp message and an Email to Vibhanshu.



So our task is successfully completed!!

Thank you!!