1. Let your Pi talk !
Now, your Pi must be able to speak. A very easy way to do it is to install espeak. (espeak is enough now, you don’t need to install Mbrola any more).
sudo apt-get update
sudo apt-get install espeak

espeak

Test it using a simple command line
espeak “hello world.”
Voice by default is english. If you want to change, select your voice using -v flag.
List of languages is here.
espeak -vfr “coucou lapin.” will talk with french accent.
For same language, you can select alternative voices using +m1 (for male voice, 1..4) or +f1 (for female voice, 1..4).
Speed is also a parameter : -s130 (by default : 100).
I recommend you to play with all these parameters to find a not-too-much-creepy voice 😉
If you want to read content of a file, just use -f option.
espeak -f “to_read.txt” -vfr+f2 -s130

2. understand source code
Once again, this source code is strongly inspired from Philipp Wagner source (here).
Download the source code here. I added a lot of comments to be more pedagogic as possible.
Algorithm is quite simple :

  • read config files with training pictures previously created in step 6 : store them in a picture collection
  • init some parameters, create a Eigen model (could be a Fisher model also)
  • train the Eigen model with collection of pictures
  • init webcam and start an infinite loop
    • capture photo
    • detect faces
    • for each face
      • try to recognize people leanrt
      • if success (confidence > threshold)
        • put name in the output image
        • speak to this person
        • display the output image

All funny parts are inside the speakTo function. Here you can add as many smarts behaviors as you want. It’ll let think your mirror is really a magic one.
Some exemples :

  • say time
  • depending hour of the day, propose important things to do : propose a morning coffee, remind to wash teeth before to go to sleep, remind to call his mother all sunday, ..)
  • connect to internet to get weather, stocks exhange, google calender next meeting, (see step 7 of this blog for code exemples)
  • adapt your speak to personn recognize (basic rules: tell a woman she’s beautiful, and tell a man he’s strong).

For such “smart agent” : the Wii balance board is a very good exemple : when you connect, your Wii always tell you short, funny and very-well adapted things…

3. compile
This step should not be difficult if you use this CMakeLists.txt. (notice the libopencv linked as already seen in step 3)

cmake_minimum_required(VERSION 2.8)
project( reco)
find_package( OpenCV REQUIRED )
add_executable( reco faceReco.cpp )
link_directories( /home/pi/pierre/libfacerec-0.04 )
target_link_libraries( reco /home/pi/pierre/libfacerec-0.04/libopencv_facerec.a ${OpenCV_LIBS} )

4. Test & Enjoy
Now, it’s time to test and to enjoy !
./reco csv-filename histo threshold
./reco faces.csv 1 5500

  • csv-filename : filename of csv file where you put all your training pictures path
  • histo : 0/1 : do you want to do a color equalization histogram before detecting face ? (try both and decide)
  • threshold : level of confidence above wich, you decide to recognize somebody (need to be tune after first run : use 5000 by default for Eigen Model (less for Fischer model)

Note : Light sensibility will depend on your webcam. With my logitech C270, it works well with natural light and artificial light.
Play with paramater (including training picture creation) and find your best set of parameter.

5. Install your Magic Mirror !
Select a wooden home-made mirror, put the webcam on its top.
Put your Pi and speakers behind the mirror to hide all technical stuffs.

mirror02

At this stage, you should have a magic mirror, which is a perfect geek useless stuff. Start to impress your girlfriend, your step-mother or the pizza deliveryman.