This project was intended to provide a simple wrapper for the ARToolKit. To use its functionalities also in other programming languages (like in our case Python), than only C. I get the video-frames from wherever I want and overlay the video-frame with whatever I want (mainly VTK). So you are no more bound to capture your video-frames with ARToolkit, and use C and OpenGL for the visualization.
Download the ARToolkit from http://www.hitl.washington.edu/artoolkit/download and compile it, I would recommend the latest version 2.72.1 and a compilation with GStreamer (possibly the easiest way).
I recommend the usage of GStreamer, I use it in all examples to grab frames from the webcam, and it is easy to configure. Have a look at the Python-GSreamer Tutorial by Jens Persson for further information: http://pygstdocs.berlios.de/pygst-tutorial/index.html
To be able to compile ARToolkit-ICE you will need to generate the interface for the target-language with SWIG.
And of course, you need AR-ICE (the ARToolKit-InterfaCE or ARToolKit is Complicated Enough), which can be downloaded under: http://sourceforge.net/projects/ar-ice
Compilation: Default target language is Python
There are only two things you have to take into account if you want to compile the ARToolkit-Interface:
- Open the Makefile and change the path to the ARToolkit installation, that means change variable ARTOOLKIT.
- Check the other include directories under INC_DIR and of course you need the Python header files, so check INC_PYTHON, maybe you have Python2.7. I also checked the compilation with Python3.0, but if you are using pyVTK you will get in trouble, currently there is no pyVTK support for Python3.0.
That was all, just type in make an run the compilation.
Running the examples (Python)
First of all, go to examples/Data and print out the marker “pattSample1.pdf”. And afterwards try the examples under examples/Python.
Now, there are only a few lines of code you require to have the ARToolkit-functionality in you Python-script:
# Of course, import the module import artoolkit as ar # Set the camera-parameter and image-size ar.VideoParameter("camera_para.dat", 640, 480) # generate a new marker, or simply if you just use standard-markers # pattern = ar.MakePattern(".patt.sample1") pattern = ar.MakePattern("patt.sample1",80,0,0) # load the pattern to artoolkit with ar.LoadPattern(pattern) # thats all, we can now search for markers in the video-frames (100 # is the black-white threshold in artoolkit) ... # all detected markers are stored in arMarkerInfo arMarkerInfo = ar.DetectMarker(videobuffer, 100) # to check if your registered marker was found, use: if ar.FindPattern(arMarkerInfo, pattern): # If the marker was detected, all necessary information is stored in # the variable pattern # get the ARToolkit-transformation-matrix print pattern.dTransformationMatrix # get the confidence # (-1, if the marker was not found, otherwise a value dCF 0<= dCF <=1) print pattern.dCF
Have a look at the examples in examples/Python, were the camera parameters were transformed, (a bit tricky) but I hope self-explanatory…
Additional functionality that is currently available is:
ar.glCameraView (double para, double scale = 0) ar.glCameraViewRH(double para, double scale = 0) ar.glCameraFrustum (ARParam *cparam, double focalmin, double focalmax) ar.glCameraFrustumRH(ARParam *cparam, double focalmin, double focalmax)
this functions were taken from gsub_lite, if you require additional functionality, add it to artoolkit.cpp\h and extend the definitions in artoolkit.i (swig-file).
Usage with other languages
Unfortunately there is currently only Python-Support, but if you need require an interface for another language you will have to add a new typemap (see typemaps/python.i, as an example). And include the new typemap into artoolkit.i using SWIG-defines:
#ifdef SWIG(TARGET) %include typemaps/(target).i #endif
Changing the Makefile:
- Change TARGET
- Include the addional headers (see INC_PYTHON)
- Add additional information for SWIG_FLAG and REMOVE
Thats all folks …
There are currently some minor projection problems with other camera resolutions than 640×480. Thanks for any suggestions 😉