c# - UWP 中的 Kinect 深度和 IR 图像(去除颜色)
问题描述
我正在为 XBOX 和 windows 使用 Kinect V2 UWP C#。为此,我关注了Kinect UWP 演示。我能够读取和显示帧,如相机帧示例中所示,但我注意到深度和 IR 图像是彩色的,例如: 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
推荐阅读
- java - 下次点击输入前自动输入
- azure-cognitive-search - 使用 Cosmos DB 索引器扩展 Azure 搜索字段
- entity-framework - EF core .any 不过滤结果
- c# - Visual Studio、C# 和 StanfordCoreNLP 问题
- javascript - 如何更改标签的内部值?
- ios - Swift Decodable 无法使用单个根元素进行解码
- string - Print characters at even and odd indices from a String
- r - 解开错误标签在两棵树中都不匹配
- javascript - 实现密码切换功能
- c - 使用 mbedtls 库 gcc 命令编译程序