隐藏Kinect v2 ColorFrame到EmguCV图像<bgr,byte =“”> </bgr,>

时间:2014-12-30 06:15:09

标签: kinect emgucv

我想将Kinect V2 SDK的ColorFrame转换为Image,即EmguCV的图像格式。将ColorFrame转换为BitmapSource然后将BitmapSource转换为Bitmap,最后将Bitmap转换为EmguCV Image似乎是CPU不必要的开销。 以下是代码 -

private byte[] pixels = null;
this.pixels = new byte[colorFrameDescription.Width * colorFrameDescription.Height * colorFrameDescription.BytesPerPixel];

using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
{
    if (colorFrame != null)
    {
        FrameDescription colorFrameDescription = colorFrame.FrameDescription;
        if (colorFrame.RawColorImageFormat == ColorImageFormat.Bgra)
            colorFrame.CopyRawFrameDataToArray(pixels);
        else
            colorFrame.CopyConvertedFrameDataToArray(this.pixels, ColorImageFormat.Bgra);

        //Initialize Emgu CV image then assign byte array of pixels to it
        Image<Bgr, byte> img = new Image<Bgr, byte>(colorFrameDescription.Width, colorFrameDescription.Height);
        img.Bytes = pixels;

        imgBox.Image = img;//Show image in Emgu.CV.UI.ImageBox
    }
}

0 个答案:

没有答案