The purpose of this tutorial is show how to add Facial Recognition to Raspberry Pi projects.
NOTE: This design of a Facial Recognition Door Lock should not be implemented to protect and lock anything of value or a home. A very simple hack of holding a photo of a “whitelisted” user up to the camera will unlock the door.
In this tutorial, I explain how to use Microsoft’s Face API (Application Programming Interface) to add Facial Recognition capabilities to your Raspberry Pi projects and applications. This project is based on a Microsoft Facial Recognition Door Lock project. This is an intermediate level tutorial; I am assuming you have set up an Operating System (OS) on a Raspberry Pi. If not, I recommend setting up your Raspberry Pi and completing some beginning level projects before attempting this one.
NOTE: Make sure you get Microsoft verified hardware or you will encounter issues getting Windows 10 IOT up and running on your Raspberry Pi. Verified hardware can be found here.
Item | Link |
---|---|
Raspberry Pi 3 | Link for Raspberry Pi |
Microsoft LifeCam HD-3000 | Amazon Link for WebCam |
HDMI Cable | Link for HDMI Cable |
LED | Link for LEDs from Adafruit |
Mouse + Keyboard | Any Wired USB Mouse +Keyboard |
Monitor/TV | Any TV or monitor with HDMI |
Jumper Wires | Amazon Link for Jumper Wires |
Micro USB Cable | Amazon Link for Micro USB Cable |
Breadboard | Amazon Link for Breadboard |
Micro SD Card | Link for Samsung SD Card |
Pushbutton | Link for Pushbuttons w/ Caps |
1. Windows 10 IoT Core Installation
1.2 Installation Steps
Windows 10 IoT Core is the OS you will need to run on your Raspberry Pi for this project. It is a version of Windows 10 optimized for small devices and single-board computers like the Raspberry Pi. This project also requires you have Microsoft Visual Studio installed on a PC.
This tutorial focuses on adding facial recognition to Raspberry Pi, not installing Windows 10 IoT Core, but here are some installation tips.
If you have issues, refer to this post on debugging the installation process.
2. Designing the Circuit
2.1 My Circuit
I always make a wiring diagram using Fritzing, an open-source schematic capture and PCB routing software. You can download Fritzing using the following link (optional): http://fritzing.org/home/
The first schematic is of the circuit I am building with an LED as an actuator (Figure 4: Circuit Schematic w/ LED). I am also just shorting a pin to ground as a sensor to tell the application to take a picture with the camera. This project can be modified to use Facial Recognition with all types of actuators and sensors.
2.2 Project Implemented as a Door Lock
The second circuit is with a relay as an actuator and a pushbutton as a sensor (Figure 5: Circuit Schematic w/ Relay and Lock). If you wish to implement your design as a door lock, this is the circuit you should build. The doorbell signals the camera to take a picture. The relay controls the electric door strike (lock) and will open if the photo taken matches a user on the “whitelist” and remains locked if not.
NOTE: This design of a Facial Recognition Door Lock should not be implemented to protect and lock anything of value or a home. A very simple hack of holding a photo of a “whitelisted” user up to the camera will unlock the door.
Create a folder where you want to put the files for this project. Use the git clone command to download the project.
git clone https://github.com/ms-iot/Facial-Recognition-Door.git
In Visual Studio, open the file called FacialRecognitionDoor.sln. To receive an API key, use this link and click “Try Cognitive Services for free;” then select Face API and follow the login instructions to receive your unique key. Enter your key in the “Constants.cs,” replacing OXFORD_KEY_HERE (Figure 7: Oxford API Key). In this file you can also change the pins used for your doorbell and relay controlling the door lock. You can also modify the messages for a “whitelisted” user and a rejected user.
On the top left of the screen, change the dropdown to “Debug,” “ARM,” and “Remote Machine” (Figure 8: Configuration for Debug).
4.1 Deploying the Application
There a multiple ways to deploy the application to your Windows IoT device. I will list the different options below; one may be easier than the other depending on the hardware you have available. I used option 1.
4.2 Running the Application
When the application starts running you will see the following image appear on your screen (Figure 9: Facial Recognition Start Screen). The first thing you need to do is to add yourself as an approved user to the “whitelist.” To do this, select the plus (+) button in the bottom right corner of the screen. The screen will now ask to take an ID photo of yourself. Look into the camera and click “Capture ID Photo;” the camera will now take your photo and display it on the screen. Enter your name and click “Confirm” to confirm the user profile.
You can now press the pushbutton or doorbell when positioned in front of the camera. If the app recognizes you as a “whitelisted” user it will unlock the door for 10 seconds.
Congratulations, you can now modify this application to use Face Recognition API with other Raspberry Pi projects.