使用kinect工具箱记录和重播

时间:2013-02-13 22:02:40

标签: c# wpf kinect record replay

我是StackOverflow和Kinect SDK的新手。我目前正在研究我的最后一年项目,该项目涉及记录/重放颜色/深度和Kinect的骨架数据。找到了Kinect Toolbox来实现这一点,我正在将工具箱与SDK示例项目(颜色/深度/骨架基础知识C#WPF)集成,以生成一个程序,可以显示之前记录的.replay文件中的所有这些流。

我现在遇到的问题是由于KinectReplay类与工具箱和SDK中的KinectSensor类的不同。在Depth Basics示例代码中,为了显示流,WindowLoaded()中的以下行为从Kinect检索的数据分配空间:

/

/ Allocate space to put the depth pixels we'll receive
this.depthPixels = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength];

                // Allocate space to put the color pixels we'll create
                this.colorPixels = new byte[this.sensor.DepthStream.FramePixelDataLength * sizeof(int)];

                // This is the bitmap we'll display on-screen
                this.colorBitmap = new WriteableBitmap(this.sensor.DepthStream.FrameWidth, this.sensor.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);

//The code below came from "Skeleton basics C# WPF", which I need to find the correspondence of "CoordinateMapper" in KinectReplay Class 
    // We are not using depth directly, but we do want the points in our 640x480 output resolution.
                 DepthImagePoint depthPoint = this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint, DepthImageFormat.Resolution640x480Fps30);

在原始示例代码中,从KinectSensor对象中检索了上述对象大小的参数,我需要做类似的事情,但是从KinectReplay对象获取数据,例如,我如何获得“{{ 1}}“从KinectReplay对象”this.sensor.DepthStream.FramePixelDataLength“?

我能想到的唯一解决方案就是打电话给“this.replay = new KinectReplay(recordStream);; “在每次从KinectReplay接收到深度图像帧时调用的this.depthPixels = new DepthImagePixel[e.FramePixelDataLength]中。因此,DepthImagePixel数组将被初始化多次,这是低效的,并且在示例代码中,这将只执行一次。

1 个答案:

答案 0 :(得分:1)

一种解决方案是在初始化期间简单地获取帧中的像素数,并始终使用此值,因为记录帧中的像素数不太可能发生变化。

例如,假设您有一个名为OnNewDepthReplay帧的方法,您可以执行以下操作(未经测试,语法可能已关闭):

public void OnNewDepthReplayFrame(DepthReplayFrameEventArgs e) {
    if (depthPixels == null) {
        depthPixels = new new DepthImagePixel[eFramePixelDataLength];
    }
    // code that uses your depthPixels here
}

但是,使用Kinect 1.5和1.6 SDK附带的记录/重放功能实际上可能比使用Kinect Toolbox更好。我曾经使用Kinect Toolbox进行录制/重放,但是当Kinect for Windows v 1.5问世时,我自己就转移到了Kinect Studio。以下是关于如何使用Kinect Studio以及videoguide on MSDN

相关问题