UWP 中的 Kinect 深度和红外图像(去除颜色)

Kinect Depth and IR image in UWP (remove color)

我正在为 XBOX 和 windows 使用 Kinect V2 UWP C#。我关注 Kinect UWP demo for this purpose. I was able to read and display frames as also shown in Camera Frame sample 但我注意到深度和红外图像是彩色的,例如: Kinect studio and UWP application output

我是新手,尝试搜索但没有找到明确的答案。有人可以帮忙吗? 非常感谢。

我尝试了很多东西,终于找到了一种方法来获得没有伪色彩的图像。

由于XAML只显示Bgra8格式,需要转换。它还有助于分别处理帧的颜色和深度。

我还需要将 Windows 10 版本更新到 10.0.19041.0 或更高版本。

//clrFrame.
            var buffFrame = clrFrame?.BufferMediaFrame;
            
            // Get the Individual Frame
            var vidFrame = clrFrame?.VideoMediaFrame;
            {
                if (vidFrame == null) return;

                
                // create a UWP SoftwareBitmap and copy Frame into Bitmap
                SoftwareBitmap sbt = new SoftwareBitmap(vidFrame.SoftwareBitmap.BitmapPixelFormat, vidFrame.SoftwareBitmap.PixelWidth, vidFrame.SoftwareBitmap.PixelHeight);
                vidFrame.SoftwareBitmap.CopyTo(sbt);

                // PixelFormat needs to be in 8bit BGRA for Xaml writable bitmap
                if (sbt.BitmapPixelFormat != BitmapPixelFormat.Bgra8)
                    sbt = SoftwareBitmap.Convert(vidFrame.SoftwareBitmap, BitmapPixelFormat.Bgra8);
                
                if (source != null)
                {
                    // To write out to writable bitmap which will be used with ImageElement, it needs to run
                    // on UI Thread thus we use Dispatcher.RunAsync()...
                    var ignore = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        // This code runs on UI Thread
                        // Create the writableBitmap for ImageElement display
                        extBitmap = new WriteableBitmap(sbt.PixelWidth, sbt.PixelHeight);

                        // Copy contents from UWP software Bitmap
                        // There are other ways of doing this instead of the double copy, 1st copy earlier
                        // this is a second copy.
                        sbt.CopyToBuffer(extBitmap.PixelBuffer);
                        extBitmap.Invalidate();

                        // Set the imageElement source
                        var ig = source.SetBitmapAsync(sbt);
                        imgView.Source = source;

                    });

                }
            }

以下项目示例有助于解决此问题。我必须为 IR 和深度创建处理并传递适当的参数。

https://github.com/dngoins/KinectUWPApps/tree/master/WorkingWithMediaCaptureFramesSolution