Kinect v2 for windows: resize color frame in c#

大城市里の小女人 提交于 2019-12-23 05:45:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!