If you recently built a Wi-Fi spy camera out of an ESP32 CAM, you can use it for several things. A baby monitor at night, a security camera to catch parcel thieves, a hidden video streamer to catch someone going somewhere they shouldn’t be – you could use it for just about anything. Best of all, this cheap camera module can perform face detection and facial recognition!
The cheap ESP32-CAM is an interesting camera module because it has enough RAM to perform those face detection and face recognition processes. The detection can recognize faces when they appear in the frame, while the recognition can spot intruders or identify faces that you have registered in the code. It̵
It’s pretty good not to mix up faces (we couldn’t trip it at all), but it can show a registered ID as an intruder due to the limited number of face scans it registers for the database. You can overcome this by inscribing the same face several times at different angles and remembering to assign each ID to the correct person.
These are the basics you’ll need to continue with this project. If you’ve already built and set up your WiFi spy camera using our previous guide, you should have everything you need to dive straight into using the facial recognition features.
Please note that the required battery may be of a different size if required.
Step 1: Set up your WiFi spy camera
We already showed how to set up the ESP32-CAM in Arduino IDE, open the default CameraWebServer sketch, modify the sketch code to select the correct camera module and add the Wi-Fi credentials, connect the ESP32-CAM to the FTDI programmer , upload the sketch to the ESP32-CAM, turn on the spy camera, find the IP address and connect to the web server interface.
There’s no need to go over all that again once we’ve got a full guide to it, so check that if you don’t have your WiFi spy camera online.
Step 2: Try Face Detection
In a web browser, connect to your Wi-Fi spy camera’s IP address to open the web interface. Then press the “Start Stream” button at the bottom to start the live camera feed.
Then increase the resolution if necessary, but don’t exceed 400 by 296 pixels, as face recognition doesn’t work in higher resolutions.
Now go back down and turn on the “Face Detection” switch. This mode detects when a human face is in front of the camera lens, and you can tell it’s working when a frame appears around the face. (It’s based on the ESP-WHO project, in case you were wondering.)
If your ESP32-CAM is still connected to your computer while Arduino IDE is running, you can open the serial monitor in the IDE to view the serial output. Here you can see that the face detections have been captured.
With this information, you could create a simple Bash script to grep and monitor a continuous stream, then build a program that detects faces and sends you notifications on your phone when someone is at the door, for example. You could basically make a really bare-bones Ring Video Doorbell. This is beyond the scope of this article, but it could be a future Null Byte guide!
Step 3: Try facial recognition
Now go back to the bottom and turn on the “Face Recognition” switch. This mode extends the detection capabilities to identify faces in the feed and is also part of the ESP-WHO project.
When a face is unknown, it will have a red box around it with an “Intruder Alert!” warning.
Back in the serial monitor, you can also see these intruder warnings, which basically means the face isn’t in your database.
In order for the face recognition tool to identify and name people’s faces, those faces must be registered. Back at the bottom of the interface, when an intruder is in the feed you want to name, click ‘Enroll Face’. It will then take several snapshots of the face until it has enough to recognize it, then it will say “Hello Subject 0” in green.
Back in the serial monitor you can see that the subject identifies 0.
Any subsequent faces you enroll will be tagged as Subject 1, then 2, and so on.
In the serial monitor, you can see that it identifies the subject by the number of each.
How accurate is the facial recognition?
Although it is a fairly simple program, it does a good job at recognizing faces. In tests, we were unable to get random images of people’s faces that match a subject’s real face and be identified as such.
We were also unable to identify inscribed faces as other inscribed faces. However, since only a few snapshots are required when registering a face, it may detect a subject as an intruder if the angle of view is different from the shooting. Plus, the software isn’t sophisticated enough to detect faces when they’re only partially seen or tilted too much, but it does work well for profile shots and tight angles.
Keep this in mind for other projects
As you have just seen, there are limitations to using a small microcontroller with a camera module to perform face detection and recognition. But it’s a great project if you want to take the next step and code your own applications that use face detection and recognition as factors. The serial monitor can be constantly monitored to look for detected faces, intruders and registered faces, and all it takes is a simple script to make it work.
Do you want to earn money as a white hat hacker? Jump-start your hacking career with our 2020 Premium Ethical Hacking Certification Training Bundle from the new Null Byte Shop and get over 60 hours of training from cybersecurity professionals.
Buy now (90% discount) >
Other valuable deals to check out: