Facial Recognition Door Lock (2019)
For a summer project, I wanted to build something I could use in my everyday life. After a little bit of research, I found it was possible to utilize real time computer vision with a library of programming functions called OpenCV. After downloading the necessary resources onto a Raspberry Pi, I began to study how to code what I wanted to do in Python. After a lot of trial and error, and piecing together the puzzle I wanted to complete, I was finally able to make my vision a reality.
Haar Cascade Classifiers
These are a machine learning approach that trains from positive and negative (Dark vs Light) in images. When converted to grayscale, these can be labelled as black and white pixels (0-255, whichever end of the grayscale spectrum it falls closer to. For example, the most relevant features of the face (eyes, nose, mouth, forehead, and eyebrows) create shadows, creating a distinct feature (Edge features and Line features) that the computer can learn from and then detect these features after training to see if a face is recognized. These features are scales and resized (similar to Fourier-analysis) to create a better model. |
LBPH Algorithm (Local Binary Pattern Histogram)
Now that the facial features are detected from the Haar Cascade Classifiers, a "box" is created around the face. This block is converted into several smaller blocks. For each block it looks at nine pixels at a time (3x3 grid) with an interest in the center block. Each neighbor of the center pixel is compared to the center and sets a value of '1' or '0' if it is greater than or less than that pixel on the grayscale. These blocks are then read in a clockwise manner to form a binary number, which is then converted into a decimal and becomes the new value of the center pixel. A histogram is created of these decimal numbers for each block on the image. |
|
How it all works together
The storeroom style lock allows the outside door handle to always be locks while the inside door handle remains always unlocked. The electric door strike is set to normally open (Normally locked in our case) so that it remains latched whenever there is no electricity running through it (Initially it was set to be normally closed so that when electricity entered it, it would unlocked but was switch in order to reduce power consumption over time). Whenever the doorbell is pushed, it sends an input to the Raspberry Pi. This input tells the camera to turn on and start searching for a face to compare to the ones we have stored in a data set. Once a face is detected and recognized, an output from the Raspberry Pi is sent to a relay that send 12V to the door strike, causing it to unlatch and then the door can be pushed open from the outside without having to turn the door handle. After 10 seconds, the relay is reverted back, closing off the electricity to the door strike. There is also a loop for the camera that turns it off after 15 seconds if a face is not recognized, needing for the door bell to be pressed again to start the process over. |
The wiring in the video was a little messy, so I cleaned it up to be a little bit more practical. Throughout this process, I learned more about what the OpenCV library is capable of, and learned more about coding in Python along the way. I made several tweaks as I went along to make it more usable and more efficient (such as adding a doorbell to turn the camera on, adding the loop to turn the camera off after so many seconds and changing the door strike from normally closed to normally open) to save electricity as well as prevent overheating from processing images all the time. I now have a cool and unique way to get into my home safely without needing to carry a key (Although I do have one incase of a power outage!). There are many ideas I'd like to add to this project in the future, but those shall remain a secret for now! |