動体検知からの・・・forked from 動体検知
// forked from ll_koba_ll's 動体検知
// write as3 code here..
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.media.Camera;
import flash.media.Video;
[SWF(frameRate="15", backgroundColor="#000000")]
public class MotionCamera extends Sprite
{
private var camera:Camera;
private var video:Video;
private var button:Sprite;
private var bmd:BitmapData;
private var now:BitmapData;
private var before:BitmapData;
private var rect:Rectangle;
private var pt:Point;
public function MotionCamera()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
camera = Camera.getCamera();
if (camera != null)
{
setupCamera();
}
bmd = new BitmapData(camera.width*2, camera.height*2 ,false,0xffffff);
var bmp:DisplayObject = addChild(new Bitmap(bmd));
bmp.scaleX = 1.5;
bmp.scaleY = 1.5;
addEventListener(Event.ENTER_FRAME, loop);
now = new BitmapData(camera.width*2, camera.height*2);
before = new BitmapData(camera.width*2, camera.height*2);
rect = new Rectangle(0, 0, camera.width*2, camera.height*2);
pt = new Point(0, 0);
}
private function setupCamera():void
{
video = new Video(camera.width*2, camera.height*2);
video.attachCamera(camera);
//addChild(video);
}
private function loop(e:Event):void
{
now.draw(video);
//now.draw(before, new Matrix(), new ColorTransform(), BlendMode.DIFFERENCE);
var ret:uint = now.threshold(now, rect, pt, ">", 0xff111111, 0xffffffff);
before.draw(video);
bmd.draw(now);
}
}
}