p3d is not work with webcamvideo

Hi All~
I am going to do the webcamvideo test with p3d. However, it is not work…Did anyone knows what’s happen?
here is my testing code

import sys

from pandac.PandaModules import *
from direct.directbase import DirectStart

if sys.platform == 'win32':
  # manually select the video mode
  if False:
    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)
  else:
    # just use the option 0
    option = WebcamVideo.getOption(0)
 
  cursor = option.open()
 
  videoTexture = Texture('movie')
  cursor.setupTexture(videoTexture)
  # calculate the same as openCVTexture has as function
  videoTextureScale = Vec2(option.getSizeX()/float(videoTexture.getXSize()), option.getSizeY()/float(videoTexture.getYSize()))
 
  # under windows the webcam must be updated manually
  def updateVideo(task):
    if cursor.ready():
      cursor.fetchIntoTexture(0, videoTexture, 0)
    return task.cont
  taskMgr.add(updateVideo, 'updateVideo')

elif sys.platform == 'linux2':
  # fallback in case something goes wrong (openCVTexture doesnt work under windows yet)
  videoTextureScale = (1,1)
 
  # use the tex-coordinates so the video fills the whole card
  videoTexture = OpenCVTexture()
  print "camera open", videoTexture.fromCamera()
  print "camera video resolution", videoTexture.getVideoWidth(), videoTexture.getVideoHeight()
  # get the texture scale
  videoTextureScale = videoTexture.getTexScale()
  if not videoTexture.getVideoWidth() or not videoTexture.getVideoHeight():
    print "invalid camera texture size", videoTexture.getVideoWidth(), videoTexture.getVideoHeight()
    sys.exit()
 
  # save the opencv video into a image
  #pnmImage0 = PNMImage()
  #openCVTexture.store(pnmImage0)

# generate a card to show the texture on
cardMaker = CardMaker('cardMaker')
# define the card size
#cardMaker.setFrame(-videoTextureScale[1]/2.,videoTextureScale[1]/2.,-videoTextureScale[0]/2.,videoTextureScale[0]/2.)
cardMaker.setFrame(-videoTextureScale[1],videoTextureScale[1],-videoTextureScale[0],videoTextureScale[0])
# set the uv coordinates of the card, y-scale must be reversed
cardMaker.setUvRange(Point2(videoTextureScale[0],0), Point2(0,videoTextureScale[1]))

# create a card and attach to render
card = render.attachNewNode(cardMaker.generate())
card.setTexture(videoTexture)
card.setTwoSided(True)

# rotate it
card.hprInterval(10,Point3(360,0,0)).loop()

base.disableMouse()
base.camera.setPos(0,-3,0)

run() 

I convert it in windows cmd and the script is
“packp3d -o webcam.p3d -r vision -r mporepy -d c:/webcam”
“webcam.p3d” is generated but it crashed when I open it. What’s wrong with my p3d files?

What does the p3dsession.log file look like? You’ll find this in the Panda3D/log directory.

David

thx David

I can’t found my p3dsession.log :open_mouth:

but i can capture the windows error message box to you

http://dc237.4shared.com/img/287544128/fb518d0e/p3derror.JPG?rnd=0.4871185424791037&sizeM=7

Hi,

I’m having a similar issue. I got my code for using the webcam and ARtoolkit working both in windows and linux. I packaged the p3d this way:

packp3d -o AR.p3d -m sample2.py -r vision

and when I run it I get:

The first time I run it I could see it downloading the opencv and artoolkit libraries. So that can not be the problem.

I have checked, and when I do not run the p3d file, panda is using glxGraphicsPipe as well and it works smoothly. Any ideas what it could be?

Thanks!!