forked from: webCam
境界検出
/**
* Copyright shin-go ( http://wonderfl.net/user/shin-go )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/2lUf
*/
// forked from shin-go's webCam
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.ActivityEvent;
import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.filters.ConvolutionFilter;
import flash.geom.Point;
import flash.media.Camera;
import flash.media.Video;
import flash.text.TextField;
import net.hires.debug.Stats;
public class FlashTest extends Sprite {
protected var video:Video;
protected var bmpd:BitmapData;
protected var convolitionFilter:ConvolutionFilter;
public function FlashTest() {
// write as3 code here..
if(setCamera()){
setFilter();
}
addChild(new Stats());
}
protected function setCamera():Boolean{
var camera:Camera = Camera.getCamera();
if (camera != null) {
video = new Video(stage.stageWidth,stage.stageWidth*3/4);
video.attachCamera(camera);
camera.addEventListener(ActivityEvent.ACTIVITY, onActivity);
addChild(video);
return true;
}else {
var txt:TextField = addChild(new TextField()) as TextField;
txt.text = "No Camera!";
return false;
}
}
protected function onActivity(e:ActivityEvent):void {
if (e.activating == true) {
}
}
protected function setFilter():void {
if (!bmpd) bmpd = new BitmapData(video.width, video.height, false, 0x000000);
var bmp:Bitmap = addChild(new Bitmap(bmpd)) as Bitmap;
bmp.width = bmpd.width / 3;
bmp.height = bmpd.height / 3;
bmp.x = stage.stageWidth - bmp.width;
bmpd.draw(video);
var edges:Array = [0, -1, 0,
-1, 4, -1,
0, -1, 0];
convolitionFilter = new ConvolutionFilter(3, 3, edges, 1);
bmp.filters = [convolitionFilter];
addEventListener(Event.ENTER_FRAME, onEnter);
}
protected function onEnter(e:Event):void {
bmpd.draw(video);
//bmpd.applyFilter(bmpd,bmpd.rect, new Point(), convolitionFilter);
}
}
}