thesven.com

ActionScript and Web Development

FLARToolkit Alchemy Branch

Click Here to see an example of FLARToolkit Alchemy.
You will need to download and print this marker

For the past few weeks I have been working on a FLARToolkit project in the office for one of our clients. While working with augmented reality in flash up to this point has been great, I have always felt that there was a bit of speed hit involved with the actual image processing to locate the marker. Through a combination of hacks and tricks I was able to deal with the slow image processing and get a few projects up and running with a consistent speed of 31fps. Thanks to a recent tweet from Mikko, I was made aware that there was an alchemy version of the FLARToolkit in the works. I am hoping that with this new toolkit that we will be able to squeeze a bit more speed out of flash to provide the user with a smoother experience.

I started to do some digging around the net to see if I could find any information of this new branch of the toolkit. As it turned out I was able to come across very little, if any information as of yet. But I did manage to find the source code with in the libspark public svn and checked out a copy to start playing around with.

Working with the alchemy branch of the FLARToolkit you will notice a few differences right away:

First of all because we are using a set of classes made with adobe alchemy we will be accessing everything through a .swc file (I am not extremely familiar with adobe alchemy at this point in time, but I think this is the only way that the files can be used). For those that do not know, Alchemy is an adobe labs project that allows C++ to be complied for use in the AVM2 action script virtual machine. For a better explanation, and much more information on alchemy check out the adobe labs site.

A lot of the familiar FLARToolkit classes have had their names slightly modified. I found this a bit confusing at first as over the past few weeks I have been getting used to the package structure and class names of FLARToolkit. After picking around the swc for a while in FDT, It was easy enough to find what I was looking for. Below is an example of the package/class name changes I came across while making my first cube demo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//FLARToolkit Alchemy
import org.libspark.flartoolkit.core.FLARCode;
import org.libspark.flartoolkit.core.FLARParam;
import org.libspark.flartoolkit.core.FLARRgbRaster;
import org.libspark.flartoolkit.core.FLARTransMatResult;
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
import org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
import org.libspark.flartoolkit.support.pv3d.FLARMarkerNode;
 
//FLARToolkit
import org.libspark.flartoolkit.core.FLARCode;
import org.libspark.flartoolkit.core.param.FLARParam;
import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
import org.libspark.flartoolkit.pv3d.FLARCamera3D;
import org.libspark.flartoolkit.pv3d.FLARBaseNode;

Not all of the FLARToolkit classes seem to be available. I know that this project is still a work in progress and when I messaged Saqoosha about this, he said he was still testing the code that was available from the svn. I’m not sure if the multiple marker detector is coming in the future, but for know I am more then happy with what is available.

The way in which some of the classes are used in the alchemy version of FLARToolkit have been altered slightly from the original as3 version. I am pretty sure this is because of the way the classes needed to be structured while being written in c++. These are a few of the differences that I ran into while making my first cube demo.

1
2
3
4
5
//this can be used instead of _cameraParams.loadARParamFile();
_cameraParams = FLARParam.getDefaultParam(WIDTH * 0.5, HEIGHT * 0.5);
 
//you need to set the bitmap data to the raster each loop
_raster.setBitmapData(_bmd);

Other than the few changes mentioned above, the process for setup and marker detection seems to have remained fairly unchanged. I did notice one other thing though, and I am not too sure what is causing it. When I first setup my marker tracking as I normally do by drawing the video to a bitmap data object, the tracking would work, but everything seemed to be very offset from the center of the marker. I played around with this for a bit and found that if I scaled down the video by 50% while drawing it to my bitmap data, that everything would work correctly. As I said above I am not too sure what is causing this, but if you download my example and figure it out or if you know why this may be happening please let me know.

Over all I have been very impressed with the results of this new branch so far. I have had the cube demo running in and around 50fps on my mac book pro, which is a great improvement over anything I have done so far with the FLARToolkit. I can’t wait to try out some new ideas with this code. I would like to say thanks to Saqoosha and Nyatla for all of their hard work on FLARToolkit and FLARToolkit Alchemy. With out them no one would be doing this stuff in flash right now.

Click Here to download the source code for the cube demo

  • Share/Bookmark
Vote in HexoSearch
Tagged as , , , , , , , , , , + Categorized as AS3, AS3, Alchemy, AS3, Code Librarys, AS3, FLAR, AS3, Flash, AS3, Papervision

14 Comments

  1. this is great. thanks for poking around in the alchemy branch and posting your results — i’m definitely gonna have to give this a shot after hearing about the success you’ve been having!

  2. Came across your post and had a few issues. First of, thanks for taking the time to talk about migrating over to the Alchemy Branch it was a big time saver. Now the bad news, I was unable to get you source code to work. It compiled but I get the following error once it runs:

    RangeError: Error #1506: The specified range is invalid.
    at cmodule.nyartoolkit::FSM__start/work()
    at cmodule.nyartoolkit::CRunner/work()
    at cmodule.nyartoolkit::CLibInit/init()
    at jp.nyatla.nyartoolkit.as3::NyARToolkitAS3$cinit()
    at global$init()[/Users/hiko/Documents/Frameworks/FLARToolKit/branches/alchemy/src/jp/nyatla/nyartoolkit/as3/NyARToolkitAS3.as:30]
    at jp.nyatla.nyartoolkit.as3::NyARParam()[/Users/hiko/Documents/Frameworks/FLARToolKit/branches/alchemy/src/jp/nyatla/nyartoolkit/as3/NyARParam.as:46]
    at org.libspark.flartoolkit.core::FLARParam()[/Users/hiko/Documents/Frameworks/FLARToolKit/branches/alchemy/src/org/libspark/flartoolkit/core/FLARParam.as:48]
    at org.libspark.flartoolkit.core::FLARParam$/getDefaultParam()[/Users/hiko/Documents/Frameworks/FLARToolKit/branches/alchemy/src/org/libspark/flartoolkit/core/FLARParam.as:55]
    at com.thesven.flaralchemy::Main/codeReady()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    That being said, including the SWC for the FLARToolKit saved me another headache. I haven’t been unable to compile my own swc from the Alchemy branch due to an error in the NyARToolkitAS3 where it cannot find cmodule.nyartoolkit.CLibInit. I was wondering how you got around that issue?

    Thanks again for the post,
    Jesse

  3. Hi Jesse,

    I have tried to compile my own swc a few times and have been unsuccessful as well. I am not sure if this is just because it is my first time playing around with alchemy and i’m doing something wrong, or if there is something required to properly compile that is not included on the svn. The swc that I am currently using can be found on the svn in the starter kit folder, there are a few examples in there as well but I have only been able to compile one of them so far.

    I played around with the code for a bit and can’t seem to replicate this error. But from looking at the error message it seems that it is coming from the call on line 84,
    _cameraParams = FLARParam.getDefaultParam(WIDTH * 0.5, HEIGHT * 0.5);.
    Im not sure if this would change anything but have you tried loading a .dat file instead of calling the default param method? Also how are you compiling? I am using FDT with the Flash CS4 FP10 library

  4. Thanks for the heads up. I am using FDT but like an idiot I was using their launcher to preview the swf so I wasn’t able to check my connections. Will try it out later tonight and get back to you.

  5. This is awesome!!. I’ve tried and the speed boost is amazing!

    I wonder if this is ready for production deployment?. It seems pretty stable to me.

  6. Hi, nice job! I’ve just added some support for Away3Dlite as well, you can check it out at:

    http://www.gerbster.nl/2010/02/the-need-for-speed-flar-alchemy-away3dlite/

  7. Hi ! im trying to use alchemy with DAE class but when i try to compile alchemy using some var with this type im getting a black window.

    Also this is happening with the earth.fla that comes with the starter kit !

    Any reply about this issue ! Thanks !

  8. Thanks for posting this! You’ll get an ever so slightly better FPS if you create your scaleMatrix in your init method and reuse it instead of creating a new one on each renderTick.

  9. Thanks for this post, it’s very helpful! I managed to put together the Alchemy port with Away3D and it works just fine!

Trackbacks & Pingbacks

  1. Twitted by zouloux

    [...] This post was Twitted by zouloux [...]

  2. Hebiflux » Réalité augmentée en Silverlight 4 : ca c’est fait

    [...] pour monter à un 50-60 fps sur un dual Core. J’avoue ne pas avoir regardé les performances d’un Flartoolkit + Alchemy sous flash, je serais curieux de comparer. C’est encore un peu expérimental, le code [...]

  3. uberVU - social comments

    Social comments and analytics for this post…

    This post was mentioned on Twitter by TheFlashBum: I am trying to wrap my head around the Alchemy branch of the FLARToolKit. Was sent this http://thesven.com/?p=126 to help me out. #NoSleep…

  4. Moment 77 » Alchemy and FLARManager

    [...] you want to track one marker it’s not the fastest. The fastest tracker I’ve seen is the Alchemy branch of [...]

  5. FLARToolkit Alchemy | CouldHll's Blog

    [...] http://thesven.com/?p=126 [Translate] Read More [...]

Leave a Reply