Color tracking
In the blob tracking example, you've learned a basic brightness tracking algorithm. In this recipe, we'll up the ante and write an algorithm to track colored pixels. This technique will be useful if you want to create an installation that more than one person can interact with. For instance, you can give each participant a brightly colored ball they can use to wave at the camera to control something on the screen.
How to do it...
The code for this example is similar to the blob tracking sketch from the previous recipe. The only difference is that we need a color
variable named trackColor
that we'll use to track, and three integer variables, each for its red, green, and blue values. The threshold variable is gone, and we use an integer variable named maxColorDifference
, instead.
import processing.video.*; Capture webcam; color trackColor; int trackR; int trackG; int trackB; int topLeftX; int topLeftY; int bottomRightX; int bottomRightY; int maxColorDifference; ...