In Panda 1.6.0, the ARToolKit finally works, and OpenCVTexture doesn’t work on Windows, but WebcamVideo does.
I got everything working, except that the calibration is off. Where are you supposed to place the virtual camera, and what is the correct FOV, to get the virtual world to align with the real world?
I don’t know exactly what FOV you need - I got it to work without setting any FOV. I just loaded the camera_para.dat as second argument to ARToolKit.make, maybe you need a custom configuration for your camera.
What do you mean with “place the virtual camera” ? Specify base.cam in the ARToolKit.make call, and wherever your patterns are reparented to, they will automatically be transformed by analyze() to have the transform relative to the camera given by ARToolKit.
Here’s the code I wrote. I’m using the exact same camera_para.dat as I used in a working C++ ARToolKit program. Maybe it has something to do with where my card displaying the movie is. I put it at a Y position of 5, and scaled it up until it filled the screen. But somehow, there isn’t a one to one match between the video and the box.
I’ve tried moving and scaling the video window, and that works, but then I have a video window with the wrong aspect ratio that only takes up part of my screen.
How does your setup differ from mine?
from pandac.PandaModules import *
from direct.directbase.DirectStart import *
cursor.fetchIntoTexture(0, videoTexture, 0)
option = WebcamVideo.getOption(0)
cursor = option.open()
videoTexture = Texture('movie')
videoTextureScale = Vec2(option.getSizeX()/float(videoTexture.getXSize()), option.getSizeY()/float(videoTexture.getYSize()))
cardMaker = CardMaker('cardMaker')
card = render.attachNewNode(cardMaker.generate())
model = loader.loadModel("box")
toolkit = ARToolKit.make(base.cam, Filename("camera_para.dat"), 1)
I use OpenCVTexture, not WebcamVideo. So I can’t really try it out here what was wrong.
But I do know I had to do some stuff to get the card underlayed correctly - I think I had to make the card square, shift it to the left, and call setTexturesPower2(0) on the texture.
I figured it out. In case anyone needs to calibrate AR in the future, the way to do it is to make the card square and shift it to the left, as pro-rsoft said. Adjust the scale and position of the card until the model matches the video.
However, you’ll then have empty space on your screen. The way to fix that is to change your display region, like this:
base.camNode.getDisplayRegion(0).setDimensions(0, 1 + 0.3202, 0 - 0.0169, 1 + 0.0169)
Those are the numbers that worked for me, but if you set it up differently, you might need to use different numbers.
Hello Howard, congratz to getting it work!
Maybe you can share your complete code, and/or write a little tutorial/example about how to do an AR-app with panda3d??? That would be realy great for noobs like me ^^
I realy want to play with Panda and my webcam, but i dont think i can get it on my own, don´t even no where to start…
I downloaded artoolkit, and installed it, but how do i tell panda where to find the libarys, or is the artoolkit already inclouded???
Pls. help a desperated noob
ARToolKit is already included.
Thanks mate, this is great, is it just inclouded in 1.6 or also 1.5.4?
I don’t remember exactly - I believe it already exists for a long time.
from pandac.PandaModules import ARToolKit
If that fails, you need to upgrade. If it succeeds, it’s included.
wow, thats a fast reply, thanks again mate!!! Gonna try what u suggested on 1.5.4
for a sample which runs under linux. check this one
for windows you need to change the opencvtexture to webcamvideo. the rest should work just the same.
Thank you sooooooo much for that example, this should help me allot!
I also tryed:
from pandac.PandaModules import ARToolKit
on panda 1.5.4 and it doesnt complain, so i should work i guess.
But i read that webcamvideo doesn’t work in v1.5.4, so i may need to use 1.6. (discourse.panda3d.org/viewtopic … highlight=)
The problem is I wanna use Panda v1.5.4 cause in v1.6 i can´t get shadow diffuse and normalmap working (see: www1.panda3d.org/phpbb2/viewtopic.php?t=5442)
so it´s a vicious circle…
Just in case anyone stumbles on this page facing the same problem, this is what I found with the Windows/Webcamvideo version.
I had the same misalignment problem. It disappears however when the camera resolution is set to 640 by 480, and also the camera_para.dat file matches a 640 by 480 camera.
Other resolutions are misaligned.
I haven’t quit figured out why. Just noticed that there is some hard coded 640x480 in the arToolKit.cxx source in the ‘make’ function…