OpenCVTexture, webcam, projectTexture example

dl.getdropbox.com/u/652502/playe … jector.zip

A simple “VideoProjector” class that uses OpenCVTexture and (optionally) projectTexture to project video from the default video input device (in my case a USB webcam) onto one or more models. It’s nothing extraordinary, but it took me a few hours, and I saw some related questions on the forums so I thought it might be helpful. There are a few known issues, but it works nicely out of the box with my computer and webcam (Ubuntu 9.04, logitech quickcam pro 9000, nVIDIA GeForce 8600M GT).

As usual, I’ll change the link to a permanent host at p3dp once I resolve some issues with my account.

Let me know if you have any problems or you come up with fixes for the known issues.

Cool thanks, I was planning to look into this soon anyway as it’s something I’m interested in.

At the moment it doesn’t work and gives an error that no video input was found, but I’m guessing it won’t take much tweaking for me to get it working. Even though it said no video input was found, OpenCV was clearly linking up to my camera since the camera’s status light turned on.

(incidentally, I’m on a MacBook Pro)

Great. I hope you find it useful. If you make any improvements on it and feel like sharing them, I’d love to see them. This class is part of a larger project, so any improvement you end up making would be much appreciated (and duly credited, of course).

One of the first things I would try is changing

self._camtex.fromCamera( camera_index = videoInputIndex )

to

self._camtex.fromCamera( )

Here’s the permanent link too: mcstrother.p3dp.com/projector.zip

nope that didn’t help. With the original code at least the camera turned on before the error. Without any parameter in fromCamera the error happens immediately when I run it.

In this thread thomas makes reference to an opencv package you need to install:
discourse.panda3d.org/viewtopic.php?t=6530

Does that apply here or only to what he was doing? That is, do I need to install something separate in order for this to work?

No, you shouldn’t need to download anything else. What version of Panda are you using? I saw a very similar problem on a friend’s computer today and it was resolved when he upgraded to the most recent version.

I am on Windows XP, Panda 1.6.2, using Logitech QuickCam Pro 4000.
I can run OpenCV 1.1 demo applications well.

Program stops and raise exception at:
if self._camtex.getXSize() is 0:
raise IOError(‘No video input found.’)

If I remove the checking, I can see the webcam green light turn on, but no texture captured.

Is it a bug in Panda 1.6.2 ?

Yes, it’s a bug. OpenCVTexture doesn’t work well on Windows - use WebcamVideo instead there (which doesn’t work on Linux. It’s a pain.)

Is the code fragment working ?

print "Choose a webcam"
for o in range(WebcamVideo.getNumOptions()):
  option = WebcamVideo.getOption(o)
  print "Option %d, '%s' at %f fps with size %dx%d" % (o, option.getName(), option.getFps(), option.getXSize(), option.getYSize())

o = int(raw_input("option>"))
option = WebcamVideo.getOption(o)
cursor = option.open()

getNumOptions() return 0. Do I need to configure it ?

Just uploaded a bare bones webcam to cardmaker example, works with OpenCVTexture and WebcamVideo.

Hope it helps some of youze!