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.