Facial recognition program OpenCV

Facial recognition program OpenCV

Github-: https://github.com/Sahil-107/face-recog/blob/master/faceRegFinal.ipynb

In today's blog, I will create a program where it will going to recognize 2 faces of my friends, and then it will do some tasks when they detected the faces.

  1. When it detects Vibhanshu's Face it will:-

    • Send a message to me on WhatsApp.
    • Send an email to me.
  2. When it recognizes my face:-

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

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.

image.png

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.

SahilModel:-

image.png

VibhanshuModel:-

image.png

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:-

image.png

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.

image.png

image.png