Reading from Webcam to display as a background

This should work for you hopefully, just put together on Xubuntu 16.04, works with OpenCVTexture and WebcamVideo. Pass 1 argument from the command line to choose OpenCV camera input, 0 is default and 1 is second cam, 2 is third camera etc. ESC to exit. To run copy code to a file i.e. WebCardNopenCVthingy.py and run with:

python WebCardNopenCVthingy.py

from panda3d.core import loadPrcFileData 
from panda3d.core import PNMImage
from panda3d.vision import WebcamVideo
from panda3d.vision import OpenCVTexture
from panda3d.core import Texture, CardMaker, Point2, MovieTexture, TextureStage
import sys
from time import sleep,time

loadPrcFileData("", "textures-power-2 none")
loadPrcFileData('', 'client-sleep 0.001')

from direct.showbase.ShowBase import ShowBase

if len(sys.argv) > 1: TEST = sys.argv[1] # if passed with argument from cli will load that camera using OpenCVTexture 
else: TEST = "WebcamVideo"
 
class MyApp(ShowBase):

    def __init__(self):

        ShowBase.__init__(self)

        print "TRYING WITH " + TEST 

        if TEST == "WebcamVideo":
           # using WebcamVideo
            option = WebcamVideo.getOption( 0 ) # 0 here is default webcam, 1 would be second cam etc.
            videoTexture = MovieTexture(option)
            videoTexture.setKeepRamImage(True)
            print "WebcamVideo based texure infos: ->", videoTexture
        else :
            # using OpenCVTexture
            videoTexture = OpenCVTexture() 
            videoTexture.fromCamera(int(TEST))
            print "OpenCV based texure infos: -->", videoTexture
        
        cm = CardMaker("card")
        cm.setUvRange(Point2(0, 0), Point2(1, 1))
        cm.setFrame(-1, 1, -1, 1)
        card = render.attachNewNode(cm.generate())
        card.setTexture(videoTexture)
        card.setPos(0, 10, 0)
        card.reparentTo(self.render)
        
        self.accept('escape', lambda: sys.exit())
        
app = MyApp()
app.run()

…to run with OpenCVTexture:

python WebCardNopenCVthingy.py {webcam number} 

        ...where {webcam number} is the number of your cam, try 0 (zero) first, then 1 if you have second cam.