Hi!
The image says all:
img693.imageshack.us/img693/8139 … placed.jpg
The marker orientation is fine, but its displaced mostly to the left. Doesn’t hit the real marker well.
Here is my code (based on some other samples and modified):
from pandac.PandaModules import *
loadPrcFileData("", “auto-flip 1”) #usualy the drawn texture lags a bit behind the calculted positions. this is a try to reduce the lag.
from direct.directbase import DirectStart
from direct.task import Task
from time import sleep
#print str(PandaSystem.getVersionString())
#print “Choose a webcam”
#for o in range(WebcamVideo.getNumOptions()):
option = WebcamVideo.getOption(o)
print “Option %d, ‘%s’ at %f fps” % (o, option.getName(), option.getFps())
ask the user which camera to use
#o = int(raw_input(“option>”))
#option = WebcamVideo.getOption(o)
option = WebcamVideo.getOption(7)
cursor = option.open()
videoTexture = Texture(‘movie’)
cursor.setupTexture(videoTexture)
print videoTexture.getXSize()
print videoTexture.getYSize()
print option.getSizeX()
print option.getSizeY()
calculate the same as openCVTexture has as function
videoTextureScale = Vec2(option.getSizeX()/float(videoTexture.getXSize()), option.getSizeY()/float(videoTexture.getYSize()))
#create a card which shows the image captured by the webcam.
cm = CardMaker(“background-card”)
define the card size
cm.setFrame(1, -1, -1, 1)
#cm.setFrame(-videoTextureScale[1]/2.,videoTextureScale[1]/2.,-videoTextureScale[0]/2.,videoTextureScale[0]/2.)
#cm.setFrame(-videoTextureScale[1],videoTextureScale[1],-videoTextureScale[0],videoTextureScale[0])
set the uv coordinates of the card, y-scale must be reversed
cm.setUvRange(Point2(videoTextureScale[0],0), Point2(0,videoTextureScale[1]))
card = render2d.attachNewNode(cm.generate())
card.setTexture(videoTexture)
#set the rendering order manually to render the card-with the webcam-image behind the scene.
base.cam.node().getDisplayRegion(0).setSort(20)
#load a model to visualize the tracking
axis = loader.loadModel(“yup-axis”)
axis.reparentTo(render)
axis.setScale(.2)
#initialize artoolkit, base.cam is our camera ,
#the camera_para.dat is the configuration file for your camera. this one comes with the artoolkit installation.
#last paremeter is the size of the pattern in panda-units.
ar = ARToolKit.make(base.cam, “./camera_para.dat”, 1)
#attach the model to a pattern so it updates the model’s position relative to the camera each time we call analyze()
ar.attachPattern("./flarlogo.pat", axis)
#updating the models positions each frame.
def updatePatterns(task):
if cursor.ready():
cursor.fetchIntoTexture(0, videoTexture, 0)
ar.analyze(videoTexture, True)
return Task.cont
sleep(1) #some webcams are quite slow to start up so we add some safety
taskMgr.add(updatePatterns, “update-patterns”,-100)
run()
Any ideas?
Some inconsistencies that may be around the problem:
· The webcam is at 640x480x30fps.
· The VideoTexture size is 1024 x 512. Tried changing it, same problem.
· The DisplayRegion of the Panda camera is 800x600, as the Window Size. Tried changing it, same problem.