I’m using recipe here: [Small issue with using numpy arrays as textures)
with 1.8.2 and cv2 (2.4.1)
Alas - not working - no image coming through
Also won’t exit and release control back. so some ptr lossage ?
my code looks like this:
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.gui.DirectGui import *
from direct.gui.OnscreenText import OnscreenText
from panda3d.core import *
import sys
import cv2
import cv2.cv as cv
import numpy as np
def get_cv_img(cap):
success, img = cap.read() # img is a numpy array
print "success", success
if success:
shape = img.shape # (480,640,3)
tex = Texture("detect")
tex.setup2dTexture(shape[0], shape[1], Texture.TUnsignedByte, Texture.FRgb)
p = PTAUchar.emptyArray(0)
try:
p.setData(img)
except AssertionError:
pass
tex.setRamImage(CPTAUchar(p))
return (tex)
class World(DirectObject):
def __init__(self):
###Standard initialization stuff
#Standard title that's on screen in every tutorial
self.title = OnscreenText(text="opencv test", style=1,
fg=(1,1,1,1), pos=(0.9,-0.95),
scale = .04 )
base.setBackgroundColor(0.5,0.5,0.5)
# initiialise cv2 camera
self.cap = cv2.VideoCapture(0) # first camera
sm = CardMaker('bg')
test = render2d.attachNewNode(sm.generate(),2)
img = get_cv_img(self.cap)
test.setTexture(img)
#
self.accept('escape', sys.exit)
def turn(self):
# continually call cap.read() here to update the texture
pass
###
w = World()
run()