Вы находитесь на странице: 1из 2

/** * Outline WebCam Image Processing * @author Brandon Fogerty * @version 0.

1 * * This example demonstrates how to play * with pixel data with Flash and Action Script 3.0 using * the webcam. * * May GOD Bless you Always! */ package { import import import import import import import import import flash.display.Bitmap; flash.display.BitmapData; flash.display.MovieClip; flash.geom.Point; flash.geom.Rectangle; flash.media.Camera; flash.media.Video; flash.utils.Timer; flash.events.TimerEvent;

public class WebCam extends MovieClip{ private private private private private var var var var var time:Timer; camInput:Camera; video:Video; tmpBmp:Bitmap = null; bmp:Bitmap;

public function WebCam() { // Get access to the camera. camInput = Camera.getCamera(); // Create a video object to contain the camera input. if(camInput != null) { video = new Video(camInput.width * 2, camInput.h eight * 2); video.attachCamera(camInput); bmp = new Bitmap(new BitmapData(camInput.width * 2, camInput.height * 2,false,0x000000)); addChild(bmp); // Create a timer that will continue to update o ur pixel data via // the "step" function. time = new Timer(20); time.addEventListener(TimerEvent.TIMER,step); time.start(); } } public function step(timeEvent:TimerEvent):void { // get the bitmap data from the current video image. var picData:BitmapData = new BitmapData(camInput.width*2

,camInput.height*2); picData.draw(video); // Remove the last bitmap that we put on the stage. if(tmpBmp != null) { //removeChild(tmpBmp); } // Create a new bitmap from the bitmap data. tmpBmp = new Bitmap(picData); for(var j:Number=0; j < bmp.height; j++) { for(var i:Number=0; i<bmp.width; i++) { // Get the red pixel color var iPixel:Number = tmpBmp.bitmapData.ge tPixel(i,j); var r:Number = iPixel >> 16; // if the red intensity is pretty higher , make it white. // Make the image monochrome as well. // Take out this conditional statement t o make a gray scale image. if(r < 120) { r = 0; } else { r = 255; } // Convert the image into a monochrome i mage. iPixel = r << 16 | r << 8 | r; bmp.bitmapData.setPixel32(i,j, iPixel); } } } } }

Вам также может понравиться