I’m seeing some weird visual artifacts when I try to render a kinect data stream using panda3d. At the moment I’m using the setRamMipmapPointerFromInt() method to pass a void * pointer holding BGRA data back into panda3d… and it works, kinda.
However, when the video changes quickly, weird glitchy graphics turn up on the texture. It’s a little difficult to explain, so I’ve put a video of it happening up here (excuse the quality, I’m pretty sure the glitches are extremely obvious to see):
youtube.com/watch?v=TTKIDriF … e=youtu.be
By comparison this is the same video stream being rendered pixel by pixel using libSDL:
youtube.com/watch?v=-HDiYSef … e=youtu.be
Notice how in the second video there are no weird previous-frame-overlay issues; that’s because the raw pixel stream from the kinect is actually not glitching; somehow pushing these pixels into the panda texture is causing the problem.
The code I’m using for my texture is:
import pyar
from pandac.PandaModules import *
from direct.task import Task
class Vision(object):
""" Vision helper """
def __init__(self):
self.api = pyar.Api()
self.api.init()
self.width = self.api.prop(self.api.AR_PROP_WIDTH)
self.height = self.api.prop(self.api.AR_PROP_HEIGHT)
self.depth_max = self.api.prop(self.api.AR_PROP_DEPTH_MAX)
self.depth_none = self.api.prop(self.api.AR_PROP_DEPTH_NONE)
def next(self):
self.api.unlock()
rgb = self.api.rgb()
depth = self.api.depth()
return (rgb, depth)
def shutdown(self):
self.api.shutdown()
class VisionTexture(Texture):
""" Texture using the vision class to read data """
def __init__(self):
Texture.__init__(self)
self.__vision = Vision()
self.setup2dTexture(self.__vision.width,
self.__vision.height,
Texture.TUnsignedByte,
Texture.FRgb)
self.makeRamImage()
taskMgr.add(self.updateTextureTask, "updateTextureTask")
def updateTextureTask(self, t):
(rgb, depth) = self.__vision.next()
rgb = long(rgb)
self.setRamMipmapPointerFromInt(rgb, 0, self.__vision.width * self.__vision.height * 3)
return Task.cont
…and to render it:
import bootstrap
import pyar
from pandac.PandaModules import *
from direct.task import Task
if __name__ == "__main__":
from direct.directbase.DirectStart import *
cm = CardMaker("cm")
cm.setFrame(-1, 1, 1, -1)
card = render2d.attachNewNode(cm.generate())
tex = pyar.VisionTexture()
card.setTexture(tex)
run()
Does anyone know if there’s some kind of locking I need to do when updating the texture data or something like that?
It seems really strange to me that I ever see a texture which has raw pixel data that is not the same as the pixel data set using setRamMipmapPointerFromInt(), which makes me think somehow… the texture is being buffered or something?
Any help much appreciated!