Hi! I have a small displacement error on the marker position.
I’ve found out that the displacemente changes according to the size of the VideoTexture being analyzed.
Here are some youtube videos where you can see clearly the problem.
youtube.com/watch?v=Z-1mUwNRsz0
youtube.com/watch?v=6-pnxWIqP2Q
And the code:
# -*- coding: utf-8 -*-
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.
#loadPrcFileData("", "fullscreen 1")
from direct.directbase.DirectStart import *
from direct.showbase.DirectObject import DirectObject
from direct.gui.OnscreenText import OnscreenText
from direct.task import Task
from time import sleep
def textoDebug(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)
class FundacionMasAR(DirectObject):
def update(self,task):
if self.cursor.ready():
self.cursor.fetchIntoTexture(0, self.videoTexture, 0)
self.ar.analyze(self.videoTexture)
self.posMark1.setText(("Mark1: x=%.2f" % self.axis.getX()) + (", y=%.2f" % self.axis.getY()) + (", z=%.2f" % self.axis.getZ()))
return task.cont
def __init__(self):
self.posMark1 = OnscreenText()
self.posPanda = OnscreenText()
print str(PandaSystem.getVersionString())
render.setAntialias(AntialiasAttrib.MAuto)
#set the rendering order manually to render the card-with the webcam-image behind the scene.
base.cam.node().getDisplayRegion(0).setSort(20)
base.camLens.setAspectRatio(640.0 / 480.0)
# ----------- Inicializar camara ------------
#print "Seleccione una camara"
#for o in range(WebcamVideo.getNumOptions()):
#option = WebcamVideo.getOption(o)
#print "Opcion %d, '%s' x %f fps" % (o, option.getName(), option.getFps())
#op = int(raw_input("option>"))
#option = WebcamVideo.getOption(op)
# Establecerla directamente
option = WebcamVideo.getOption(0)
self.cursor = option.open()
self.videoTexture = Texture('movie')
self.cursor.setupTexture(self.videoTexture)
# ------------------------------------------------
# What about this? Didn't do the trick.
#self.videoTexture.setXSize(640)
#self.videoTexture.setYSize(480)
self.videoTextureScale = Vec2(option.getSizeX()/float(self.videoTexture.getXSize()), option.getSizeY()/float(self.videoTexture.getYSize()))
self.txtCursor = textoDebug(0.95,"Cursor: " + str(self.cursor.sizeX()) + " x " + str(self.cursor.sizeY()))
self.txtVideoTex = textoDebug(0.90,"VideoTexture: " + str(self.videoTexture.getXSize()) + " x " + str(self.videoTexture.getYSize()))
# This didn't work either.
#self.videoTexture.setTexturesPower2(0)
# ---- CardMaker ---------------------------------
self.cm = CardMaker("background-card")
self.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
self.cm.setUvRange(Point2(self.videoTextureScale[0],0), Point2(0,self.videoTextureScale[1]))
#cm.setUvRange(Point2(1,0), Point2(0,1))
self.card = render2d.attachNewNode(self.cm.generate())
self.card.setTexture(self.videoTexture)
# ---- ARToolkit ---------------------------------
#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.
self.ar = ARToolKit.make(base.cam, "./camera_para.dat", 1)
#load a model to visualize the tracking
self.axis = loader.loadModel("yup-axis")
self.axis.reparentTo(render)
self.axis.setScale(.2)
self.posMark1 = textoDebug(0.85,"Mark1: x=" + str(self.axis.getX()) + ", y=" + str(self.axis.getY()) + " z=" + str(self.axis.getZ()))
#attach the model to a pattern so it updates the model's position relative to the camera each time we call analyze()
self.ar.attachPattern("./raro1.pat", self.axis)
sleep(1) #some webcams are quite slow to start up so we add some safety
taskMgr.add(self.update, "update-patterns",-100)
run()
FundacionMasAR()
[/code]