There are dozens of excellent smart doorbell projects that use facial recognition to tell you who is at your door. While this idea isn't unique, hopefully this project is simpler to put together than most. It's also nice because it doesn't use a 3rd party facial recognition software, so you can rest assured that nobody is stealing your face data (...except of course facebook and every photo sharing app you use).PREREQUISITES
Ok, the prerequisites take longer than five minutes. But I promise that the rest of the tutorial only takes five minutes.SETUP
Boot up your MaaXBoard. I'm using remote desktop that we set up in headless mode, and I'm also using a virtual environment. Enter your virtual environment (mine is named "cv"):
- Install face_recognition on the MaaXBoard.
face_recognition bills itself as "the world’s simplest face recognition library" and they're not exaggerating. It's incredibly easy to use the python and examples.
face_recognition is built on top of dlib. Dlib is an incredible resource of open source c++ machine learning algorthims. Dlib's facial recognition model that face_recognition uses was trained on over 3 million faces is and has a 99.38% accuracy with a standard deviation of 0.00272 on the LFW bechmark.
And yes, dlib is quite large and installing it takes a long time (I didn't include that in the tutorial's five minutes). I've included the -vvv (maximum verbosity) option so that you can tell that it's still running and not hung up on something.
pip install dlib -vvv
You'll probably see some warnings, but dlib should install correctly. Once it's done, check to make sure that it is installed:
Now install face_recognition:
pip install face_recognition
I'm planning to create an LTE version of this project soon using Avnet's Monarch GO. Until then, as long as your MaaXBoard has a WIFI or ethernet connection you can use the Twilio API to send texts (I'm using the free version).
Install twilio using pip:
pip install twilio
You can follow the instructions here to get Twilio set up using Python on MaaXBoard.Give yourself camera permissions
Make sure your camera is plugged into the MaaXBoard. You can use a USB webcam or a MIPI-CSI camera.
MaaXBoard's linux version doesn't allow non-root users to access serial devices, like MIPI-CSI or USB cameras. If you're not logged in as root, you'll have to grant your user permissions if you haven't already.
ls -l /dev/video*
This will tell you the ownership and the permissions for the existing cameras.
/dev/video0 is the MIPI-CSI driver and it always shows up, whether or not there is a camera inserted. If you have a USB webcam, it will always be
/dev/video1 or higher.
You should now be able to run sudo chmod for any cameras you have to grant permission to non-root users:
sudo chmod -R a+rwx /dev/video1
sudo chmod -R a+rwx /dev/video0
First, edit the code to include your Twilio auth ID, auth token, phone number, as well as the phone number you would like to text. Replace the obama.jpg and biden.jpg with whomever's photo you would like to recognize.
If you're using a USB webcam, you'll probably need to change
video_capture = cv2.VideoCapture(1).
Then run the code:
Want to make it faster? Face_recognition lets you run in parallel on all 4 of your maaxboard's cores! Just use use the --cpus flag:
python face_rec.py --cpus 4
This super simple version of the code needs to train on only a single image of a person in order to to detect their face!
I was able to successfully detect four different friends faces with 100% accuracy using just one image of each of us.
If you'd like to know more about how facial recognition works, Adam Geitgey, the author of face_recognition library, has an excellent blog post here.