Skip to content

Adding a Filter to Video (Actionscript)

November 17, 2009

I’ll got through making a filter and applying it to a video displaying your Webcam. In this case I tried using the ColorMatrixFilter and just turned up the saturation. On the left is the regular camera feed, on the right is the filtered camera feed.

Here’s the Actionscript:

</pre>
package filterCamCode{
import flash.display.MovieClip;
import flash.media.Camera;
import flash.media.Video;
import flash.filters.ColorMatrixFilter;

public class FilterCam extends MovieClip {

private var cam:Camera;
private var vid:Video;
private var vid2:Video;
private var vid3:Video;
private var cm:ColorMatrixFilter;
private var matrix:Array;

public function FilterCam() {
cam=Camera.getCamera();
trace("cam width = "+cam.width);
trace("cam height = "+cam.height);
vid=new Video();
//vid.scaleX=-1;
//vid.x+=vid.width;
vid.attachCamera(cam);
addChild(vid);

vid2=new Video();
//vid2.scaleX=-1;
//vid2.x= stage.stageWidth
vid2.x=(stage.stageWidth/2)
vid2.attachCamera(cam);
addChild(vid2);

var boost:Number = 2; //multiplys the saturation of each colour channel
var brightness:Number = -50; //offsets the final value of each colour channel
matrix= new Array(); //each row is source pixel's red, green, blue, alpha, and offset
matrix= matrix.concat([boost, 0, 0, 0, brightness]); // red
matrix= matrix.concat([0, boost, 0, 0, brightness]); // green
matrix= matrix.concat([0, 0, boost, 0, brightness]); // blue
matrix= matrix.concat([0, 0, 0, boost, brightness]); // alpha

cm= new ColorMatrixFilter(matrix);
vid2.filters = [cm];

}//ExpCamera

}//class
}//package

Advertisements
One Comment leave one →
  1. sajil permalink
    September 18, 2011 06:34

    great post..thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: