Facial recognition program using python and open CV.

3 min readJun 20, 2021

Basic overview of our program

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

  1. When it detects myFace it will -
  • Send message to me on WhatsApp.
  • Send an email to me.

2. When it recognize Sahil 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 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.

Hence the first step is done.

Step 2) 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 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.

Snapshots of code are given below.

Sahil model
Vibhanshu model

Step 3) Detect face and execute task.

Now to execute task we used python libraries like cv2, pyautogui time and os.

  • To send Whatsapp and email
Mail and Whatsapp
  • To launch an ec2 instance and attach volume.

Time to test the program….

After recognizing this face the program will send a WhatsApp message and an email.

After recognizing this face it will launch an ec2 instance with attached volume.

Hence instance is launched!

Hence the task is completed successfully!