IR Tracking Test

So I had some free time during this break (not really, but I didn't feel like doing the work I'm supposed to do.) I've been wondering for a while if we could have made the infrared (IR) stuff work, so I posed that as a challenge for myself. Turns out, it wasn't all that hard.

First thing I had to do was make a IR camera. Very easy. Initially, I just taped two pieces of photo negative to my webcam (the darkest stuff at the end of the strip.) That worked well enough to pick up the LEDs shining out of a remote control.

Then I got a little more adventurous and hacked open the webcam. That was pretty much just one screw and some careful dismantling of the rest. Right in front of the lens is a square of iridescent glass; that's the IR filter. I popped that out with a screwdriver (it kind of chipped at first until I broke away enough to pry the whole thing out.) I replaced it with two small squares of the negative and put the thing back together. Props to Cameron Browning for teaching me this trick.

The results were impressive. I picked up a crazy amount of IR light. If you flick a lighter in front of the camera, it looks like you lit a flare. If you turn out all the lights, you can use a TV remote as an IR flashlight. Super cool.

For the software, I used OpenCV. Not only is it open source, not only does it have an insane amount of features, it also works with Python! Download it immediately if you're into this stuff.

Anyway, with a bit of fiddling the examples and looking through the documentation, I was able to do the following:

  • capture from my webcam
  • threshold the image to make a black and white binary image set to where I wanted to pick up the IR light
  • find the contours of each shape
  • calculate the moments of each shape
  • use the moments to get the area, position, angle, elongation, etc. of each shape.

This is very good stuff. You can make all kinds of great things with a rig like this, including a multitouch display. More to come with that, believe me. Check my del.icio.us links for the research I'm doing on that.

The best part is that I got this done in less than a few hours of screwing around. If you're interested, be encouraged--this is very, very doable.

Attached is my python code for the tracking. Use it in good health.

Here's a video of the results so far:

AttachmentSize
mocon.py.txt6.37 KB

Copyright Mike Edwards 2006-2009. All content available under the Creative Commons Attribution ShareAlike license, unless otherwise noted.