Face Detection on the OLPC XO

Sample Face Detection Image

Ok, here is some working code for face detection using the XO’s webcam.  It requires the opencv, opencv-python, and xawtv packages.  Xawtv can be skipped if you change it to use gstreamer instead, but gstreamer takes around 3 seconds to initialize the camera, take a picture, and save it.  Xawtv, on the other hand, takes about a half second.  The face detection algorithm, from OpenCV itself takes anywhere from 0.1 seconds to 3 seconds depending on what parameters you choose.  I chose ones that seem to work almost all of the time and take about 0.25 seconds.

Object detection is pretty fascinating stuff, and well beyond the scope of this blog post, so I’ll just refer you to this pdf.  By training and customizing Haar files, one could detect an endless possibility of objects.  Gesture detection and sign language to tex tare two of the more interesting possibilities.  If I can find image databases, I might try training a Haar filter for hand detection.

This is basically just proof of concept code attached.  I’m going to try a v4l2 python library and package something up as a usable XO activity this weekend.  To run this, just put both of the files below in the same directory and run “python face.py”.  Assuming you’re on an XO and you have opencv, opencv-python, and xawtv installed, it should pause for a second while the camera turns on and captures a picture, and then display an image with any faces enclosed by green rectangles.  It works best if most of your head is within the image frame and there is a decent amount of light.

Face detection script
The Haar cascade file that it uses

Related Posts

11 Replies to “Face Detection on the OLPC XO”

  1. Well this sounds a good idea for an OLPC laptop but i have heard about things that all such face recognition softwares have a limited amount of accuracy………
    So, what is the accuracy of the algorithm that you are using right now moreover does the algo that u are using for face recognition uses neural network so that it can keep improving its performance….

  2. The algorithm is the Haar-based one from OpenCV. It compares Haar features in an image to ones in a precomputed file that was created by training it with thousands of images of the object and many thousands more of objects that were not it. Thus, the accuracy depends entirely on the quality of the precomputed Haar data and the quality of the image face detection is being performed on.

    I’ve found it to be fairly accurate in decent lighting. With low light, theres enough sensor noise that increasing contrast isn’t enough have clear features in the image. The accuracy also depends on how much computing time you want to put into it. Longer=better. Basically, it’s accurate, unless its not accurate enough for what you’re trying to do 😉

  3. Hey Nirav,
    I am a graduate student in University of Texas – Austin (ECE). I am also interested in computer vision, image processing and pattern recognition. I saw this link while I was looking for a GSOC project. Do you have a specific project in your mind about computer vision for GSOC? Please let me know.

  4. Last time I checked, OpenCV comes with an example python script that does face recognition on a live stream. Too lazy to dig out my XO and try it just now, but did you try that before writing your own?

  5. I did. This is an old post. The last OpenCV release, the one for which there is a package in the Fedora 7 repository, is incompatible with the camera on the XO. So, the script in this post uses xawtv to capture the image and then does face detection in OpenCV.

    Since then, I’ve figured out how to patch OpenCV to work with the camera, so this script is now unnecessary (and slow).

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.