问题
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);
}
回答1:
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;
so the complete method is:
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;
}
来源:https://stackoverflow.com/questions/26779835/kinect-v2-for-windows-resize-color-frame-in-c-sharp