thesven.com

ActionScript and Web Development

FLARToolkit Multiple Unique Markers

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 < numDetectedMarkers; i++){
 
                    //only use markers with a confidence rating of .5+
                    if(detector.getConfidence(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){}
}

CLICK HERE TO VIEW MY FIRST FLAR MULTIPLE MARKER TEST
** you will need to download and print the markers from HERE and HERE

If you would like to download the source files for this project you can do so from HERE

  • Share/Bookmark
Vote in HexoSearch
Tagged as , , , , , , + Categorized as AS3, AS3, FLAR, AS3, Papervision

2 Comments

  1. Hello Sven,
    great work that you did, good job!

    I have a question: How can i load .dae files into the flartoolkit with miultimarkers?How does the code look like?
    best regards from Greece

Trackbacks & Pingbacks

  1. Getting started with Augmented Reality | AVinteractive Blog

    [...] TheSven.com, has an excellent tutorial on using multiple marker in FlarToolKit, so once you have managed to complete the above tutorials, check this out to have more markers. Link [...]

Leave a Reply