Tracking colors: tracking laser

I have started building the programm that will be used int he final installation.
The first think to do is tracking the laser, so here is a first attempt for doing it.

The code is a mix of two other programms. One is the Laser Tag software created by Theodore Watson for the Graffiti Research Lab and the other one is a Color Tracking code created by Zach Lieberman and posted in his blog”s class Magic++.

This is what this color tracking code does:
It takes an incomming image, either from a live cam or a static picture, and converts it from RGB to HSV, which is a better color system for tracking. Then, changing the HSV values, we try to isolate the color that we want to track. Once we have located the HSV values that fit the color that we want to track, we compare each pixel and see if it is inside the HSV values that corresponds to the target color. If the pixels are between the desired ranges, we convert them to white, if not, we convert them to black. So, as a result we have a thresolded image that totally separates the target color.

Here is a video running the code:

Color and laser tracking using openframeworks from berio on Vimeo.

The HSV values can be changed by pressing some keys on the keyboard.
It is also possible to switch between and static image and a live cam as the input source by pressing key “i”.
Moreover, it is important to set up the configuration of the camera and put it in manual, as Theodore Watson explains. You can do it by pressing key “p”. We may want to put the white balance in manual, as well as the brightness, exposure, etc… For that reason we will need a camera that will let us change its configuration (built-in i-sign, for example, will not let us do it), so here is a webpage-list of hardware that we can use:
http://wiki.openframeworks.cc/index.php?title=Hardware.

I am using a firewire camera, that works in linux, osx and windows: Fire i DC

So far, I have been using a red laser <5mW, but I will switch to a green and more powerful laser, which will be easier to track, so green color is easier to isolate than red (as also happens using green screens).

Here is the code:
Color tracking OF 0.06:

Color tracking OF 0.07:

Next step will be playing with blobs sizes, and maybe with the movement of the laser, in order to separate the laser color tracking from other objects that could share the same color.
And then we will start to combine the laser tracking with the projection.