FLASH 8 : threshold() >> Motion detection... - jeanphiBlog
http://jeanphiblog.media-box.net/dotclear/index.php?2005/10/16/163-flash-8-threshold-motion-detection
参考にしてつくってみた。
なんでこんなことしてるかは今んとこ秘密w
ActionScript3.0 Motion 01 動体検知っぽいなにか
http://labs.un-q.net/as3/camera/motion/01/
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.media.Camera;
import flash.media.Video;
public class MotionTest02 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 MotionTest02() {
init();
}
private function init():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.x = camera.width*2 + 10;
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);
now.threshold(now, rect, pt, ">", 0xff111111, 0xffffffff);
before.draw(video);
bmd.draw(now);
}
}
}



