# Raspberry Pi Face Recognition Treasure Box

## Overview

http://www.youtube.com/watch?v=CTP9rpgabYI

Face recognition is an exciting field of computer vision with many possible applications to hardware and devices. Using embedded platforms like the Raspberry Pi and open source computer vision libraries like [OpenCV](http://opencv.org/), you can now add face recognition to your own maker projects! **In this project I'll show you how to build a treasure box which unlocks itself using face recognition running on a Raspberry Pi.**

![](https://cdn-learn.adafruit.com/assets/assets/000/013/672/medium800/raspberry_pi_DSC00396.jpg?1390291779)

Before you get started with this project, it will help to familiarize yourself with a few things:

- If you haven't setup or used a Raspberry Pi, go through the tutorials on [learning the Raspberry Pi](http://learn.adafruit.com/category/learn-raspberry-pi) like [preparing an SD card](http://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi), [network setup](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup), and [using SSH](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh) before attempting this project. Also take a look at the [lesson on using a servo](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor) for more background on how servos work.
- Skim the [OpenCV tutorial on face recognition](https://docs.opencv.org/3.4/da/d60/tutorial_face_main.html) for an idea of how face recognition algorithms work. Don't worry, you don't need to fully understand the math or code to build and learn from this project.

 **This is a learning project for fun** and not suited for real security duty.&nbsp;In addition to the basics of computer vision, you’ll learn vital concepts like the occasional&nbsp;_false positive,_&nbsp;_false negative_ and _spoofing._&nbsp;It’s&nbsp;exciting that we can explore computer vision at the hobbyist level now…but it takes work to get right!

Continue on to learn about the hardware needed to build this project.

# Raspberry Pi Face Recognition Treasure Box

## Hardware

You will need the following parts for this project:

- **[Raspberry Pi computer](https://www.adafruit.com/category/176).** Nearly any model will suffice, old or new…provided it has the camera connector. That leaves out only the Pi 400 and very early Pi Zero units.
- Your Pi will need **internet access** &nbsp;to set up the software, so make sure you have either a wired or WiFi&nbsp;network connection for your Pi.
- [**Raspberry Pi camera**](https://www.adafruit.com/category/177). There are several models now, and most any will do…this is not a demanding project, resolution-wise.&nbsp;Depending on where your camera and Raspberry Pi can be placed inside your box, you might need a [longer](http://www.adafruit.com/products/1648) or [shorter](http://www.adafruit.com/products/1645) camera cable. _Pi Zero models use a smaller camera connector and require special cabling._
- **Small box** that can fit the Raspberry Pi and locking mechanism inside. I found an inexpensive plain wooden box at a craft store, and finished it with wood stain and polyurethane.&nbsp;Look for a box that has hinges which are screwed in from the outside of the box. Although not terribly secure, it will allow you to disassemble and open the box in case the locking mechanism fails to open.
- **Small servo** or lock solenoid for the locking mechanism, depending on how your box can be latched shut.
  - A [servo](http://www.adafruit.com/products/169 "Link: http://www.adafruit.com/products/169") that rotates a latch can work with most boxes that open from the top or side. **The software for this project is written to use a servo.**
  - A [lock solenoid](http://www.adafruit.com/products/1512) can work with boxes that have a door or drawer. See [this locking drawer project](http://learn.adafruit.com/secret-knock-activated-drawer-lock) for information on using a lock solenoid. _As written, the code for this project does not work with a solenoid…this is a “learning opportunity.”_

- **[Momentary push button](http://www.adafruit.com/products/1505)** that can mount to the box. Depending on how thick your box is, you might need a smaller or larger push button. Improvise!
- [Power supply for the Raspberry Pi](https://www.adafruit.com/category/166) and servo or solenoid. Small hobby servos can be powered directly from the Pi’s GPIO header. For larger servos,&nbsp;a [4x AA battery pack](http://www.adafruit.com/products/830) is a simple option.
- Wood, wood glue, and fasteners for building a latch mechanism and frame to support the Pi inside the box. The exact material will depend on your box, but you can see further below how I used 1/4" dowel and thin bass wood to build the frame and latching mechanism for my box.
- [Hookup wires](http://www.adafruit.com/products/1311) to connect the switch, servo, and servo power supply. [Female jumper wires](http://www.adafruit.com/products/824) work well for connecting directly to the Raspberry Pi GPIO pins, or you could use the [Pi cobbler](https://www.adafruit.com/category/163) with a [small breadboard](http://www.adafruit.com/products/64).

Danger: 

## Assembly
The box you use for your project will dictate exactly how the Raspberry Pi, servo, and latching mechanism need to be mounted. Read the notes below for tips on how to construct your hardware, based on how I built mine: Use a box which can fit the Raspberry Pi, servo, and latching mechanism.  
  
Drill a hole in the top or side for the Raspberry Pi camera. I found a 7/16" drill bit was enough for the camera to comfortably fit. Be careful when drilling large holes--work up from smaller bits so you don't crack the box. If you do damage the box, you can generally use wood filler to hide mistakes.  
  
If they aren't mounted there already, consider moving the hinges to be mounted from the outside of the box. This will allow you to disassemble the box in case the hardware fails in a locked position.  
  
Drill a hole in the box to mount the push button. You can see I mounted mine on the back of the box where it can be reached while a user looks into the camera on the top.  
  
Drill another hole to allow power cables to come into the box for both the Raspberry Pi and servo. I found a 1/2" hole was enough to fit a micro USB cable through for powering the Pi. To the left, you can see the hole I drilled in my box next to the push button.

![raspberry_pi_DSC00374.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/728/medium640/raspberry_pi_DSC00374.jpg?1390376164)

![raspberry_pi_DSC00376.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/732/medium640/raspberry_pi_DSC00376.jpg?1390376417)

For the latching mechanism, mount a small dowel perpendicular to the side of the box. Attach a right angle of wood to a servo horn so it can act as a latch that swings down to catch the dowel, locking the box. See the pictures to the left to see the latch mechanism and dowel I built in my box.  
  
If possible, mount the Raspberry Pi in the top of the box or near the hole for the camera. You can see how I mounted my Pi to a small board along with the locking servo, and then attached that board to dowels glued in to form a frame in the box top.  
  
 A few screws and a smaller board can act as a clamp to hold the servo in place.

![raspberry_pi_DSC00397.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/733/medium640/raspberry_pi_DSC00397.jpg?1390376489)

![raspberry_pi_DSC00384.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/734/medium640/raspberry_pi_DSC00384.jpg?1390376555)

![raspberry_pi_DSC00377.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/735/medium640/raspberry_pi_DSC00377.jpg?1390376601)

![raspberry_pi_DSC00381.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/736/medium640/raspberry_pi_DSC00381.jpg?1390376654)

## Wiring

The electronics in this project are fairly simple and involve connecting a servo and push button to the Rasperry Pi. If you have never used these devices with a Raspberry Pi, read the following tutorials for a good overview of their usage:

- [Raspberry Pi Lesson 4: GPIO Setup](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup)
- [Raspberry Pi Lesson 8: Using a Servo Motor](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor)
- [Bread Board Setup for Input Buttons](http://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi/bread-board-setup-for-input-buttons)

Other than the camera (connecting to the “CAMERA” connector on the Raspberry Pi board), only four or five connections are needed…

Here’s a view of the Pi’s GPIO header (40 pins on most boards, 26 on the early Model A and B). This is with the Pi turned “the tall way,” with the two 5V pins near the top-right corner of the board.

The **servo signal** comes from **GPIO18**.

The **button** connects to **GPIO25** and any&nbsp; **ground** pin (there are several, see diagram, _any_ will do but there’s one conveniently right next to GPIO25).

The software is easily reconfigured to use different pins, if you have other devices wired to the Pi that would conflict.

![projects_box-gpio.png](https://cdn-learn.adafruit.com/assets/assets/000/113/915/medium640/projects_box-gpio.png?1659491183)

Small _micro servos_ often work fine powered directly off a 5V pin on the Raspberry Pi.

For larger servos, or for best performance even on small servos, a separate 6V power source is best. In the second image here, notice that there’s no 5V connection to the Pi…but it’s _vital_ that a ground connection is made between the Pi and battery “–” terminal.

These are merely _schematic representations…_you might use a breadboard or not, either way, whatever approach works best. It’s the _connections_ that are important.

![projects_box-fritz-1.png](https://cdn-learn.adafruit.com/assets/assets/000/113/913/medium640/projects_box-fritz-1.png?1659490063)

![projects_box-fritz-2.png](https://cdn-learn.adafruit.com/assets/assets/000/113/914/medium640/projects_box-fritz-2.png?1659490075)

Continue on to learn about how to set up the software for the project.

# Raspberry Pi Face Recognition Treasure Box

## Software

Start with a fresh install of the latest&nbsp; **32-bit Raspberry Pi OS “Lite”** &nbsp;on a flash card.&nbsp;You do not need the “Desktop” version (but no harm done if that’s what you’re most familiar with), and certainly not the 64-bit version (it’s cutting edge and doesn’t always play well with different hardware).

The operating system can be [downloaded from the Raspberry Pi site](https://www.raspberrypi.com/software/operating-systems/) or selected in the _[Raspberry Pi Imager](https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi/raspberry-pi-imager)_ application.&nbsp;Strongly recommend the _Imager_ option, as this gives you the opportunity to **set up an account, ssh and network credentials** before booting the Pi for the first time.

So let’s suppose at this point you have the Pi up and running and accessible on the network…

## Prerequisite Configuration and Installation

First the Pi camera must be enabled with the _raspi-config_ utility. From the command line…

```auto
sudo raspi-config
```

From “ **Interface Options** ,” select “ **Legacy Camera Enable/Disable**.”&nbsp;We want this **enabled**.

You’ll see a warning about future deprecation. That’s okay, we can still use this at present.

From the main menu, select “ **Finish** ” and “ **Yes** ” when asked to reboot. Then log back in and we’ll resume installing.

![projects_cam-enable-1.png](https://cdn-learn.adafruit.com/assets/assets/000/113/917/medium640/projects_cam-enable-1.png?1659492881)

![projects_cam-enable-2.png](https://cdn-learn.adafruit.com/assets/assets/000/113/918/medium640/projects_cam-enable-2.png?1659492886)

![projects_cam-enable-3.png](https://cdn-learn.adafruit.com/assets/assets/000/113/919/medium640/projects_cam-enable-3.png?1659492890)

![projects_cam-enable-4.png](https://cdn-learn.adafruit.com/assets/assets/000/113/920/medium640/projects_cam-enable-4.png?1659492896)

![projects_cam-enable-5.png](https://cdn-learn.adafruit.com/assets/assets/000/113/921/medium640/projects_cam-enable-5.png?1659492901)

![projects_cam-enable-6.png](https://cdn-learn.adafruit.com/assets/assets/000/113/922/medium640/projects_cam-enable-6.png?1659492905)

Back at the command line, the following commands then install _most_ of the prerequisites…

```auto
sudo apt-get update
sudo apt-get install libatlas-base-dev libavcodec-dev libavformat-dev libgtk-3-dev libopenjp2-7 libswscale-dev python3-pip
pip3 install numpy opencv-python picamera
```

(the second `apt-get`&nbsp;should be _one long continuous line…_it may appear wrapped in the browser, but if you click “Copy Code” this will grab these as whole lines)

You can ignore any messages about packages which are already installed or up to date.&nbsp;Also, there are a _lot_ of packages here and _very infrequently_ a server will fail to respond. If you encounter this, try again in a couple hours, it’s usually just a hiccup at the other end.

There’s one more prerequisite package to install…but we must note that this takes _extremely long_ to install!&nbsp;All the underlying face detection software must be downloaded and compiled from source code, a complex process.

**Even on the latest Raspberry Pi, this could take a bit over an hour to run. On older models, especially single-core, _several hours._ You might want to start this before going to bed, or out for errands.**

Ready? Here we go:

```auto
pip3 install opencv-contrib-python
```

Answer “Y” when prompted to start the lengthy install process.

## Project Software Install

After prerequisite software is all loaded above, download the software for this project using:

```auto
cd
wget https://github.com/adafruit/pi-facerec-box/archive/refs/heads/master.zip
unzip master.zip
```

This creates a new subdirectory **pi-facerec-box-master** in your home directory, containing the project code. Let’s go in there to start using the pieces…

```auto
cd pi-facerec-box-master
```

Continue on to learn about training the face recognition algorithm to recognize your face.

# Raspberry Pi Face Recognition Treasure Box

## Training

This project uses the _eigenfaces_ algorithm in OpenCV to&nbsp;perform face recognition. To use this algorithm one first creates a set of _training data_ with pictures of faces that _are_ and _are not_ allowed to open the box.  
   
Included in the project is a large set of face images that are tuned for training with the face recognition algorithm. This is the database of faces&nbsp;published by research AT&T Laboratories Cambridge in the mid 90's. These faces make up the set of negative images which represent faces that are not allowed to open the box. You can see these images in the **training/negative** subdirectory of the project.  
  
To generate images of the person who will be allowed to open the box, or positive training images, you can use the included **capture-positives.py** script. This script will take pictures with the box hardware and write them to the **training/positive** sub-directory (which will be created by the script if it does not exist).  
  
With the box hardware assembled and powered up (servo power is not necessary for this step), connect to the Raspberry Pi in a terminal session and navigate to the directory with the project software. Execute the following command to run the capture\_positive script:

```auto
python capture_positives.py
```

After a moment for the script to load, you should see the following instructions:  
  
**Capturing positive training images.  
Press button or type c (and press enter) to capture an image.**  
**Press CTRL-C to quit.**  
  
The script is now ready to capture images for training. If you see an error message, make sure OpenCV and the software dependencies from the [previous step](http://learn.adafruit.com/raspberry-pi-face-recognition-treasure-box/software) are installed and try again.  
  
Point the box's camera at your face and press the button on the box (or send the letter 'c' in the terminal session) to take a picture. If the script detects a single face, it will crop and save the image in the positive training images sub-directory. If the script can't detect a face or detects multiple faces, an error message will be displayed.  
  
If see error messages about not detecting a single face, you can examine the full picture that was captured by the camera to understand if it's picking up your face (or if other faces might be in view--be careful, even photos or posters with faces behind you can be detected!). Sometimes it’s just that the camera is upside-down. Open the file **capture.pgm** (located in the directory with the scripts) in an image editor to see the last image that was captured. It's easiest to use a tool like [Cyberduck](http://cyberduck.io/ "Link: http://cyberduck.io/") to view the files on your Raspberry Pi over SFTP (SSH file transfer protocol).&nbsp;

**NOTE:** As each image is captured, you _might_ get an error message like the following:

**imwrite\_('capture.pgm'): can't write data: OpenCV(4.6.0) […]**

**error: (-5:Bad argument) Portable bitmap(.pgm) expects gray image in function 'write'**

_This is non-fatal and can be ignored._ The image _is_ gray, something in an underlying library is just reporting wrong. Sorry!

Using the capture\_positives.py script, capture some pictures of the face that is allowed to open the box. Try to take pictures of the face with different expressions, under different lighting conditions, and at different angles. You can see the images I captured for my positive training data below:

Training images I captured for my face. Try to get pictures with different expressions, in different light, etc. to build a better face recognition model.

![raspberry_pi_training_images.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/697/medium640/raspberry_pi_training_images.jpg?1390343498)

Exit the **capture\_positives.py** script by pressing CTRL-C in the terminal session.

After capturing a number of positive training images, you can run the **train.py** script to perform the _training._ Run the following python script to train the face recognition model:

```auto
python train.py
```

You should see a message that the training images were loaded, and the text 'Training model...' to indicate the training calculations are being performed. Training the face recognition model on the Pi can take several minutes.

Once the training is complete you should see the message 'Training data saved to training.xml'. The training data is now stored in the file training.xml, which will be loaded by the box software to configure the face recognition model.

If you're curious you can examine images that are output by the training to visualize the eigenfaces of the model. Open the mean.png, positive\_eigenface.png, and negative\_eigenface.png files in an image viewer. You don't need to do anything with these images, but can learn more about their meaning from the OpenCV website, Wikipedia, or the original research paper on eigenfaces.

_Eigenfaces_ generated from my training data.   
  
The _positive eigenface_ is a summary of the features that differentiate my face from the average or mean face. This face will be allowed to unlock the box.  
  
The _negative eigenface_ represents all the other faces in the training set. This face will not be allowed to unlock the box.

![raspberry_pi_eigenfaces.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/698/medium640/raspberry_pi_eigenfaces.jpg?1390343557)

With the **training.xml** file generated, you're ready to move on to configure the servo latch and software for the project.

# Raspberry Pi Face Recognition Treasure Box

## Configuration

## Servo Configuration

In this step you'll determine the positions for the locked and unlocked servo positions of the box. Make sure the hardware is assembled, the software dependencies are installed, and power is applied to both the Raspberry Pi and servo before you continue. Connect to the Raspberry Pi in a terminal session, “cd” to the project directory and type the following command:

```auto
python servo.py
```

Servos operate on timed pulses, typically from 1000 to 2000 microseconds long (but a few servos may function a bit beyond this range), covering the full “sweep” of the servo (usually 180 degrees, sometimes 90 for high-torque units).

Using this script, you can interactively type in different timing values and see how this affects servo position. Idea is to progressively dial in on good values for “open” and “locked” positions.

_If your servo is connected to a different pin than GPIO18, edit the file **config.py** and change the number associated with&nbsp; **LOCK\_SERVO\_PIN**._

You can see the values I found for my hardware below:

Latch in the unlocked position with a servo pulse width of 2000 microseconds.

![raspberry_pi_DSC00392.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/674/medium640/raspberry_pi_DSC00392.jpg?1390334645)

Latch in the locked position with a servo pulse width of 1100 microseconds.

![raspberry_pi_DSC00391.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/675/medium640/raspberry_pi_DSC00391.jpg?1390334757)

Take note of the pulse width values you determined for the locked and unlocked position as they will be used later in the configuration, then press CTRL-C to exit.

## Software Configuration

In the directory with code for this project, open the file **config.py** in a text editor. This file defines the configuration for the project and might require a few changes for your hardware. Specifically you can adjust the following values:

- **LOCK\_SERVO\_PIN** - this should be the GPIO number of the Raspberry Pi which is connected to the signal line of the lock servo. This project is built to use GPIO 18 by default.
- **LOCK\_SERVO\_UNLOCKED** - this should be the pulse width value (in microseconds) for the unlocked position of the latch. Use the value you determined in the previous step.
- **LOCK\_SERVO\_LOCKED** - this should be the pulse width value for the locked position of the latch.
- **BUTTON\_PIN** - this should be the GPIO number which is connected to the push button on the box. This project is built to use GPIO 25 by default.

The rest of the values in the configuration can be ignored. The only other value of interest is the **POSITIVE\_THRESHOLD** configuration, which gives the boundary for how confident the face recognition has to be before it's considered a positive match. For now the default value of 2000 should suffice, but it can be adjusted later if the box has too many false positive or false negative recognitions.  
  
Continue on to run the box software and finish the project.

# Raspberry Pi Face Recognition Treasure Box

## Usage

To run the box software, make sure the hardware is assembled and the [training](http://learn.adafruit.com/raspberry-pi-face-recognition-treasure-box/training-1) is complete. First you'll run the box with only power to the Raspberry Pi and not the lock servo--this will allow you to test the face recognition without locking yourself out of the box. Apply power to just the Raspberry Pi (and not the servo), then connect to the Pi in a terminal session, navigate to the folder with the software, and execute the following command:

```auto
python box.py
```

You should see the box software load and the message 'Loading training data...' appear. Allow a moment for the training data to load and the following message to appear:

**Running box...**  
**Press button to lock (if unlocked), or unlock if the correct face is detected.**  
**Press CTRL-C to quit.**

The box will lock itself (if no power is applied to the servo yet, the lock latch should not move) and be ready to try unlocking with face recognition. Aim the box camera at your face, like you did when training the face recognition model, and press the button on the box. You should see a message that the button was pressed, and after a moment if the face is recognized you will see a message like:

**Predicted POSITIVE face with confidence 1321.35253959 (lower is more confident). Recognized face!**

If the face is not recognized you will see a message like:

**Predicted NEGATIVE face with confidence 3987.76625152 (lower is more confident). Did not recognize face!**

If a single face couldn't be detected (because none is visible, or there are multiple faces detected) an error message will be displayed like with the training script.

When a face is found, you'll notice the prediction message includes how the face was recognized (i.e. matching either the positive or negative training data), and the confidence of the recognition. The confidence is a value like 1321.35 or 3987.77 above and represents the distance of the captured face from the predicted face--a lower distance value means the captured face is more similar to the predicted face.

To unlock the box, a captured face must be a positive prediction with a confidence value below the POSITIVE\_THRESHOLD configuration value. By default the POSITIVE\_THRESHOLD is 2000, so the positive prediction with confidence 1321.35 was considered a match and would have unlocked the box.

When the box is in an unlocked state, press the button to lock the box again. You do not need to have a face recognized to lock the box.

Play with unlocking and locking the box to see what prediction and confidence you get from your trained face recognition model. Ideally you want images of the positively trained face to be predicted as positive images with a low number for the confidence value. The eigenfaces recognition algorithm is sensitive to the lighting and orientation of your face, so try to have as similar conditions as when the positive training images were captured (or consider re-training your model to include more varied images).

You can see examples of how my training data predicted faces below (remember you can look at the capture.pgm image in the software directory after pressing the button to attempt a face recognition):

This image unlocked my box because it was a match for the positive training images, and had a confidence of 1321.35 which was below the threshold of 2000.

![raspberry_pi_positive_capture.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/703/medium640/raspberry_pi_positive_capture.jpg?1390351605)

This image of a face from a magazine did not unlock my box because it was a match for the negative training data, with a confidence of 3987.77.

![raspberry_pi_negative_capture.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/704/medium640/raspberry_pi_negative_capture.jpg?1390351642)

This image unfortunately did not unlock my box. Although it was predicted as a positive match, the confidence was 2269.04 which was slightly higher than the positive match threshold.   
  
If you get a lot of false negative predictions like this, it's a sign you need better training data or should adjust the **POSITIVE\_THRESHOLD** configuration value up.

![raspberry_pi_false_negative_capture.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/705/medium640/raspberry_pi_false_negative_capture.jpg?1390352556)

This image matched the positive training data, but the confidence value of 4407.85 was too far above the threshold to unlock the box.   
  
If you get a lot of false positive responses like this it's also a sign that you need better training data. Remember face recognition is far from perfect--there's always a chance someone who looks like the positively trained images will match close enough to unlock the box!

![raspberry_pi_false_positive_capture.jpg](https://cdn-learn.adafruit.com/assets/assets/000/013/707/medium640/raspberry_pi_false_positive_capture.jpg?1390353189)

Based on how the face recognition responds, you might consider training it again or adjust the **POSITIVE\_THRESHOLD** configuration to a higher/lower value.   
  
When you're happy with how the recognition is working, apply power to the servo and try locking and unlocking the box for real. Congratulations on building the face recognition treasure box!  
  
If for some reason your box is locked and will not recognize a face to unlock itself, you can manually set the servo position to an unlocked value by following the steps in the [servo configuration](http://learn.adafruit.com/raspberry-pi-face-recognition-treasure-box/configuration). If you don't have access to the Raspberry Pi terminal or the servo isn't moving, unfortunately you'll need to disassemble your box (this is why it's a good idea to use a box with hinges on the outside!).

# Raspberry Pi Face Recognition Treasure Box

## Future Work

This project is a great example of how to use the Raspberry Pi and Pi camera with OpenCV's computer vision algorithms. By compiling the latest version of OpenCV, you can get access to the latest and most interesting computer vision algorithms like face recognition. You can consider extending this project in other interesting ways, such as:

- Adding LED's to the box which flash when a face is detected and recognized. This feedback would help you train and use the box without having to connect to the Pi in a terminal session.
- Make the main box.py script start up automatically when the Raspberry Pi powers on. Search the web for “systemd startup” for tips on&nbsp;automatically running a script at start up.
- Investigate using other face recognition algorithms in OpenCV. See the [OpenCV tutorial on face recognition](http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html "Link: http://docs.opencv.org/modules/contrib/doc/facerec/facerec\_tutorial.html") for more information. Algorithms such as Fisherfaces might be more robust to varied lighting or other conditions.
- Have the box send you an email with a picture of whoever is attempting to open it.
- Add a microphone and look at adding [speech recognition](http://raspberrypi.stackexchange.com/a/10392 "Link: http://raspberrypi.stackexchange.com/a/10392") as another means of unlocking the box.

Can you think of other ways to extend the project?


## Related Guides

- [Bluetooth Controlled NeoPixel Lightbox](https://learn.adafruit.com/bluetooth-neopixel-lightbox.md)
- [BLE Volume Knob with CircuitPython](https://learn.adafruit.com/bluetooth-le-hid-volume-knob-with-circuitpython.md)
- [Adafruit HUZZAH32 - ESP32 Feather](https://learn.adafruit.com/adafruit-huzzah32-esp32-feather.md)
- [CircuitPython Libraries on Linux and the 96Boards DragonBoard 410c](https://learn.adafruit.com/circuitpython-libraries-on-linux-and-the-96boards-dragonboard-410c.md)
- [Make an AI Freezer Monitor](https://learn.adafruit.com/ai-freezer-monitor.md)
- [Automatic Cat Treat Dispenser](https://learn.adafruit.com/automatic-cat-treat-dispenser.md)
- [How To Solder Headers](https://learn.adafruit.com/how-to-solder-headers.md)
- [Unicorn Hat with Moving Ears](https://learn.adafruit.com/unicorn-hat-with-moving-ears.md)
- [IBM PC Keyboard to USB HID with CircuitPython](https://learn.adafruit.com/ibm-pc-keyboard-to-usb-hid-with-circuitpython.md)
- [ANO Directional Navigation and Scroll Wheel Rotary Encoder and Breakout](https://learn.adafruit.com/ano-rotary-encoder.md)
- [Bluefruit Ouija Board](https://learn.adafruit.com/bluefruit-ouija-board.md)
- [Lucky Cat with Circuit Playground Express](https://learn.adafruit.com/lucky-cat-with-circuit-playground-express.md)
- [Crickit Controlled Animatronic Eyeball](https://learn.adafruit.com/crickit-controlled-animatronic-eyeball.md)
- [Adafruit Metro ESP32-S3](https://learn.adafruit.com/adafruit-metro-esp32-s3.md)
- [Circadian Pi Desk Light](https://learn.adafruit.com/circadian-pi-desk-light.md)
