Python Code for Facial Recognition and Security Automation.

In this task we would do the following:
📌 When it recognizes users face then do the following —
⚙It sends mail to your mail-id by writing this is the face of your name.
⚙Second, it sends a WhatsApp message to your friend, it can be anything.
⚙Create EC2 instance in the AWS using CLI.
⚙Create 5GB EBS volume and attach it to the instance.

What is facial Recognition System ?

A facial recognition system is a technology capable of matching a human face from a digital image or a video frame against a database of faces, typically employed to authenticate users through ID verification services, works by pinpointing and measuring facial features from a given image.

Face recognition systems use computer algorithms to pick out specific, distinctive details about a person’s face. These details, such as distance between the eyes or shape of the chin, are then converted into a mathematical representation and compared to data on other faces collected in a face recognition database.

Difference between Face Detection and Facial Recognition?

  • Face Detection: it has the objective of finding the faces (location and size) in an image and probably extract them to be used by the face recognition algorithm.
  • Face Recognition: with the facial images already extracted, cropped, resized, and usually converted to grayscale, the face recognition algorithm is responsible for finding characteristics that best describe the image.

Our Pre-requisite:

a)AWS CLI Configured
b)Python ≥ 3.6
c)Working Camera
d)Libraries Installed :
— opencv python
— opencv contrib python
— pywhatkit
— pillow …please check below for more.

Approach to be used?

We will be using Haarcascade Face Detection to Generate our Image data set and later on that data set we will be training the Model using 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.

To learn more please visit:

Now let’s get Started and jump directly to the code Part:-

✔ Step-1: Creating a Dataset using Haarcascade Face Detection

>> To use this you must have the directory created in your current folder
>> Either use ‘cmd’ for creating the directory : “mkdir ./faces/user”

✔ Step-2: Training the Model using the LBPH Algorithm.

>> Here we are using some file operations and retrieving the data from it.
>> Here we have created a Model name “vimal_model”

✔ Step-3: Defining the Function for sending mail and Whatsapp.

>> Here we will be using smtplib and sending mail with Attachment if users face get’s recognized.

✔ Step-4: Calling the Function for sending mail and Whatsapp.

>> Here we are calling the Above created Function and Sending the mail and whatsApp Message if user’s face get Recognized.

✔ Step-5: Defining the Function for Launching EC2 , EBS and Attaching Both.

Final — Result:

Thank you for your time you can get the source code here:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Student from 2nd Year, A proud ARTH learner, love new technologies, Curious about many thing, likes to explore places, love eating pizza and much more.