This idea, like most good ones, came to me while I was in my bathroom. I recently took delivery of a Microvision SHOWWX laser pico projector, and I was trying to come up with a quick project to show the cool stuff it could do. I noticed that the light above my mirror was diffused by a large frosted glass dome, which led to this strange project. It’ll probably make more sense around Halloween.
The software is pretty similar to what I wrote the last time I did face tracking: OpenCV’s very convenient Haar feature detection along with Pygame to do the image display. I tried taking a picture of my own eye, but Flickr user Sarah Cartwright’s is much more photogenic and available under Creative Commons Attribution-Share Alike.
A regular pico projector would probably work as well, but the contrast ratio on this thing means it looks like the iris is being projected by itself. I have some much cooler projects planned that will really take advantage of the focus free nature of the laser projector. In the mean time, the code for this project is available below. The image is CC A-SA, the code is public domain, and the Haar file is Intel License Agreement like the rest of OpenCV. I also attached the Python script itself for perusal by search engines or folks who just want to see the code.
OpenCV has issues using the camera on the XO, rising from the way it negotiates color palette settings with the OV7670 v4l2 driver. I haven’t delved deep enough into v4l2 yet to come up with a proper fix for either the driver or OpenCV. However, I have a temporary fix that (probably) works fine but is very ugly.
The easy and dirty solution is to install the opencv, opencv-devel, and opencv-python packages with yum, to download the libhighgui.so.1.0.0 that I compiled, and to copy it to /usr/lib/libhighgui.so.1.0.0. In short:
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.