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?