Rapiro facial recognition with OpenCV and Raspberry Pi

Posted on Updated on

I decided to have a go at doing something fun with my Kickstarter Rapiro this evening and got some inspiration from Tony DiCola on the AdaFruit blog (http://learn.adafruit.com/raspberry-pi-face-recognition-treasure-box?view=all).

So here are the steps I took and the script I put together for my Rapiro Facial Recognition 3am hack.

1. Install open CV

sudo apt-get update

sudo apt-get install build-essential cmake pkg-config python-dev libgtk2.0-dev libgtk2.0 zlib1g-dev libpng-dev libjpeg-dev libtiff-dev libjasper-dev libavcodec-dev swig

wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.7/opencv-2.4.7.tar.gz

tar zxvf opencv-2.4.7.tar.gz

cd opencv-2.4.7

note: the make command takes about 5 hours!


sudo make install

2. Install Python Dependancies

sudo apt-get install python-pip

sudo pip install picamera

sudo pip install rpio

sudo apt-get install python-serial

3. Download Tony’s base project here from GitHub note that I deleted all the negative training images or it takes an age to run the final script.

4. Take Pictures of you – type c (and press enter) to capture about 10-12 images in different orientations and expressions.

sudo python capture-positives.py

5. Build the training file

python train.py

6. Add my rapiro.py file to the folder

7. Try the script out

sudo python rapiro.py

8. If it works add it to a bash script on startup (Make sure you are in the pi folder)

cd ~
sudo nano rapiroscript
type these lines:
cd pi-facerec
sudo python rapiro.py (save and exit: Ctrl+X, Y, Enter)
sudo nano .bashrc Scroll down to the bottom and add the line: ./rapiroscript (save and exit: Ctrl+X, Y, Enter)

9. Finally auto login

sudo nano /etc/inittab
find: 1:2345:respawn:/sbin/getty 115200 tty1
comment out like so: #1:2345:respawn:/sbin/getty 115200 tty1
then add below this line: 1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

10. You can add commands or play around with some different ones in the rapiri.py script

  • #M1 – robot will move forward
  • #M2 – robot will move backward
  • #M3 – robot will turn right
  • #M4 – robot will turn left
  • #M5 – robot will raise his hand and wave the left hand. LED will become green and flashing
  • #M6 – robot will lower his left hand. LED will become Yellow
  • #M7 – robot will move both arm and contract his hands. LED will become Blue
  • #M8 – robot will wave goodbye with his left arm. LED will become RED.
  • #M9 – robot will raise its right arm and move its waist. LED will become BLUE
  • #M0 – robot will go to initial position
  • #PS00A000T010#PS00A180T010 – full head movement from side to side
  • #PS01A000T010#PS01A180T010 – Waist
  • #PS02A000T010#PS01A180T010 – r Shoulder
  • #PS03A000T010#PS03A180T010 – r Arm
  • #PS04A000T010#PS04A180T010 – r HAND
  • #PS05A000T010#PS05A180T010 – l Shoulder
  • #PS06A000T010#PS06A180T010 – l Arm
  • #PS07A000T010#PS07A180T010 – l hand
  • #PS08A000T010#PS08A180T010 – r Foot yaw
  • #PS09A000T010#PS09A180T010 – r Foot pitch
  • #PS10A000T010#PS10A180T010 – l Foot yaw
  • #PS11A000T010#PS11A180T010 – l Foot pitch

or more here http://forum.rapiro.com/thread/21/


This is very useful for testing

sudo apt-get install minicom

echo "#M6" | sudo minicom -b 57600 -o -D /dev/ttyAMA0

And for viewing the PiCam on a Mac

nc -l 5001 | mplayer -fps 31 -cache 1024 - run this on your mac after installing brew then running brew install mplayer
raspivid -t 999999 -o - | nc 5001 run this command on your Pi with your Macs IP

One thought on “Rapiro facial recognition with OpenCV and Raspberry Pi

    2017 week 8 in review – D’Arcy Norman dot net said:
    February 26, 2017 at 5:06 pm

    […] Rapiro facial recognition with OpenCV and Raspberry Pi « Gary Fletcher […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s