A Face Recognition program for Security and Automation

In this task we would do the following:

πŸ“Œ When it recognizes your face then β€”
πŸ‘‰ 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.

πŸ“Œ When it recognizes the second face, it can be your friend's or family member's face.
πŸ‘‰ Create EC2 instance in the AWS using CLI.
πŸ‘‰ Create 5GB EBS volume and attach it to the instance.

In computer science, face recognition is basically the task of recognizing a person based on their facial image. It has become very popular in the last two decades, mainly because of the new methods developed and the high quality of the current videos/cameras.

Note that face recognition is different from face detection:

  • 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.

What is LBPH?

Local Binary Patterns Histogram algorithm was proposed in 2006. It is based on a local binary operator. It is widely used in facial recognition due to its computational simplicity and discriminative power.

The steps involved to achieve this are:

  • creating dataset
  • face acquisition
  • feature extraction
  • classification

The LBPH algorithm is a part of OpenCV.

Steps

  • Suppose we have an image having dimensions N x M.
  • We divide it into regions of the same height and width resulting in m x m dimension for every region.
  • The local binary operator is used for every region. The LBP operator is defined in a window of 3x3.

here β€˜(Xc, Yc)’ is a central pixel with intensity β€˜Ic’. And β€˜In’ is the intensity of the neighbor pixel

  • Using median pixel value as a threshold, it compares a pixel to its 8 closest pixels using this function.
  • If the value of neighbor is greater than or equal to the central value it is set as 1 otherwise it is set as 0.
  • Thus, we obtain a total of 8 binary values from the 8 neighbors.
  • After combining these values we get an 8-bit binary number which is translated to a decimal number for our convenience.
  • This decimal number is called the pixel LBP value and its range is 0–255.
  • Later it was noted that a fixed neighborhood fails to encode details varying in scale. The algorithm was improved to use a different number of radius and neighbors, now it was known as circular LBP.
  • The idea here is to align an arbitrary number of neighbors on a circle with a variable radius. This way the following neighborhoods are captured:
  • For a given point (Xc,Yc) the position of the neighbor (Xp, Yp), p belonging to P can be calculated by:

here R is the radius of the circle and P is the number of sample points.

Task

First, we would create a dataset to train a model to recognize my face.

So we would create a dataset by cropping the face, resizing it, and converting it in black and white.

You can get the code on GitHub from the link attached at the end of the blog.

First Part

When it recognizes your face then β€”
πŸ‘‰ 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.

Creating Dataset

Now we will create a model via the LBPH algorithm.

Model Creation

Now we would create two functions one to send email via SMTP server and send a WhatsApp message.

Now, that everything is set up we would write a code that will recognize our face and call function email_send and WhatsApp to create a security program to alert when face come in front of the camera.

Face Recognition

Now, we could see that a video is captured to recognize a person and when the face is recognized, a mail is sent and a WhatsApp to a number.

Result

Second Part

When it recognizes the second face, it can be your friend’s or family member’s face.
πŸ‘‰ Create EC2 instance in the AWS using CLI.
πŸ‘‰ Create 5GB EBS volume and attach it to the instance.

Now we create a Dataset using the same code as above. And then create the model.

In my case, the second person is Virat Kohli.

Creating a function to launch ec2, EBS volume, and to attach them

We are using the boto module to create an ec2 instance, create an EBS volume of 5GB, and attach them.

Face Recognition

Now we would collect the data through the same procedure as done in the first step and train the model to detect the face.

Now, we could see that a video is captured to recognize the user and when the face is recognized, aws function is run.

Result

We could see that the face is recognized and in the AWS ec2 instance, an EBS volume is launched and attached when the face is recognized.

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

https://github.com/shiv0112/faceRecog_automation

I automate things πŸ˜‰

I automate things πŸ˜‰