Attention: Old PyARTK module is obsolete for a long time. Now the new ARTKBlender module is available. It works on current version of Blender and provides similar functionality as old one.

PyARTK is Python wrapper for ARToolKit. I used it to integrate ARToolKit with Blender Game Engine.

Sources

There are actual sources of wrapper. I have downloaded version 0.1 from its home page and modified sources to use module NumPy instead of older module Numeric.  Wrapper uses SWIG to generate Python interfaces.
To build PyARTK module it’s necessary to have installed:

  • ARToolKit
  • SWIG
  • NumPy

Binaries

To make it easier to use this wrapper, I have built binaries for Windows. They are built for Python 2.5.x using VisualStudio 2003. As long as actual version of Blender (2.49a) is built with Python 2.6, I prepared binaries for it, too.
To install you have to unpack them and store folder PyARTK in path listed in PYTHONPATH environment variable. It’s required to have NumPy module installed.
ARToolKit installation is recommended, because it contains lots of tools and resources.

Examples and demos

GameBlender – ARToolKit demo contains camera tracking in GameBlender’s virtual scene.

Demo zip content

Demo contains main file artkdemo.blend and video file artkdemo.avi with live video footage. In Data folder there are files needed for ARToolKit: camera parameters file, marker pattern file and marker picture (to use this demo with your own video files or webcams). I have picked this marker from PatternMaker set.

Demo requires Texture Plug-in to be available for video replay.

Description

artkdemo.blend file contains virtual scene setup (little man, some spheres and invisible table and ground mesh), camera with parented video backplane and three important scripts for initialization and pattern detection.

Scripts are designed to allow multiple patterns handling. Initialization script init.py is bound to backplane. It initializes PyARTK modules and loads video frames to backplane texture from source defined in backplane property.

Every blender object can define ARToolKit pattern which will control its position and orientation. It must call script initPatt.py to be registered for pattern detection. Properties of object define filename of pattern, its size (in Blender units), position of center in pattern, flag to indicate if object should behave like camera or not, and properties for pattern detection.

Script detect.py load video frame from source, displays it on backplane, detects paterns and matches them to registered objects. Then for every matched object calculates its position and orientation.

There is also different simple scene setup in layer 11, which I used to test pattern detection on one object with webcam. This setup contains initialization for camera not driven by ARTK – positions of objects are calculated relatively to camera position.

One warning: GameBlender and numpy don’t like each other – when game is started for the second time, numpy doens’t work correctly. So it’s necessary to restart Blender after game is stopped.

I hope you’ll enjoy this demo and it’ll inspire you to get into AR world.

38 thoughts on “PyARTK in Blender Game Engine

  1. Nice work!
    but I would liked it better if it would have worked for me.
    I installed everything you said but the character and the balls don’t show in the video.
    I have Blender 2.48a.
    pleasse help.

    1. Hi, Eric,

      is anything written in Blender’s console? Is video showing during play? Have you started .blend file by double-click, or opened from Blender?

  2. Nothing was written except the usual “Blender Game Engine Started” etc.

    but after that I’ve tried it on another computer with python 2.5.2 installed(the first one have python 2.5.4) and it worked awesome.
    so I think you should write somewhere that you can only use this with python 2.5.2

    PS: any plans to make this work with a web cam?

  3. Hi, Eric,

    it already works with the webcam. Try to switch in demo to layer 11 – there is simple setup working with webcam. In fact, all you need is to set backplane property “source” to value “cam”.

  4. Wow! this is great if I would have a better camera I would play with it but still this is so cool!

    and it’s so small, maybe it should be integrated into blender.

  5. pls help…
    python script error from controller “cont#contr#1”
    trace somethin…
    detect.py line 45 (module)
    ‘module’ object has no attribute ‘source’
    etc…
    sorry for the mistakles i looked and typed what i remember….pls help

  6. wassem,

    sorry, I have accidentaly set video source to webcam in the last update of demo file. Now I set it back to artkdemo.avi, so it should work correctly.

  7. sorry ashsid,but the problem still exists… i think you did not upload your uodated file to your website… if your webhost takes much time to update, then could you tell what the code is to be changed at the line 45 of detect.py…

    Also there is one more error
    init.py line 11
    source output pin failed to render..

    thx,
    waseem

  8. wassem,

    I just checked the demo, it should be correct. To reapir this error, just select backplane object, go to its game properties and set source to ‘artkdemo.avi’ (or full path to video file). Then it should work.

  9. i checked the source, its “artkdemo.avi”…then also the error exists…

    i have
    blender 2.48
    python 2.5.2
    pyartk
    video text plugin
    numpy

    do you knw about logmein… i can let you control my pc so you can do it for me and i could watch it and learn…

  10. hello??? why are’nt you replyin for my post above… should i install artoolkit but i do not have visual c++, i have visual basic 2008 express

    thx,
    waseem

  11. waseem,

    sorry, I overlooked your previous message. I looks like problem in your DirectShow components. Do you have proper codec, can you replay video in media player? Try to install ffdshow and check if it start to work…

  12. thx, thx, thx…. a million thx to you…
    for making this, for helping me…. your video tex plugin(i am goin to try this for realtime reflection)

  13. could you explain the installation steps to a non programming user like me. i’ve downloaded all the files but i dont know how to put them together.

    i already install python 2.6 and NumPy. i’ve downloaded SWIG and extract it.

    how does SWIG work with PyARToolkit? i keep getting error “ImportError:DLL load failed: the specified module could not be found. Python script error from controller “cont#CONTR#1″”

  14. Hi, ardhan,

    I’m sorry, there is a lot of things to explain, building interfaces with SWIG is not so easy.
    If you are using Windows, I suggest you to download binaries, I’ve just uploaded them.
    If you are linux man, you have to look for tutorials how to use SWIG, I can’t help you, because I don’t have linux on my comp right now.

  15. Hello from Spain.

    WHen I use your binaries, my python (2.5) crashes using ArDetectMarker. I would like build my own binaries using swig, but I have problems:
    – When I run python setup.py install, the extension swig_cpp is not recognized.
    I have Visual Studio 2003 installed, but swig don’t see this compiler.

    What is wrong? ARtoolkit is installed in my system. In setup.py, the path (include and lib) is ok.

  16. Hi, Andres,

    I used SWIG just to generate wrapper files for ARTK libraries: arlib_wrap.c from arlib.i; arparamlib_wrap.c from arparamlib.i.

    Then I created VS projects to build Python .pyd files from wrapper files.

    Let me know if you need deeper explanation.

  17. Hi,

    I don´t understand very well.
    In pyartk folder, I run “python setup.py install” and I believe that this command must compile pyartk if I have swig and VS installed, but the problems are here: extension swig_cpp…
    I need a deeper explanation of your process to compile, please, if you have a bit of time…

    Thank you very much

    Andres

    1. Hi, Andres,

      I wasn’t able to build PyARTK using “setup.py” script. So I created “swig.bat” script to build wrap files for ARTK libraries and than included them in VS 2003 projects. Look at this package, it contains mentioned files for PyARTK build.

  18. hello.
    i just find the cool thing. i use blender 2.49b and python 2.6.4 on windowsxp when i tried the demo, the error message on console is
    Python script error from controller “cont1#CONTR#2”:
    Traceback (most recent call last):
    File “detect.py”, line 4, in
    ImportError: Module use of python25.dll conflicts with this version of Python.
    i notice the current Texture Plug-in is built with python 2.5, is it the reason? can you uplode a compatible 2.6 built? thank you very much.

  19. i am very sorry man i don’t know there is a new version demo exist, it works for me. maybe i would browse whole site before leave any comment:P

  20. Hi!
    I would like to know how can i to install it on windows… i saw some steps for the bins but how can i to install de pyartk on windows? and the other things step by step.

    Thank u ! nice work

  21. Hi Cami,

    just download binaries for Python 2.6, store them in Python subfolder (.\Lib\site-packages\PyARTK) and then you can use it with Blender 2.49 – demo should work.

  22. Hi! Again!
    I installed the Numpy and i did put the PyARTK where u told me but i can not see the result like ur demo. Can u tell me where I have to write the path rute? i had download the numpy and artoolkit and PyARTK and PyuARTK bin for windows but when i do “P” in Blender i can only to move the player but i can not to see the web cam, of course i did the obj[‘sopurce’]=’cam’ buit i can not get image of the cam like ur video… can u tell me something about it

    Thank you so much!
    – Cami

  23. Hi Ash!

    Now i fixed what was wrong with the cam! Now I have one more question … When I give “P” to start the game, I can to see the player and the white canvas with the video image from my cam, but when I move the pattern in the cam, what happens is that it moves only the canvas, and when I leave
    still the pattern and move the cam the same thing happens, it just moves the canvas with the camera, but the player and the areas are in the same
    point and those dont change. How do I work well as your video? that if I put the pattern on the floor i could see Blender 3d objects on it, like AR works

    Thanks again Ash!
    -Cami

  24. Hi Cami,

    I don’t know if I understand you correctly. Each pattern is associated with Blender object. One is connected to camera, other can be connected to some 3D object. In demo there is pattern connected to blender camera, so when you set Blender to show camera view (Num0), you’ll see camera moving in Blender scene (like in demo video). In this case webcam movement cannot be distinguished from pattern movement. But if you connect pattern to some object, when you move pattern, you’ll see object moving in scene.

    Hope this helps,
    Ash

  25. Hi Ash!
    My idea is that if i have the pattern on a table (like your video) when i would move the webcam up the pattern i could see the player from top view, but if i move the webcam a little down i could see a side of the player… So how can i to connect the pattern to some object?

    Thanks Ash,
    -Cami

  26. Hi Again!
    I was triying it, but when i push Num 0,nothing happens. I have Blender 2.49b.

    Thanks!
    -Cami

  27. HI ASH
    I HAD PROBLEMS WITH THE DEMO BUT ALL THEY ARE CLEAR. THE DEMO IS RUNNING VERY WELL. THANK YOU FOR IT! I WILL WORK IN IT AND I WILL SHOW U!

    THANKS!

  28. i have problem…
    my console said me.

    importError:Dll load failed
    python script error from controller “cont1#CONTR#2”:
    Traceback:
    File “detect.py”, line 4, in
    import blendVideoTex

    help me plz

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.