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 (

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


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

5. Build the training file


6. Add my file to the folder

7. Try the script out

sudo python

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 (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 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


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


Unboxing my Rapiro kickstarter!

Posted on Updated on

After a bit of a wait I got my Rapiro today and started to put it together, this should be quite a fun bit of kit!

A box

Posted on Updated on

Built a nice box for the humanoid head I’m working on today and mounted the final servo.. Next eyes and so many options!


I also git to show him off at rLab robot workshop today which was just an inspiring day!!


Bit better motion vid

Video Posted on Updated on

The jaw hinge is attached and he’s plugged into an Arduino and already a lot better movement… still a lot of work to do – but looking good and really fun!

Robot gets his moves on

Posted on Updated on

My 3d printed robot getting his first moves on, unfortunately he was missing a hinge in his jaw, but its still v cool!



Image Posted on Updated on

Reading Hackspace is hosting a Robot Workshop on the 3rd of November (, so rather than go empty handed I’ve been building my own.

About this time last year I done a huge amount of work on stereo vision and hope to plug that back into this guy.