Assertion Error on OpenCVTexture()


#1

I’m getting an error while using ARToolkit on Ubuntu 11.10 with panda3d 1.8.0 (stable release).
Here is my code:

from pandac.PandaModules import *
loadPrcFileData("", "auto-flip 1")
from direct.directbase import DirectStart
from direct.task import Task
from time import sleep

tex = OpenCVTexture()
tex.setTexturesPower2(0)
assert tex.fromCamera(0)

cm = CardMaker("background-card")
cm.setFrame(-1, 1, 1, -1)
card = render2d.attachNewNode(cm.generate())
card.setTexture(tex)

base.cam.node().getDisplayRegion(0).setSort(20)

axis = loader.loadModel("yup-axis")
axis.reparentTo(render)
axis.setScale(.2)

ar = ARToolKit.make(base.cam, "./camera_para.dat", 1)
ar.attachPattern("./patt.hiro", axis)


def updatePatterns(task):
  ar.analyze(tex, False)
  return Task.cont
  
  
sleep(1)
taskMgr.add(updatePatterns, "update-patterns",-100)

run()

And here is the error that I get:

DirectStart: Starting the game.
Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)
:display:glxdisplay(warning): No suitable FBConfig contexts available; using XVisual only.
depth_bits=24 color_bits=24 accum_bits=64 back_buffers=1 force_hardware=1 
:display(warning): FrameBufferProperties available less than requested.
mmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
--------------------------------------
SIZE = 640, 480
Distortion factor = 318.500000 263.500000 26.200000 1.012757
700.95147 0.00000 316.50000 0.00000 
0.00000 726.09418 241.50000 0.00000 
0.00000 0.00000 1.00000 0.00000 
--------------------------------------
Assertion failed: (xsize > 0) && (ysize > 0) at line 287 of panda/src/vision/arToolKit.cxx
Traceback (most recent call last):
  File "raw.py", line 27, in updatePatterns
    ar.analyze(tex, False)
AssertionError: (xsize > 0) && (ysize > 0) at line 287 of panda/src/vision/arToolKit.cxx
:task(error): Exception occurred in PythonTask update-patterns
Traceback (most recent call last):
  File "raw.py", line 34, in <module>
    run()
  File "/usr/share/panda3d/direct/showbase/ShowBase.py", line 2910, in run
    self.taskMgr.run()
  File "/usr/share/panda3d/direct/task/Task.py", line 502, in run
    self.step()
  File "/usr/share/panda3d/direct/task/Task.py", line 460, in step
    self.mgr.poll()
  File "raw.py", line 27, in updatePatterns
    ar.analyze(tex, False)
AssertionError: (xsize > 0) && (ysize > 0) at line 287 of panda/src/vision/arToolKit.cxx

If I don’t add the task to the task manager it doesn’t crash but I don’t get the webcam video on my card. So I think the problem is with the OpenCVTexture class (my webcam does work on other software).
Any ideas how to fix it?


#2

I did some more research on the forums and I found out this topic:

panda3d.org/forums/viewtopic … 930e8b45be

In it the member mavasher gets the exact same error as me, but he didn’t get any response.


#3

I hate bumping my own thread, but I was planning on using panda3d and artoolkit on my graduation project and I’m stuck if I can’t get it to work. Any help at all would be greately appreciated.


#4

opencv textures are quite a bit of a pain.

in most cases you are better off using webcamvideo

from my own code-snips base.

from panda3d.core import loadPrcFileData 
loadPrcFileData("", "textures-power-2 none")
from pandac.PandaModules import *
from panda3d.vision import WebcamVideo
from panda3d.core import MovieTexture
#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.task import Task
from time import sleep
import sys
for x,option in enumerate(WebcamVideo.getOptions()):
  print >>sys.stderr, option ,x

print "choose webcam and resolution by index"
option = WebcamVideo.getOption(int(raw_input()))
from direct.showbase.ShowBase import ShowBase
ShowBase()
print "req:", option
tex = MovieTexture(option)
tex.setKeepRamImage(True)
cm = CardMaker("card")
cm.setUvRange(Point2(0, 0), Point2(1, 1))
cm.setFrame(-1, 1, -1, 1)
card = render2d.attachNewNode(cm.generate())
card.setTexture(tex)


#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("./patt.hiro", axis)

#updating the models positions each frame.
def updatePatterns(task):
  ar.analyze(tex)
  return Task.cont
  
  
taskMgr.doMethodLater(1,updatePatterns, "update-patterns", priority = 100)

run()

#5

I have tried to use it in windows with WebCamVideo before and I saw accuracy issues:
lai.sel.eesc.usp.br/hiro1
lai.sel.eesc.usp.br/hiro2

You can notice that if I place the marker on the far left of the screen the model jumps to the right side of the screen. Everywhere else it kinda follows the marker. The orientation works right, but the placement always tends to the middle (except if the marker is on the left side).

I couldn’t get it right with any kind of positioning of the card or changing the camera display region.
So I’m now trying to use it on linux with the OpenCVTexture hoping that the ARToolKit implementation in panda wasn’t made to work with the WebCamVideo class. My calibration file is not the problem because I have tested ARToolKit without panda (using C with the same camera calibration file) and the accuracy is flawless.

Also I thought that WebcamVideo didn’t work on Linux, did the devs implement it on linux?


#6

webcam support was indeed overhauled lately. the sample i posted above should run fine on linux (in fact i wrote it on my linux machine)

as for the jumping, you may need to enable non-power-of-2 textures in your config-prc file


#7

Hey Thomas thanks for your help. I got it to work on Linux using your code, it works flawlessly. But trying the same code on Windows it didn’t run.

For some reason in windows this:

from direct.showbase.ShowBase import ShowBase 
ShowBase()

needs to be before this call in Windows:

WebcamVideo.getOptions()

Or else this call returns an empty list.

When I place the ShowBase() call before, it runs fine but there are the same accuracy issue I mentioned before (no jumping when close to the left side though). The rest of the code is exactly the same.

loadPrcFileData("", "textures-power-2 none")

doesn’t fix the accuracy issues in Windows. Should I report it as a bug?


#8

Maybe you should choose a different option from getOptions(), perhaps that has a higher resolution, or a different framerate?


#9

I tried different options, all of them get the same problem. I also tried with 2 different cameras on windows. On linux I only tried with one because I can’t get the other one to work in linux.