We all have a smartphone nowadays, with face unlock features. But many of us are still using the basic old mechanical locks to protect our house, safe locks, etc. Wouldn't it be amazing to have the feature of a face recognition system installed in our house just like we see in movies? Here, in this project I am going to demonstrate a prototype of such face recognized security system with all information about the process as well as the coding part and the hardware equipment, you may need to build such a system.
First, let us see what hardware and software are required for this project.
Introduction:Now as we know what are the requirements for this project. So, let's see what is going to happen in this project.
The first device the user is going to interact with is our LDR - Light Detecting Resistor.
The face recognition won't be activated until there is a hindrance in the light intensity, otherwise, if we directly connect the face recognition system, it will start consuming memory and power.
Now if LDR observes any hindrance in the light intensity, it will send the information to Bolt Cloud which will be observed by the python code which we have written in our system. And python will start the webcam to scan for authorized personals or intruders. If there is an authorized person in the camera's viewing angle it will detect and close the circuit for port 1 where our relay is attached which will connect the motor to the power source. The motor here will act as a pulley to pull the metallic rod out from its hole. And it will also send a telegram message to the authorities about the access granted with the name of the authority and time. If there is an intruder in the camera's viewing angle, then the circuit consisting buzzer will be closed. The buzzer will start ringing to alert the authorized persons that an intruder is trying to break in. And a telegram message will be sent to the authorities that an intruder tried to break in with the time.
That's was all we are going to do here. Now, let's check out the step-wise procedure to build this project.
Procedure:- Connect one of the LDR terminals to the 3v3 port of Bolt IoT Module and the other to the 'A0' analog port. (This is because the A0 terminal of the Bolt IoT module is the only port available in Bolt IoT for taking analogous input values).
- Connect the positive terminal of the buzzer to the '0' digital port and another terminal to the GND port. (This is because the digital port '0' is used to input and output and in this case we are using it as an output port to supply power to the buzzer through port '0').
- Connect the LED Positive terminal to the '1' digital port and the negative port to the GND port. (This is because the digital port '1' is used to input and output and in this case we are using it as an output port to supply power to the LED through port '1'). Here, I don't have a relay so, just for the demonstration I am using LED.
- Use breadboard to connect these circuits as shown in the diagram. (Using breadboard is not compulsory, we are using it so that we can easily make changes in the circuit later if needed and for simplicity too).
- Now, connect the USB cable to the bolt module and another end to the power supply through your laptop or charger.
Here ends the hardware setup. For more information about LDR and Bolt IoT Module click the embedded link.
Note: All these connections are made in the Bolt IoT device, which can be bought from the following link.
Software Setup:First of all, we need to install python in our system otherwise the "*.py" won't open. You can download python from here. And then make sure your pip is upgraded by entering the following command in the command prompt:
pip -m ensurepip --upgrade
- First of all, we need to install python in our system otherwise the "*.py" won't open. You can download python from here. And then make sure your pip is upgraded by entering the following command in the command prompt:
pip -m ensurepip --upgrade
Now, you need to install a few libraries to run this project. Otherwise, you will get an Import error. Libraries needed for this project are:
- open CV library:
pip install opencv-python
- NumPy library:
pip install numpy
- face_recognition:
pip install face-recognition
- Now, you need to install a few libraries to run this project. Otherwise, you will get an Import error. Libraries needed for this project are open CV library:
pip install opencv-python
NumPy library:pip install numpy
face_recognition:pip install face-recognition
For more information click here: Python,face-recognition library, Open CV library, Numpy library, and Pickle library.
Procedure:- Create a python - conf.py: In this file enter the device API and device id.
- Second, create a python file - embedding.py: This file is used for creating encodings for authorized persons and create a pickle file for this data to be used for face recognition.
- Third, create a python file - recognition.py: This file is the main file consisting of the program to detect the faces for authorized function. And this is the main file that will contain IoT implementation to add functions through our Bolt IoT device.
- First of all, the Authorized person has to create his/her face encodings by just opening the embedding.py file. Then enter their name and any number and tap 's' 5 times to take 5 samples of their face. That's all the encodings will be saved as a pickle file in the same directory in which the file embedding.py is present.
- Now when the person wants to unlock the door. He/she has to place their hands over the LDR, which will send a signal to the Bolt Cloud through API that the value of the LDR has been changed.
- Now the python code will receive those signals and starts the webcam to start the face-recognition process.
- Then the face encodes will be created and compared with the encodings of the previously created pickle file.
- Now, if the person is an authorized person, then the signal will be passed to the IoT device that the person is an authorized person and to close the circuit for the port 1 where the LED is connected in our case but relay with stepper motor will be attached in real-time applications. Then a message will also be sent to the authorities about the authority who got access and at what time.
- And if the person is not an authorized person then the signal will be passed to the IoT device that the person is not authorized. And to alert the intruder, the circuit for port 0 will be closed that will pass current to the buzzer which will start ringing. And also a telegram message will be sent to the authorities about the intruder along with a timestamp.
This project is based on the original research published at Modern Face Recognition with Deep Learning. Here the original research states that the face image captured is passed through a deep learning algorithm Hog's Algorithm which follows these steps:
- First, the image captured is converted to a black and white image.
- Then every pixel is then analyzed according to the darkness of every corresponding pixel.
- An image gradient is created in which all pixels are converted to arrows, then the strongest arrows form an image gradient called Hog's Image.
- This hog's image of the face is compared with various training to detect the face in face recognition.
- Still, this algorithm won't be able to recognize if the face is tilted.
- So, now the face landmark estimation algorithm is used to tilt the image to center the lips, eyes, and nose. For this, we are going to use basic methods to tilt like rotation, and scale the parallel lines called an affine transformation.
- The basic idea behind this is that there are 68 specific points in our faces created over the lips, outside structure of the eye, top of the chin, etc.
- Then an image is created consisting of these 68 points.
- Then this image is analyzed to detect faces.
- But if an image is compared with several others images every time, it would be time-consuming.
- So, now what we do is we create measurements from training images once, and then those measurements are saved. And when the new image needs to be analyzed instead of comparing the image with other training images. We just compare measurements of the new image with previously saved measurements.
- Now for measurements, we use Deep Convolution Neural Network to generate 128 measurements of each face.
- But still how a computer can recognize these images. For this, we compare 3 images.
- The first one is the previously saved image of the known person.
- The second is the new image of the known person.
- The third is the image of an unknown person.
- And if the new image measurements are more similar to the measurements of the previously saved image of the known person. Then the computer will know that the new image is of the known person.
- In ML, these 128 measurements of the face image are called embedding.
- But to get the accuracy we need to find the best 128 measurements which we could use to get perfect face recognition.
- And for getting these perfect 128 measurements, we need to train these images for millions of people, millions of times which is very time-consuming.
- So, people at Open Face published their training research. Which is used in projects to achieve accuracy.
- This research is used as a reference to create a face recognition library which we use in this project.
- This project prototype can be implemented in our system to add the face-recognition system to it.
- This project can be further improved by adding the relay and stepper motor to simulate the unlocking of the door.
- In the future, we can add 3d image processing to prevent intruders to use photographs to unlock the door.
- In the future, we can add the features to add an image and send it to the authorities to catch the intruder faster.
So, that's how an LDR-activated IoT-based face recognition security system prototype can be built.
This was just a prototype that's why we used LED here. You can use relay and motor to add the unlocking feature to your project. Furthermore, you can add a telegram messaging feature to this project to alert the authorities about the intruder with a face image of the intruder attached.
Comments