In December 2019, Baidu, JD and Alipay launched the offline “Face Scan Payment”, which made the public guess that this technology was commercially available. For us, face-scanning is changing our ways of life.
Face scan payment means that all kinds of payments can be finished even the phone is left home. It is extremely a welfare for the forgetful guys because there is no need to worry about leaving face home. What’s more, this technology can be also used for security monitoring, such as the smart access control system in the smart access control system.
So, now in this lesson, let’s use the face recognition of HUSKYLENS to make a smart access control system.
In this project, we are going to learn the face recognition of HUSKYLENS, using the build-in learning function to distinguish the faces learned before. When the smart access control system recognizes the faces already learned, the servo will rotate a certain angle to open the door and play joyful music to take away the weariness of the master. When unknown faces are recognized, the buzzer will make a warning sound to scare away strangers. There should be, of course, a visitor mode, so a button is set as a doorbell. Then, we can realize the make of smart access system.
Like other biological characteristics of the human body (fingerprint, iris, etc.), the face is inherent, unique, and not easily copied. It is the first kind image that has been studied, and also the widely used one in the field of computer vision. This project is making use of the face recognition of HUSKYLENS.
Face recognition is a biological recognition technology for identity recognition based on information about facial features. It uses a camera to collect images and videos containing human faces and automatically detects and tracks the faces, then performs a series of analytical techniques of the detected faces.
Operating Principles: there are four key steps of face recognition:
Face Detection: detect the face positions and select them by frames.
Face Alignment: recognize faces from different angles by locating the features.
Face Encoding: extract face information and make it understandable for a computer.
Face Match: match the face information with the existing database to get a similarity score and give out the matching result. Face recognition is regarded as one of the most difficult courses in the field of biological recognition even artificial intelligence due to the features of the face as biological characteristics.
Similarity: there is not much difference between individuals. All the faces, even the facial organs are similar in structure and shape. Such a feature is beneficial to the use of human face for locating, but unfavorable for distinguishing individuals.
Mutability: facial appearance is not very stable. Through changing the expression of the face, or observed in different angles, the visual images vary widely. Besides, it is also influenced by the light condition (such as day and night, indoor and outdoor, etc.), cover (such as masks, sunglasses, hair, beard, etc.), age, etc.
Access Control System: through face recognition, the identity of the person entering into the protected areas such as prisons, detention houses, neighborhoods, schools and houses, can be recognized.
Camera Monitoring System: it can be used for monitoring the crowd in public places such as banks, airports, stadiums, shopping malls, and supermarkets. For example, the monitoring system can prevent the terrorists from boarding the plane, or the social security from being stolen. Face recognition is now widely used in many fields, such as student attendance system, camera, phone unlocking, all-in-one machine for human identification, etc.
Back to the smart access control system, due to the build-in learning ability, HUSKYLENS can recognize faces. It works like a collector for a database, marking the face information that is specified to be input. How to operate it in detail? Take out your HUSKYLENS and let’s do it once together.
Note：if you use this camera for the first time, please refer to the product WIKI page for firmware burning and language setting.
Connect HUSKYLENS to the I2C interface on the mainboard of Arduino Uno, and mainboard to the computer via USB, then it could be electrified.
Dial the “function button” to the left until “face recognition” is displayed at the top of the screen.
Point HUSKYLENS at the area with faces on it. When a face is detected, it will be automatically selected by a white frame with the word "Face" on the screen.
Point the “+” symbol at the face that needs to be learned and short press the “learning button”. If HUSKYLENS detected the same face, a blue frame with words "Face: ID1" will be displayed on the screen, which indicates that HUSKYLENS has learned the face before and can recognize it now.
* Long press the “learning button” then let HUSKYLENS learn the face from different angles.
* If there is no “+” symbol on the screen, it means that HUSKYLENS has already learned in the current function. When HUSKYLENS is in the face recognition mode, short press the "learning button", the screen will display "click again to forget". Before the countdown ends, short press the "learning button" again to delete the learned face information, then the yellow "+" symbol is displayed. Now you can let HUSKYLENS learn a new face.
After learning the basic steps of HUSKYLENS, let’s put the smart access control system into practice. The first thing we need to practice is to make the application end able to recognize faces both learned and unlearned. The next step is to add a servo, an RGB light to achieve identification and door opening, while a buzzer to make a warning and welcoming sound. And finally, the doorbell function.
Here, we are firstly going to learn about how to use HUSKYLENS camera to detect and distinguish faces, determine whether the faces are learned or unlearned, and make the servo rotate a certain angle to open the door. The green light will be on if the face has been learned before, otherwise, the red one will flash.
More functions can be added based on learning how to distinguish faces and execute feedback functions. For example, it is realizable to play different music with different faces recognized, so that making a sound of warning and welcome can be achieved.
Different functions are in demand in different places. Here we add a doorbell, which requires an interrupt function.
HUSKYLENS: I2C Pin (T—SDA, R—SCL, +—5V, - —GND)
RGB Light: digital pin 5
Button: digital pin 3
Buzzer: digital pin 2
Servo: digital pin 9
Here we will do a small experiment to distinguish faces, and our camera has learned the specific face information in default. When the camera sees the face again, it can tell if you have learned the face. To make the display function more simple and clearer, the green light of the RGB connecting to digital pin 5 indicates a learned face is recognized. Under this circumstance, the smart access control system will open the door, and close the door after people entered. If unlearned detected, which means strangers, the servo will not rotate and the RGB light will flash red to drive them away.
Open Mind+ (version1.6.2 and above), switch to “upload mode”, and click “expansion”. Choose “Arduino Uno” under “main control board”, “HUSKYLENS camera” under “sensor”, “actuator” under “servo module”, and “WS2818 RGB light” under “display”.
Here are the instructions mainly used.
Let the camera learn a face in advance, and upload the above program to the main control board. When detecting a certain face, the RGB light will flash green in order. After that, the servo will rotate from 10° to 100°, then the door will open. The door will be closed automatically once the people pass. The servo will not rotate when detecting other faces, and the RGB light will flash red to alarm.
By refining the previous code, we can add a piece of music, beautiful or funny one, when RGB light and servo respond if no one or someone unknown is passing by our access control system.
Here we use the buzzer in the kit.
Search on the internet and cut the piece needed.
In Mind+, the instruction of playing notes is built-in, and there are low, medium, high pitches, and various beats.
As shown in the table below, here is a simple way to identify, taking note 2 for example.
Let the camera learn your face in advance, and upload the above program to the main control board. When detecting your face, the RGB lights will flash green in order, and the buzzer will play music2. Meanwhile, the servo will rotate to open the door and close after people pass. If the camera catches other faces, the RGB lights will all flash red to warn the strangers while the buzzer will play a spoof song misic1. If there is no face caught, the light and buzzer will not run.
Question: what if someone comes to visit?
Where should the code of button of buzzer-controlling be put? Imagine it, when someone visits (not the face learned before), the previous program is triggered and music is played. By the end of this or any time someone presses a button, the system should make some reacts. The interrupts have just the ability to stop the current operation and trigger the interrupted program, so here we use interrupts to solve this problem.
Let the camera learn your face in advance, and upload the above program to the main control board. When detecting your face, the RGB lights will flash green in order, and the buzzer will play a piece of joyful music. Meanwhile, the servo will rotate to open the door and close after people pass. If the camera catches other faces, the RGB lights will all flash red to warn the strangers while the buzzer will play a spoof song. If there is no face caught, the light and buzzer will not run. In the above processes, pressing the button at any time will switch the music to "Ding Dong" to realize the visiting function. If there is no face caught, the light and buzzer will not run.
Through the access control system project, we learned the working principle of face recognition and the application of instruction of face recognition algorithm on HUSKYLENS. In AI visual recognition field, face recognition is an essential part with plenty of application scenarios. Let's think about what other face recognition applications we can make.
1. Learn the working principle of face recognition.
2. Learn the related instructions about face recognition of HUSKYLENS.
In this project, we designed an access alarm system by combining face recognition with music and some sensors. However, if applied to the actual scene, the sound of the buzzer alarm is too low, so can we combine it with the Internet of Things? We can try building a home alarm system, using the camera to detect whether there is a stranger outside the door. If the stranger stays too long and does not ring the doorbell to visit, then the Internet of things will send messages to the master's computer or phone. What’s more, it can even realize remote door opening.