如何使用ViewModel在Kinect Interaction Sample中传递骨架数据

时间:2013-04-02 10:37:33

标签: c# wpf xaml kinect kinect-sdk

我正在使用最新的SDK(1.7),并希望在其中一个示例中进行一些更改。

我有一个名为KinectAttractWindow的项目,我希望从骨架,深度或彩色图像中获取数据,但我无法弄清楚如何在视图和视图模型之间传递这些数据。例如,在此HomeScreenViewModel中,我想使用此HomeScreenView绘制骨架。或者如何使用相同的项目架构显示深度或颜色数据?

如何以正确的方式做到这一点?你有什么建议吗?

我已经更新了我的HomeView和ViewModel,但是我在这里得到了一个N​​ullReferenceException:

'this.RGBImage.DisplayImage.Source =
                BitmapSource.Create(colorFrame.Width,
                colorFrame.Height,
                96,
                96,
                PixelFormats.Bgr32,
                null,
                pixels,
                stride);'

1 个答案:

答案 0 :(得分:1)

首先确保您的对象RGBImage及其属性DisplayImage不是null。我使用WriteableBitmap来显示我的RGB值,因为它会创建一个WriteableBitmap对象并重写像素它使性能更好。您可以在WriteableBitmap here上找到更多信息。

您可以像这样使用它 -

WriteableBitmap wBitmap = new WriteableBitmap(colorFrame.Width,
                                                  colorFrame.Height,
                                                  // Standard DPI
                                                  96, 96,
                                                  // Current format for the ColorImageFormat
                                                  PixelFormats.Bgr32,
                                                  // BitmapPalette
                                                  null);

通过执行此操作将新像素写入对象 -

wBitmap.WritePixels(
                // Represents the size of our image
               new Int32Rect(0, 0, colorFrame.Width, colorFrame.Height),
                // Our image data
               _pixelData,
                // How much bytes are there in a single row?
               colorFrame.Width * colorFrame.BytesPerPixel,
                // Offset for the buffer, where does he need to start
               0);

将其指定给图像控件 -

this.RGBImage.DisplayImage.Source  = wBitmap;

骨架数据

您可以执行与颜色数据完全相同的骨架跟踪,Enable()流,处理SkeletonFrameReady中的数据并保存ViewModel中属性中的所有数据。 通过这样做,它使您能够数据绑定到这些属性。