Hardware Reference
In-Depth Information
Once you have the closest match,
the nested for loops are over. All that
remains in the draw() method is to see
whether the closest match is less than
the threshold you set as an acceptable
match. If it is, draw a circle there.
8
Continued from previous page.
// Only consider the color found if its color distance is less than
// the color threshold. For greater color accuracy, make this lower.
// For more forgiving matching, make it higher:
if (closestMatch < colorThreshold) {
// Draw a circle at the tracked pixel
fill(trackColor);
strokeWeight(2.0);
stroke(0);
ellipse(closestX, closestY, 16, 16);
}
}
Now, add a handler for when the
mouse is pressed. This changes
the tracked color to whatever color is
at the mouse location.
8
void mousePressed() {
// Save color where the mouse is clicked in trackColor variable
int loc = mouseX + mouseY*opencv.width;
trackColor = pixelArray[loc];
}
Lighting for Color Tracking
As you can see when you run this sketch, it's not the most
robust color tracker! The closest match tends to jump
around a lot. Changing the color-
Threshold helps, but not a lot. You can get it to be more
precise by controlling the image and the lighting very
carefully. There are some lighting tricks you can use as
well:
• Regular LEDs don't work well as color-tracking objects
unless they're relatively dim. Brighter LEDs tend to show
up as white in a camera image because their brightness
overwhelms the camera's sensor.
• Color recognition doesn't have to be done with a
camera; color sensors can do the same job. Texas
Advanced Optoelectronic Solutions (www.taosinc.com)
makes a few different color sensors, including the TAOS
TCS230. This sensor contains four photodiodes, three
of which are covered with color filters; the fourth is not,
so it can read red, green, blue, and white light. It outputs
the intensity of all four channels as a changing pulse
width. The cheaper TAOS TSL230R has no LEDs—it
just detects ambient color. Other color sensors are
available as well. Their shortcoming is that they are
designed to detect color only relatively close (within a
few centimeters), and they don't have the ability to see
a coherent image. They are basically one-pixel camera
sensors.
• DayGlo colors under ultraviolet fluorescent lighting tend
to be the easiest to track, but they lock you into a very
specific visual aesthetic.
• Objects that produce their own light are easier to track,
especially if you put a filter on the camera to block
out stray light. A black piece of 35mm film negative (if
you can still find 35mm film!) works well as a visible
light filter, blocking most everything but infrared light.
Two polarizers, placed so that their polarizing axes are
perpendicular, are also effective. Infrared LEDs track
very well through this kind of filter, as do incandescent
flashlight lamps.
 
Search WWH ::




Custom Search