Using Face Recognition for automation

Mayank_Agarwal
3 min readJun 25, 2021

SUMMER-TASK-6 (Team Task)

GitHub ->

https://github.com/Mayankagarwal007/face_recognition_python.git

In this article I will explain how we can use Face Recognition and then send the mail and whatsapp message. Further if other face detected then we create EC2 instance in AWS!

For Face detection we are using LBPH algorithm

What is LBPH algorithm?

The Local Binary Pattern Histogram(LBPH) algorithm is a simple solution on face recognition problem, which can recognize both front face and side face. The gray value of the pixel is replaced by the median value of its neighborhood sampling value, and then the feature value is extracted by the sub blocks and the statistical histogram is established.

As we have an image in grayscale, each histogram (from each grid) will contain only 256 positions (0~255) representing the occurrences of each pixel intensity.

Then, we need to concatenate each histogram to create a new and bigger histogram. Supposing we have 8x8 grids, we will have 8x8x256=16.384 positions in the final histogram. The final histogram represents the characteristics of the image original image.

Let’s create a LBPH model using Python

Collecting Dataset ->

Model training ->

The LBPH model is trained by using face_LBPHFaceRecognition.create() from cv2.

we need opencv-contrib-python so install by ->

pip install opencv-contrib-python

Main Face Recognition Code ->

face_detector is a function that is called later in a loop, for getting image coordinates.

Now once the face is a detected we can take further actions!

Here the a is a variable acting as a switch variable to trigger the automation when the trained face is a detected.

Code to do whatsapp message ->

in the first argument of sendwhatmsg use the phone number with country code!

Code to do Mail ->

Terraform code ->

--

--