Simple Flash Video By The Pixel

package
{
	import flash.display.Sprite;
	import flash.media.Camera;
	import flash.media.Video;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.utils.ByteArray;
  	import flash.events.Event;
	import flash.utils.Timer;
	import flash.events.TimerEvent;

	public class VideoProcessing extends Sprite
	{
		// Camera
        private var camera:Camera;

        // My Video
        private var videoOut:Video; 

		// My Bitmapdata
		private var bmpd:BitmapData;

		// Bitmap
		private var bmp:Bitmap;

		private var timer:Timer;

        public function VideoProcessing()
        {
			trace("Starting");

			// Setup the camera
			camera = Camera.getCamera(); 

			// Video components
			videoOut = new Video();

			// Set positions
			videoOut.x = 0;
			videoOut.y = 0;

			// Attach camera to our video
            videoOut.attachCamera(camera);
			addChild(videoOut);

			// Create the bitmapdata object
        	bmpd = new BitmapData(320,240);

       		// Create the bitmap image
			bmp = new Bitmap(bmpd);

	       	// Add it to the stage
	       	bmp.x = 0;
    	   	bmp.y = 240;
       		addChild(bmp);			

			// Create timer
			timer = new Timer(10,0);
			timer.addEventListener(TimerEvent.TIMER, grabFrame);
			timer.start();

			trace("done starting");

		} 

        private function grabFrame(e:TimerEvent):void
        {
			//trace("timer");

			// Save the frame to the bitmapdata object
			bmpd.draw(videoOut);

			// Modify the bmpd
			//http://itp.nyu.edu/~dbo3/cgi-bin/ClassWiki.cgi?ICMVideo#removeStillBg
    		for (var row:int=0; row<bmpd.height; row=row+1) { //for each row
    			for(var col:int=0; col<bmpd.width; col=col+1) { //for each column
			      	//get the color of this pixels
      				var pix:uint = bmpd.getPixel(col,row);

					var red:int = pix >> 16;
					var green:int = pix >> 8 & 0xff;
					var blue:int = pix & 0xff

					if (red > 50 && green > 50 && blue > 50)
					{
						bmpd.setPixel(col,row,0);
				    }
				}
			}

        }
	}
}
This entry was posted in thoughts and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>