适用于Windows的Kinect v2:在C#中调整颜色框的大小 [英] Kinect v2 for windows: resize color frame in c#
本文介绍了适用于Windows的Kinect v2:在C#中调整颜色框的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都知道,如果可能的话,如何降低kinect帧分辨率以实现色彩流动?因为全高清尺寸对于我的示波器来说太大了. 我找到了完整高清帧的代码:
anyone know, if it's possible, how to decrease the kinect frame resolution for color flow? because the full-hd size is too high for my scope.Thanks I have found this code for full hd frame:
private BitmapSource ToBitmap(ColorFrame frame)
{
int width = frame.FrameDescription.Width;
int height = frame.FrameDescription.Height;
PixelFormat format = PixelFormats.Bgr32;
byte[] pixels = new byte[width * height * ((PixelFormats.Bgr32.BitsPerPixel + 7) / 8)];
if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
{
frame.CopyRawFrameDataToArray(pixels);
}
else
{
frame.CopyConvertedFrameDataToArray(pixels, ColorImageFormat.Bgra);
}
int stride = width * format.BitsPerPixel / 8;
return BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride);
}
推荐答案
我解决了在最后添加此代码的问题
i have resolved adding this code at the end
BitmapSource bitmap= BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride);
ScaleTransform scale=new ScaleTransform((Width / bitmap.PixelWidth),(Height / bitmap.PixelHeight));
TransformedBitmap tbBitmap = new TransformedBitmap(bitmap, scale);
return tbBitmap;
所以完整的方法是:
private BitmapSource ToBitmap(ColorFrame frame)
{
int width = frame.FrameDescription.Width;
int height = frame.FrameDescription.Height;
PixelFormat format = PixelFormats.Bgr32;
byte[] pixels = new byte[width * height * ((PixelFormats.Bgr32.BitsPerPixel + 7) / 8)];
if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
{
frame.CopyRawFrameDataToArray(pixels);
}
else
{
frame.CopyConvertedFrameDataToArray(pixels, ColorImageFormat.Bgra);
}
int stride = width * format.BitsPerPixel / 8;
BitmapSource bitmap= BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride);
ScaleTransform scale=new ScaleTransform((640.0 / bitmap.PixelWidth),(480.0 / bitmap.PixelHeight));
TransformedBitmap tbBitmap = new TransformedBitmap(bitmap, scale);
return tbBitmap;
}
这篇关于适用于Windows的Kinect v2:在C#中调整颜色框的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文