In the present generation, technology can fulfill almost all human needs. and is evolving rapidly. Automation was considered a science fiction in past times but not today. With the combination of technology and our homes, industries, schools and work places, we can build awesome future ahead.
We know how it feels after coming back home from a long tiring day from work. All we want and hope for is everything to be done on its own. We want to control the lights, fan or AC at just the tip of our fingers; click a button and food is right in front of us, hot and delicious, and turn the music on letting us enjoy the night by our voice. But alas, even if most of us work with technology, we forget to implement it with the day to day things which could make our lives much easier.
Considering automations in security, my project is a facial detection system which opens lock on detecting an owner and sends alerts when an intruder is detected. Face recognition is nowadays implemented by the cell phone industries. Face recognition is used as a biometric security standard because of its ability and quickness to recognize faces. Because of its increasing demand, companies are investing in this market to make products reliable and scalable and with increased security.
My project focuses on reducing the complexities of daily life to provide us a better ease of access to things using IOT and Application Programming Interface (APIs). As a requirement the projects will also be using various sms/email private API providing platforms according to our needs.
Software SectionStep 1. Virtual box softwareFirst, we will have to install Virtual Box software on our computer. You can download it from here: https://www.virtualbox.org/wiki/Downloads
Then you will have to install the Ubuntu server image file. You can download it from here: http://releases.ubuntu.com/16.04/ubuntu-16.04.6-server-i386.iso
Once you open your Virtual box, you will have to set your RAM to a minimum of 4 GB and hard disk memory to a minimum of 20 GB. After doing this install the ubuntu image file and then remember to increase your monitor counter or the processor count to a minimum of 4.
(optional) After this, you have to upgrade your Ubuntu server to 18.04 as it provides lots of new features and is better for this project. Type following lines on the terminal:
sudo apt-get update && sudo apt-get upgrade
sudo do-release-upgradeAs we will be using OpenCV in our project, it will use lots of GUIs which cannot be provided by the ubuntu server and hence you will have to install Ubuntu desktop on your server. Yes, I am doing this way because with one command tasksel you can use any other lighter Desktop on your server as per your requirement.
Let’s get into our business. Type the following commands on your ubuntu server
sudo apt update && sudo apt upgrade
sudo add-apt-repository universe
sudo add-apt-repository multiverse
sudo apt install tasksel
sudo taskselThen, you will see a menu pane, where you have to select Ubuntu desktop and now all the packages will install and may take some time depending on your network. After this, you have to reboot your system.
sudo rebootFinally, you will see your Ubuntu Desktop. Enter your login credentials and you are done.
- Bolt IoT
Bolt IoT is used as an alert system in this project. It also has its own cloud platform.
You have to register to use its cloud platform. Go to this.. www.cloud.boltiot.com
Bolt registration
Once done with the registration you will receive a verification email and do the verification process then you are good to go.
BOLT API key
Now, click on API in the menu and you will find your API key copy it somewhere and keep it safe and save the unique Bolt id that you will see on the main window adjacent to online /offline label and will start with BOLTxxxxxxx.
Now in the ubuntu terminal on your desktop that you created, you will have to type following commands to install Bolt packages to use the bolt device from a remote server. Which works on MQTT for communication with the server. You will have to install the pip package manager to install all python tools.
** Remember Python 3 is already installed and comes with Ubuntu 18.04
sudo apt-get -y update
sudo apt install python3-pip
sudo pip3 install boltiot- OpenCV
Install OpenCV which will be used for face recognition. There are various ways of installing OpenCV and the one using cmake is quite tedious, which might lead to errors if not done correctly. It might be difficult for ones just starting out with all of these. The version of OpenCV has to be 3.6. So, I will be doing it in an easy way. Type following commands on the terminal:
sudo apt-get install python3-opencv
pip3 install opencv-python** you can check whether OpenCV is installed or not by typing python3 on terminal and then type the following commands in the interpreter.
check cv2, dlib and face_recognition
** while working on programs if additional libraries are asked you can easily install it by using pip3 command such as for dlib, and face_recognition library which will be used in the project
example:
pip3 install dlibStep 2. IP WebcamI am using an IP webcam app that is available on Google play store. It is a streaming server that works on your local network. You will get the network address when you will click on the ‘Start server’.
click on start server
Twilio is a third-party SMS functionality provider. It is a cloud communications platform as a service (PaaS) company. Twilio allows software developers to programmatically make and receive phone calls and also send and receive text messages using its web service APIs.
Creating an account on Twilio
a. Open https://www.twilio.com/ in browser.
b. Click on Get a Free API Key button to sign up.
c. Fill all the necessary details in SIGN UP form. Below is the screenshot of filled sign up form.
d. To verify they will ask for our phone number. Choose India as an option in the dropdown and then enter our phone number
e. After verification we will redirect to our dashboard and we will need to Create New Project.
f. Click on "Products" as shown on the screen below, and enable the SMS services by clicking on two checkboxes for Programmable SMS and Phone Numbers as shown below. Once you have done this, scroll to the bottom of the screen and click on "Continue".
g. Now, we will need to give a name for our project. I have given the name as My Project. Click on "Continue" once we have entered the project name.
h. Click on "Skip this step" when it asks to Invite a Teammate
i. Our project should be created at this point. Click on "Project Info" to view the account credentials which is required for our projects
j. We can view the Account SID and Auth token on this page. The Auth token is not visible by default, we can click on "view" button to make the Auth token visible as shown below. Copy both and save them somewhere securely.
k. From the drop-down menu, choose "Programmable SMS". Now click on Get Started button to generate phone number
l. Click on Get a number button. Then a popup will appear which will have the final number
m. Click on Choose this number button to finalise this number.
n. By this method we can generate several numbers and we can see these numbers in Active Numbers area
o. To check whether this is working or not, we have to go to Build with Programmable SMS and send a message to our given phone number. if everything is ok then it ill work, but if message has not received, then we have to again set up from beginning.
a. We have to save the given number in our mobile phone and need to send a code that is showing with the number in following image join ground-party
b. After sending the code we will get a reply from Twilio "You are all set" on our whatsapp.
c. Now we will go to next step which is "send a one-way message".
d. For rechecking and reverification we will send whatsapp message to our mobile number from twilio.
e. If we successfully receive the sent message on our whatsapp then we have successfully configured the whatsapp set up.
Mailgun is an Email automation service. It has a very powerful set of inbuilt functions for sending emails. Developers can process their email with the help of Mailgun API
Creating an account on Mailgun
a. Open https://www.mailgun.com/ in browser.
b. Click on Sign Up button.
c. Fill all the necessary details in SIGN UP form. Below is the screenshot of filled sign up form.
d. We will get a verification mail having a link. Click on that link to verify our mail.
e. To verify they will ask for phone number. Choose India as an option in the dropdown and then enter our phone number.
f. After verification, we will go to domain and click on sandbox url
g. Now we need to verify our mail address to receive mail from mailgun. for this we need to enter our mail address in authorised recipient section. we will receive the mail then we have to verify our email address.
Mailgun Mail Address Verify
h. We need to click on API section for API key and API url.
As explained in the software set up part, we will be needing the Virtual Box Setup and IP Webcam for this project. Regarding the hardware, we would be needing the led and a buzzer. We can use a solenoid lock to unlock a door when the owner is detected (represented by led) and a buzzer as an alert module in our home system so that if an intruder tries to unlock the alarm will buzz.
· The hardware schematic for the project is as follows –1. GPIO pin 1 of Bolt module is connected to the positive pin of LED (Solenoid lock representation)
2. GPIO Pin 2 is connected to the positive pin of the piezo buzzer
3. The negative pins of both the LED and Buzzer is connected to the GND of Bolt IOT module
Now, comes the main part where we will have to keep a good focus to understand facial recognition as well as the liveness detection that the project is set up on.
So, let's divide this project into three parts: face recognition, eye-blink- heuristic, IOT alert
Step1: Face recognition
We may start with face detection first and the job is done by OpenCV.
The haar cascade library is used for this purpose. We will have to download the haar cascade frontal face library which is a classifier in xml format. Usually, the classifier comes bundled with Opencv 3.6. We can also program for eyes, mouth, etc. We can code similarly and use different classifiers as per need.
There are various ways of performing face recognition. The most common way of doing it is through the use of bundled OpenCV recognizers which can train our dataset and stores it in a.yml file. However these recognizers are dependent on the dataset of the person’s face that we would be using for our project. More the dataset input, more will be the accuracy and precision of the facial detection.
However a lot of progress has been observed in facial recognition as more work and study is going in deep learning as OpenCV was not introduced solely for this purpose. So, deep learning (Deep Neural Network or Conventional Neural Network) is the key to face recognition which will consider and approximate various intricacies of the face.
For the project the face_recognition library will be used which is based on dlib’ s state of the art face recognition. Dlib is a C++ toolkit consisting of algorithms on machine learning and tools for complex software creation in C++ to solve problems pertaining to real world. The model provides an accuracy of 99.38 %.
The project requires only one image dataset per user and the recognition is quite efficient and accurate. The face_recognition works on RGB image, and in our case, it will recognize a face and identify who it is.
The face_recognition library encodes the image dataset and then face matching is attempted with the face in each frame of the live video stream (through our IP Webcam App in our case). The face is then encoded into a 128-d embedding vector. The face detection is done is through Histogram of Gradient model by default rather than the Convolutional Neural Network model because it takes a lot of time to process on CPU and if there is a large dataset then it is tedious despite its accuracy. Hence the default hog model is better for our purpose.
However, only till this process of facial detection, if we use our photo or printed picture or selfie then it will detect and recognize the face. So this library will be able to recognize the face efficiently and quickly but it will not be able to differenciate between a live person and a fake person. Since we are dealing with a project of a face as a security feature it is important to rectify this issue. Hence we will use the following step to detect liveness of the face.
Step 2: Anti-spoofing algorithm: Eye-blink based heuristic approach
There are various efficient ways of dealing with a fake face and an original live face. These are helpful in prevention of thwart attacks. The thwart attacks can be in different ways such as print attacks, replay, 3D mask attack etc and following approaches are some of them used to solve this problem:
1. Optical flow algorithm based in which Keras 3D convolution can be used or any procedure that finds a difference between 3D and 2D faces.
2. The binary classification which can be used to detect live faces using SVM to classify real or fake faces and works mostly with selfies.
3. Heuristic-based eye blink or lip movement to observe the differences between a live and a fake face.
The heuristic-based eye blink detection will be used for the project with the feature of a facial landmark technique. We can detect the eye blinks for the liveness check of the face using a facial landmark shape predictor. Facial landmarks are used to detect blinks of an eye. Facial landmarks can efficiently represent and localize visible regions of the face, such as Eyes, Eyebrows, Nose, Mouth and Jawline. Facial landmarks technique can be efficiently applied to face alignment, head pose estimation, face swapping, blink detection and much more.
Facial landmarks detection will localize the face in the 2D image and then will try to detect the key facial structure and plot the region of interest of the face in other similar images if they exist. The facial landmark library plots 68 points on the input image and through the plotting, we can see that the eye plots are from points 37 to 46.
The EAR (Eye-Aspect-Ratio) produces a constant value when the eye is open and decreases rapidly when the eye gets closed (demonstrated in figure A). So this helps us immensely for accurate determination of the person’s eye blinks basing on the vertical and horizontal eye landmark points. The shape predictor will be implemented for the ROI (Region of Interest) in face.
The first constants which will be used in our program is the EAR threshold which will be 0.3 and the other will be the consecutive frame reference for the eye to be below the threshold (or the number of blinks) to trigger the detection process which will be 3. The deep learning face detector which will be used, as mentioned earlier, is the default ‘hog’ model. So, the eye blinks will be detected in the consecutive frame of a live stream. We can observe the number of eye blinks and the threshold on the top of the frame in Figure B.
In the program, we will be counting the number of eye blinks and this blinks will be a determining factor between a real image and a fake image. Whenever a face is detected it will detect the blinks of a person and then will try to recognize the face using face_recognition library. If known face is detected then it will authorize and display the results and if unknown face comes up the same process will be applied and if the eye blinks are detected then it will proceed to check the person is known and unknown. In this way, we deal with the liveness of a face.
Next, we will be moving to the final step of adding an IoT door unlocking and intruder alert system when an intruder is detected.
Step3: IoT Face unlocking and Intruder alert
We will have to create a python file on the ubuntu server which will have all the Bolt credentials like Bolt ID and API key and save it as configuration file- conf.py This will help to connect to the bolt device and the online cloud platforms.
For the project my Huawei tablet has been used that will stream live video through IP Webcam App on the host address on the port 8080.
In the virtual machine, we will program and save the ‘OWNER’ image. The API request program is done in python in the virtual machine and all the credentials will be used from the configuration files.
Again, as mentioned above in the setup, my face has been set as the ‘OWNER’ image and any other person would be considered as an intruder. When the stream starts and if anyone tries to use a fake photo or a selfie to unlock, then the blink detector will try to detect blinks. Due to frame drops there might be some glitches in detecting blink sometimes, as it depends on quality of stream.
The program has been made in such a way that the when OWNER is detected by the program after the anti spoof process, then the GPIO pin 1 of Bolt module will be set to HIGH and lock will be unlocked (shown in the project as turning ON an LED) and if an intruder is detected, alert messages will be sent to our whatsapp, email and through SMS. Simultaneously, the buzzer will start to buzz through GPIO pin 2. If the intruder continues to be detected through the program, the server will continue notifying us through mails, messages and buzzers.
The flowchart of activities in this particular project section is as follows :-
Below images show that when OWNER is detected, the program gives an ‘Authorized!!’ message on the video frame (Fig 1) and consecutively, the GPIO pin 1 of Bolt Module is set to HIGH which unlocks the lock. And when any other person tried getting in front of the camera (My father in this case), the program displays an Intruder message after performing the facial recognition and subsequently starts sending the Alert messages and also sets the GPIO pin 2 to HIGH which turns the buzzer ON (Fig 2). Subsequently, the alert messages are also sent as shown in figure 3 and figure 4. The alert protocols can be modified according to our requirements.
Make the same circuit connections as described before.
Twilio generates an Authorization Security Identifiers (SIDs) and a Secret Authorization token for our account which can be used to send messages. It also generates a sandbox domain number which can be used to send messages to our predefined whatsapp number. Now, in our Virtual box, we can create a python file named conf.py which will store all the credentials related to Twilio. To create a new file we need to type sudo nano conf.py in the terminal. After that we write below code format to save all the credentials in a single file
Similarly Mailgun generates a domain which serves as a type pf API platform for sending oir test emails to a particular email or many emails all at once. Similarly, in our VPS, we can create a python file named econf.pywhich will store all the credentials related to Mailgun. To create a new file we need to type sudo nano econf.py in the terminal. After that we write below code format to save all the credentials in a single file for use in our projects
Note: We have to replace all the above value with our credentials. We can find the first four values in Twiliodashboard and the last two in Bolt Cloud dashboard.
Then run the attached code and see it work!



















Comments