When I was researching color tracking with Flash, there were surprisingly few examples. The examples I did find did not have any source to download. So, I am offering up my source code from my color tracking experiment. The ColorIsolator class is based on an old AS2 algorithm by Mario Klingemann (Quasimondo) for selective color. I’ve translated it here to AS3 and applied it to video from the webcam.
It works like this. Once a color is selected from the video, using a seriess of thresholds, the ColorIsolator drops all pixels that don’t fall within the defined range of the target color. The remaining pixels are set to the target color and getColorBoundsRect is used to pinpoint the remaining blob of color. It’s really simple. I had the general idea, but I didn’t understand how to define a range of color until I found Klingermann’s code.
I would consider this just a starting point. It actually works very well, but there are a number of things that can be done to improve it. Here are my recommendations to try out:
- Try using HSV color values rather than RGB.
- Introduce a palleteMap in place of or in addition to the saturation/contrast ColorMatrixFilter.
- Add blob detection to ignore anomalies/artifacts of the target color.
All I ask is for constructive criticism and to let me know if and where you use this. A credit to myself and Mario in your source code comments would be nice.
Thanks to Justin Windle (soulwire) for a great exchange of ideas for this.

4 Responses
By peko on Nov 21, 2009 | Reply
Pixelblender version of HSV Threshold:
http://gasubasu.com/2009/11/21/hsv-threshold-using-pixelblender/
By theoN on Mar 2, 2010 | Reply
Update; I didn’t read the full post, but it’s funny that I’ve been looking at the exact same things as you. I basically started out with Justin Windle’s library as well, then needed color detection, tried doing it on my own but I struggled bigtime, then I came across Mario’s code as well, unfortunately in AS2 and then I bumped into this. I’m extatic lol … you just started this earlier than me. GREAT GREAT share! I’m sure if it was higher in the google rankings a lot more ppl would be posting these kind of comments
By admin on Mar 2, 2010 | Reply
Thanks! Glad you find it useful. I’ love to see what you come with. Post a link here if you don’t mind sharing later.