Packagecc.cote.chromatracker
Classpublic class ChromaTracker
InheritanceChromaTracker Inheritance Object

The ChromaTracker class allows the detection of a specific color or range of colors in any DisplayObject. It is particularly useful to track blobs of color in a live video feed (from a camera). This class provides methods to retrieve view the detected pixels as a normal Bitmap object or a rectangle representing the outer boudary of detected pixels.

This class is still in beta. Fell free to suggest improvements or corrections on the project's home page.

See also

ChromaTracker's Home Page


Public Properties
 PropertyDefined By
  bitmap : Bitmap
[read-only] A Bitmap object of the currently detected pixels to easily visualize the result
ChromaTracker
  blur : Number
A Number between 0 and 1 representing the amount of blur applied
ChromaTracker
  brightness : Number
A Number between -1 and 1 representing the brightness correction
ChromaTracker
  center : Point
[read-only] A Point object representing the center of the detected rectangular zone
ChromaTracker
  color : uint
A uint representing the color set for detection
ChromaTracker
  contrast : Number
A Number between -1 and 1 representing the contrast correction
ChromaTracker
  hue : Number
A Number between -1 and 1 representing the hue correction
ChromaTracker
  rect : Rectangle
[read-only] A Rectangle object representing the outer rectangular boundary of detected pixels
ChromaTracker
  saturation : Number
A Number between -1 and 1 representing the saturation correction
ChromaTracker
  tolerance : Number
A Number between 0 and 1 representing the color tolerance
ChromaTracker
Public Methods
 MethodDefined By
  
ChromaTracker(source:DisplayObject, color:uint = 0x000000, tolerance:Number = 0.2, blur:Number = 0.2, brightness:Number = 0, contrast:Number = 0, saturation:Number = 0, hue:Number = 0)
Creates a ChromaTracker object.
ChromaTracker
  
track():Rectangle
Executes color detection and returns a rectangle that represents the outer boundary of detected pixels.
ChromaTracker
Property Detail
bitmapproperty
bitmap:Bitmap  [read-only]

A Bitmap object of the currently detected pixels to easily visualize the result


Implementation
    public function get bitmap():Bitmap
blurproperty 
blur:Number

A Number between 0 and 1 representing the amount of blur applied


Implementation
    public function get blur():Number
    public function set blur(value:Number):void
brightnessproperty 
brightness:Number

A Number between -1 and 1 representing the brightness correction


Implementation
    public function get brightness():Number
    public function set brightness(value:Number):void
centerproperty 
center:Point  [read-only]

A Point object representing the center of the detected rectangular zone


Implementation
    public function get center():Point
colorproperty 
color:uint

A uint representing the color set for detection


Implementation
    public function get color():uint
    public function set color(value:uint):void
contrastproperty 
contrast:Number

A Number between -1 and 1 representing the contrast correction


Implementation
    public function get contrast():Number
    public function set contrast(value:Number):void
hueproperty 
hue:Number

A Number between -1 and 1 representing the hue correction


Implementation
    public function get hue():Number
    public function set hue(value:Number):void
rectproperty 
rect:Rectangle  [read-only]

A Rectangle object representing the outer rectangular boundary of detected pixels


Implementation
    public function get rect():Rectangle
saturationproperty 
saturation:Number

A Number between -1 and 1 representing the saturation correction


Implementation
    public function get saturation():Number
    public function set saturation(value:Number):void
toleranceproperty 
tolerance:Number

A Number between 0 and 1 representing the color tolerance


Implementation
    public function get tolerance():Number
    public function set tolerance(value:Number):void
Constructor Detail
ChromaTracker()Constructor
public function ChromaTracker(source:DisplayObject, color:uint = 0x000000, tolerance:Number = 0.2, blur:Number = 0.2, brightness:Number = 0, contrast:Number = 0, saturation:Number = 0, hue:Number = 0)

Creates a ChromaTracker object. By default, a small amount (0.2) of tolerance and blur is used. The blur is particularly useful to get rid of stray single pixels. Please note that lighting conditions must be controlled to achieve a reliable detection.

Parameters
source:DisplayObject — DisplayObject upon which to perform color detection (MovieClip, Video, Bitmap, etc.)
 
color:uint (default = 0x000000) — Color to detect (24bit unsigned int)
 
tolerance:Number (default = 0.2) — Tolerance to apply to the red, green and blue channels to match a larger range of colors (between 0 and 1)
 
blur:Number (default = 0.2) — Amount of blur to apply (between 0 and 1)
 
brightness:Number (default = 0) — Brightness adjustement (between -1 and 1)
 
contrast:Number (default = 0) — Contrast adjustement (between -1 and 1)
 
saturation:Number (default = 0) — Saturation adjustement (between -1 and 1)
 
hue:Number (default = 0) — Hue adjustement (between -1 and 1)
Method Detail
track()method
public function track():Rectangle

Executes color detection and returns a rectangle that represents the outer boundary of detected pixels. This method takes into account color and matrix transformations that may have been applied to the DisplayObject as well as blend modes. The execution of this method also updates the 'bitmap', 'rect' and 'center' properties.

Returns
Rectangle — A Rectangle object representing the rectangular outer boundary of detected pixels