在我的代码中,我从字节数组(依次从 Kinect)接收 WriteableBitmap,我想将它们转换为位图以与 EmguCV 一起使用。目前这是我的代码:
// Copy the pixel data from the image to a temporary array
colorFrame.CopyPixelDataTo(this.colorPixels);
// Write the pixel data into our bitmap
this.colorBitmap.WritePixels(
new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
this.colorPixels,
this.colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
0);
BitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(colorBitmap));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
Bitmap b=new Bitmap(ms);
Image<Gray, Byte> img = new Image<Gray, Byte>(b);
img = img.ThresholdBinary(new Gray(200), new Gray(255));
我得到了代码的下半部分here https://stackoverflow.com/questions/10334110/how-to-convert-writeablebitmap-in-rgb24-pixel-format-into-a-emgucv-imagebgr-by代码编译了一切,但是当我尝试运行程序时挂起(它应该对图像执行一些操作,然后将其转换回可以显示为图像的格式。)暂停我的代码,然后在 VS 2013 中使用 IntelliTrace,我在以下位置收到以下异常Image<Gray, Byte> img = new Image<Gray, Byte>(b);
“抛出了 System.ArgumentException:不支持 URI 格式。”使用替代代码,从我直接从字节到位图的地方给了我同样的错误。 (代码可以在这里找到。 https://stackoverflow.com/questions/11730373/byte-array-to-bitmap-image)
有人知道如何解决此错误或转换为位图的其他方法吗?我是 C# 和 EmguCV 的新手,我将非常感激。
事实证明所有代码都没有问题。我不太确定错误的技术细节,但是当尝试在 WriteableBitmap 中写入 Gray16 图像(将转换为 Emgu 图像)时收到错误。支持 Bgr565 或其他格式,我相信MS 并未完全实现 Gray16。如果做WinForms应用程序,Format16bppGray也会给出同样的错误。
我决定在将位图写入 Bgr555 时使用灰色 Emgu 图像,这会产生更多噪音,但总比没有好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)