I tried many things and finally found a way to get images without pseudo colors.
Since XAML only displays in format Bgra8, it needed to be converted. It helped processing frames separately for color and depth as well.
I also needed to update my Windows 10 version to 10.0.19041.0 or later.
//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;
});
}
}
The following project sample helps with this problem. I had to create processing for IR and depth and pass appropriate parameters.
https://github.com/dngoins/KinectUWPApps/tree/master/WorkingWithMediaCaptureFramesSolution