package { import com.transmote.flar.FLARManager; import com.transmote.flar.marker.FLARMarkerEvent; import com.transmote.flar.pattern.FLARPattern; import com.transmote.flar.source.FLARCameraSource; import com.transmote.utils.time.FramerateDisplay; import exampleSupport.MarkerOutliner; import flash.display.Sprite; /** * FLARManagerTest_2D simply draws an outline around all detected markers. * * @author Eric Socolofsky * @url http://transmote.com/flar */ [SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")] public class FLARManagerExample_2D extends Sprite { private static const CAMERA_PARAMS_PATH:String = "../resources/flar/FLARparams.dat"; private static const PATTERN_PATH:String = "../resources/flar/patterns/pat16/"; private static const PATTERN_RESOLUTION:uint = 16; private var flarManager:FLARManager; private var markerOutliner:MarkerOutliner; public function FLARManagerExample_2D () { this.init(); } private function init () :void { // build list of FLARPatterns for FLARToolkit to detect var patterns:Vector. = new Vector.(); patterns.push(new FLARPattern(PATTERN_PATH+"patt002.pat", PATTERN_RESOLUTION)); patterns.push(new FLARPattern(PATTERN_PATH+"patt004.pat", PATTERN_RESOLUTION)); patterns.push(new FLARPattern(PATTERN_PATH+"patt010.pat", PATTERN_RESOLUTION)); patterns.push(new FLARPattern(PATTERN_PATH+"patt012.pat", PATTERN_RESOLUTION)); // FLARManager creates and uses a FLARCameraSource by default. // the image from the first detected camera will be used for marker detection. this.flarManager = new FLARManager(CAMERA_PARAMS_PATH, patterns); this.addChild(FLARCameraSource(this.flarManager.flarSource)); // begin listening for FLARMarkerEvents this.flarManager.addEventListener(FLARMarkerEvent.MARKER_ADDED, this.onMarkerAdded); this.flarManager.addEventListener(FLARMarkerEvent.MARKER_UPDATED, this.onMarkerUpdated); this.flarManager.addEventListener(FLARMarkerEvent.MARKER_REMOVED, this.onMarkerRemoved); var framerateDisplay:FramerateDisplay = new FramerateDisplay(); this.addChild(framerateDisplay); // MarkerOutliner is a simple class that draws an outline // around the edge of detected markers. this.markerOutliner = new MarkerOutliner(); this.markerOutliner.mouseChildren = false; this.addChild(this.markerOutliner); } private function onMarkerAdded (evt:FLARMarkerEvent) :void { //trace("["+evt.marker.patternId+"] added"); this.markerOutliner.drawOutline(evt.marker, this.flarManager.flarSource.downsampleRatio, 8, this.getColorByPatternId(evt.marker.patternId)); } private function onMarkerUpdated (evt:FLARMarkerEvent) :void { //trace("["+evt.marker.patternId+"] updated"); this.markerOutliner.drawOutline(evt.marker, this.flarManager.flarSource.downsampleRatio, 1, this.getColorByPatternId(evt.marker.patternId)); } private function onMarkerRemoved (evt:FLARMarkerEvent) :void { //trace("["+evt.marker.patternId+"] removed"); this.markerOutliner.drawOutline(evt.marker, this.flarManager.flarSource.downsampleRatio, 4, this.getColorByPatternId(evt.marker.patternId)); } private function getColorByPatternId (patternId:int) :Number { switch (patternId) { case 0: return 0x47b200; case 1: return 0x990000; case 2: return 0xFF7F00; case 3: return 0xF2F2B2; default: return 0x666666; } } } }