【问题标题】:SystemAccessViolation converting Drawing.Bitmap to Emgu.CV.ImageSystemAccessViolation 将 Drawing.Bitmap 转换为 Emgu.CV.Image
【发布时间】:2020-12-22 19:29:42
【问题描述】:

我需要将 Drawing.Bitmap ("_MyBitmap") 转换为 EmguCV.Image

为此,我使用以下代码:

    Dim nCVImage As New Emgu.CV.Image(Of Bgr, Byte)("c:\users\myuser\desktop\1.png")

    MsgBox("Width: " & nCVImage.Width)'this work fine!! :-)

    'Now (after the messagebox), the error is shown.        

    Stop'this is just some Stop statement for me to see to which point VB.NET executes the code when OpenCV throws the message. Stop is not hit. This means that the error must have occured in the very first line already.


    Dim m As Mat = nCVImage.Mat

    Dim imagez0 As Image(Of Gray, Byte) = m.ToImage(Of Gray, Byte)
    Dim imagez1 As Image(Of Bgr, Byte) = m.ToImage(Of Bgr, Byte)
    Dim imagez2 As Image(Of Gray, Byte) = imagez0.Canny(150, 60)

但是,第一行已经引发了异常“ImageSize 溢出”。

_MyBitmap 非常好。我可以在图片框中显示它。它的大小是 1200 x 1000 像素。

有人看到我的错误吗?

谢谢!

【问题讨论】:

  • IIRC,有一个重载接受一个包含数据字节的锯齿状数组和一个接受(宽度、高度、步幅、Scan0)的数组。要使用后者,请参阅:Analyze colors of an Image 中的注释(简而言之,从Image.LockBits 获取 ImageData,它包含您需要的属性。考虑 Stride,因为您正在创建特定类型的位图,所以转换可能需要)
  • @jimi 我的方法有什么问题?
  • 我不记得接受源 System.Drawing.Bitmap 对象的 Emgu.CV.Image() 构造函数的重载。不过,您可以指定文件位置。
  • @Jimi 你的意思是这样吗? Dim nCVImage As New Emgu.CV.Image(Of Bgr, Byte)("c:\users\myuser\desktop\1.png") 我问是因为它抛出了同样的错误。
  • @Jimi 实际上,这很奇怪。我用一些观察来扩充我的帖子。我很确定错误发生在第一行,但我不明白为什么或哪个图像似乎加载正常。

标签: vb.net emgucv


【解决方案1】:

找到解决办法:

“cvextern.dll”丢失。

我做的是下载

https://vorboss.dl.sourceforge.net/project/emgucv/emgucv/4.4.0/libemgucv-windesktop-4.4.0.4099.exe

并按照建议进行安装。

(不知道我是怎么到那里的)

我编译了以下文件:

C:\Emgu\emgucv-windesktop 4.4.0.4099\Solution\Windows.Desktop\Emgu.CV.Example.sln

然后我将 \x86\cvextern.dll 复制到我的 \Debug\x86 文件夹中。

另外,我将我的项目升级到框架 4.7.2 并使用 Nuget 的 Emug.CV v4.4.0.4099。

不确定为什么它不会自动将 cvextern.dll 放入我的应用程序目录。 完全令人不安!!!

【讨论】:

    猜你喜欢
    • 2017-05-25
    • 2020-02-09
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 2020-07-03
    • 1970-01-01
    相关资源
    最近更新 更多