Gae*_*aki 7 c# bitmap writeablebitmap emgucv kinect
在我的代码中,我从字节数组(依次从Kinect)接收WriteableBitmaps,我想把它们变成用于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));
Run Code Online (Sandbox Code Playgroud)
我从这里得到了代码的下半部分.代码编译和所有内容,但是在我尝试运行程序时挂起(它应该对图像执行一些操作然后将其转换回可以呈现的格式作为一个图像.)暂停我的代码,然后在VS 2013中使用IntelliTrace,我在Image<Gray, Byte> img = new Image<Gray, Byte>(b);"A System.ArgumentException被抛出时得到以下异常:不支持URI格式." 使用替代代码,从我直接从字节到位图的位置给出了同样的错误.(代码可以在这里找到.)
任何人都有关于如何解决此错误或其他方法转换为位图的提示?我是C#和EmguCV的新手,我非常感激.
事实证明所有代码都没有问题。我不太确定错误的技术细节,但是当尝试在 WriteableBitmap 中写入 Gray16 图像(将转换为 Emgu 图像)时收到错误。支持 Bgr565 或其他格式,我相信MS 并未完全实现 Gray16。如果做WinForms应用程序,Format16bppGray也会给出同样的错误。
我决定在将位图写入 Bgr555 时使用灰色 Emgu 图像,这会产生更多噪音,但总比没有好。