THESVEN

creator of stuffs for the interwebs

I have been playing around with the FLARToolkit for a week or so now trying to figure out the best settings and detection methods to work with a few .DAE models (you can see my first FLAR experiment a few post back). While I have been picking through the soucre code the FLARMultipleMarkerDetector class kept catching my eye. Through all of my test projects so far I have only been using single markers to detect and display an object. It would be great to be able to detect multiple markers in one project and display different models based upon the marker, so I decided to take a further look into this class. At first glance this class does not look much different then the FLARSingleMarkerDetector that I have been using so far, except for three things. Rather than passing through a single variable for the FLARCode parameter, you must pass through an array containing all of the markers that you wish to use. This is the same for the size parameter, and the order of the array must match up with the corresponding FLARCode object in the markers array. There is one additional paramter that must be passed into the FLARMultipleMarkerDetector constructor that is not needed in the SingleMarkerDetector, and that is the total amount of markers you will be trying to track. Below is an example of the code used to set up a FLARMultipleMarkerDetector.

[Embed(source="/pattern1.pat", mimeType="application/octet-stream")]
private  var   Pattern:Class;
[Embed(source="/pattern2.pat", mimeType="application/octet-stream")]
private  var   Pattern2:Class;
 
fpattern = new FLARCode(16, 16);
fpattern.loadARPatt(new Pattern());
 
fpattern2 = new FLARCode(16, 16);
fpattern2.loadARPat(new Pattern2());
 
patternArray = [fpattern, fpattern2];
 
patternSizeArray = [80, 80];
 
detector = new FLARMultipleMarkerDetector(cameraParams, patternArray, patternSizeArray, amountOfPatterns);

Since there is going to be multiple markers being tracked, a new FLARBaseNode must be added to your papervision scene for each marker. Then the objects that you wish to display will need to be added to their respective containers. You can do this simply by creating a for loop based upon the length of the array being used to hold all of your patterns. Also take note that each marker will be returning its own FLARTransMatResult, so an array will be need to store this information into and pass the information on to the FLARBaseNoes. Due to the multiple containers and markers the loop function which is used to track the markers must be altered to accommodate the FLARMultipleMarkerDetector. Below is a sample peice of code showing how to detect the makers using the FLARMultipleMarkerDetector.

private function loop(e:Event):void{
 
            try{
 
                bmd.draw(vid);
 
                var numDetectedMarkers:int = detector.detectMarkerLite(raster, 80);
                var markerId:int;
                for(var i:int = 0; i  0.4){
                        //figure out which marker we're looking at
                        markerId = detector.getARCodeIndex(i);
                        detector.getTransmationMatrix(i, transMats[markerId]);
                    }
 
                }
 
                //apply the transform matricies to the basenodes
                for(var j:Number = 0; j < baseNodes.length; j++){
                    baseNodes[j].setTransformMatrix(transMats[j]);
                    r.renderScene(s, c, v);
                    trace('set trans mat for ...', baseNodes[j]);
                }
 
            }
            catch(e:Error){}
}