【发布时间】:2013-12-28 08:07:56
【问题描述】:
在我的代码中,我从字节数组(又从 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));
我从here 获得了代码的下半部分。代码可以编译,但在我尝试运行程序时挂起(它应该对图像执行一些操作,然后将其转换回可以显示为图像的格式。)暂停我的代码,然后在 VS 2013 中使用 IntelliTrace,我在Image<Gray, Byte> img = new Image<Gray, Byte>(b); 处收到以下异常@“抛出了 System.ArgumentException:不支持 URI 格式。”使用替代代码,从我直接从字节到位图的地方给了我同样的错误。 (Code can be found here.)
有人知道如何解决这个错误,或者转换为位图的替代方法吗?我是 C# 和 EmguCV 的新手,非常感谢。
【问题讨论】:
标签: c# bitmap kinect emgucv writeablebitmap