Face Recognition Treasure Safe

Protect your valuables from prying eyes without remembering a combination or carrying a key; your face is the key to unlock this safe! This project will show you how to use a Raspberry Pi and Pi camera to build a safe that unlocks itself using face recognition.

The software for this project is based on algorithms provided by the OpenCV computer vision library. The Raspberry Pi is a perfect platform for this project because it has the power to run OpenCV, while being small enough to fit almost anywhere.

Step #3: Bend the servo bracket

This piece will function as the servo mounting bracket and must be custom fit on each specific safe.

Mark and cut a rectangle about 1½"×8" from the sheet metal. In the center, mark out a rectangle that matches the face of your servo.

Clamp the sheet metal to a work surface and remove the center rectangle with a chisel. Clean up the edges with a file.

Test-fit your servo into bracket and the servo horn. Then bend the strip so it fits around the locking mechanism of the safe, securing your servo in place. Use a vise for support. If the metal isn't pliable, use a small hammer to aid in the bending.

Step #12: Train face recognition

In a terminal session on the Pi, navigate to the directory with the software and execute the following command to start the training script:
sudo python capture-positives.py

Once the training script is running you can press the button on the box to take a picture with the Pi camera. The script will attempt to detect a single face in the captured image and store it as a positive training image in the ./training/positive subdirectory.

This takes about 10 minutes to run and will train the classifier to recognize your face.

Every time an image is captured it is written to the file capture.pgm. You can view this in a graphics editor to see what the Pi camera is picking up and help ensure your face is being detected.

Use the button to capture around 5 or more images of your face as positive training data. Try to get pictures from different angles, with different lighting, etc. You can see the images I captured as positive training data above.

NOTE: If you're curious you can also look at the ./training/negative directory to see training data from an AT&T face recognition database that will be used as examples of people who are not allowed to open the box.

Finally, once you've captured positive training images of your face, run the following command to process the positive and negative training images and train the face recognition algorithm (note that this training will take around 10 minutes to run):
python train.py

Step #14: Use it!

At this point all the configuration is done and the box is ready to go. To run your Face Recognition Treasure Safe, execute this: sudo python box.py

The box will lock itself and wait for the button to be pressed, then grab a camera image and try to recognize the face of the user. If it matches it will unlock itself. The button can be pressed to lock the box and repeat the process.

Step #15: Troubleshooting

If the face recognition isn't working well you can either take more positive training images and train it again, or tweak the POSITIVE_THRESHOLD to a higher value in the config.py file to make it less sensitive.

If for some reason you can't get it to recognize you at all and you need to force the box unlocked, run servo.py again and input the unlocked servo position.

I love to tinker and write about electronics. My days are spent building projects and working as a Technical Editor for MAKE.

Advertisement

Clint Buckman

How hard would it be to modify to have multiple users and show the last user on and lcd?

Remi Jonquieres

Sure! I am helping NovoSIP (www.novosip.com) the French team that conceived a SIP video door station and I think that it could be a great idea to have it together in the Raspberry Pi and allow the residents with more that one face (visitors are using the call button of the door phone).

I am working on my fourth attempt to get the software working. I have installed Raspian from a new copy of NOOB. I use the terminal commands and everything seems to work fine. After enabling the camera, I reboot it. Then it hangs up when looking at the USB keyboard or mouse. The startup sequence stops there.

Any ideas?

Howard Adrin Story

I have had trouble with the untested wireless Wifi. The pi would lock up every 12 to 24 hours. But in your case. I would look at the power supply you are using. Make sure it at least what is recommended.

George Spelvin

Yup – The recommended power supply was slow in shipping, so I was using one that was probably dodgy. All is working great now!

Luis Orbegoso

Con una foto tuya la abren.

Zachary

How would you change the code so that instead of activating a servo motor, it would trigger a relay switch?

Jim Willette

The magazine article says that the schematic and code would be on this page, but I can’t find them here. Maybe I’m dense, but where is this (vital) extra material?