From PIL to Panda Texture.

Hello, is this possible?

frame = cvQueryFrame(capture)

im = Ipl2PIL(frame)

print im.mode #prints RGB

tex = Texture()

buffer = PTAUchar.emptyArray(0)
buffer.setData(im.tostring())

tex.setFormat(Texture.FRgb)  
tex.setXSize(im.size[0])
tex.setYSize(im.size[1])

tex.setRamImage(CPTAUchar(buffer), MovieTexture.CMOff)

I am getting a “GL Texture creation failed for : GL error 1281” Error.

Thanks, and sorry for my english.

Seems like you’re doing everything right (though I would use Texture.CMOff instead of MovieTexture.CMOff, but that doesn’t technically matter).

Perhaps the GL error is due to some other problem? Are you sure you are applying the same Texture object that has the ram image, for instance, and not some other Texture object by mistake?

David

Yes I am, this is the full code:

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

from opencv import * 
from opencv.highgui import * 
from opencv.adaptors import *

storage = cvCreateMemStorage(0)
capture = cvCreateCameraCapture(0)
cascade = cvLoadHaarClassifierCascade('haarcascade_frontalface_alt.xml', cvSize(1, 1))

gray = cvCreateImage(cvSize(640, 480), 8, 1)
small = cvCreateImage(cvSize(320, 240), 8, 1)

frame = cvQueryFrame(capture)

cvFlip(frame, None, 0)   
cvCvtColor(frame, gray, CV_BGRA2GRAY)
cvResize(gray, small, CV_INTER_NN)

im = Ipl2PIL(frame)

tex = Texture()

buffer = PTAUchar.emptyArray(0)
buffer.setData(im.tostring())

tex.setFormat(Texture.FRgb)  
tex.setXSize(im.size[0])
tex.setYSize(im.size[1])

tex.setRamImage(CPTAUchar(buffer), Texture.CMOff)

cardMaker = CardMaker('cardMaker')
cardMaker.setFrame(-4 / 3.0, 4 / 3.0, -1, 1)
cardMaker.setUvRange(Point2(0.625, 0), Point2(0, 0.9375))

card = render.attachNewNode(cardMaker.generate())
card.setTexture(tex)
card.setTwoSided(True)
card.setY(5)
card.setScale(1.72)
card.setSx(-card.getSx())
card.setBin('fixed', -1)
card.setDepthTest(False)
card.setDepthWrite(False)

model = loader.loadModel('box')
model.reparentTo(render)
model.setBin('fixed', 1)
model.setDepthTest(False)
model.setDepthWrite(False)

run()

The next step would be the face detection. Thanks.