【问题标题】:Converting WriteableBitmap to Bitmap for use in EmguCV将 WriteableBitmap 转换为 Bitmap 以在 EmguCV 中使用
【发布时间】: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&lt;Gray, Byte&gt; img = new Image&lt;Gray, Byte&gt;(b); 处收到以下异常@“抛出了 System.ArgumentException:不支持 URI 格式。”使用替代代码,从我直接从字节到位图的地方给了我同样的错误。 (Code can be found here.)

有人知道如何解决这个错误,或者转换为位图的替代方法吗?我是 C# 和 EmguCV 的新手,非常感谢。

【问题讨论】:

    标签: c# bitmap kinect emgucv writeablebitmap


    【解决方案1】:

    结果所有代码都很好。我不太确定错误的技术细节,但是在尝试在 WriteableBitmap 中写入 Gray16 图像(将被转换为 Emgu 图像)时收到错误。支持 Bgr565 或其他格式,我相信Gray16 没有被 MS 完全实现。如果做 WinForms 应用,Format16bppGray 也会报同样的错误。

    我决定在将位图编写为 Bgr555 时使用 Gray Emgu 图像,这会产生很多噪音,但总比没有好。

    【讨论】:

      【解决方案2】:

      我有同样的问题。 “不支持 URI 格式”的异常与位图无关,但与加载所需的 opencv dll 无关。我刚刚将 x86 和 x64 文件夹(包括 opencv_core290.dll 等)复制到了我的可执行目录中。

      【讨论】:

      • 这实际上是针对许多不同错误而引发的一揽子错误声明。就我而言,它是位图格式,但它也会发生在不正确的 dll 加载中,例如在您的情况下。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-23
      • 2015-01-05
      • 2013-06-22
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 2012-01-12
      相关资源
      最近更新 更多