Search code examples
vb.netemgucv

SystemAccessViolation converting Drawing.Bitmap to Emgu.CV.Image


I need to convert a Drawing.Bitmap ("_MyBitmap") to an EmguCV.Image

To do that, I use the following code:

    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)

However, the first line already raises the exception "Overflow for imageSize".

_MyBitmap is perfectly fine. I can show it in a picturebox. It's size is 1200 x 1000 pixels.

Does anybody see my mistake?

Thank you!


Solution

  • Found a solution:

    "cvextern.dll" was missing.

    What I did was to download

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

    and install it as it was suggested.

    (not sure how I got there)

    I compiled the following file:

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

    Then I copied \x86\cvextern.dll to my \Debug\x86 folder.

    Also, I upgraded my project to framework 4.7.2 and used Nuget's Emug.CV v4.4.0.4099.

    Not sure why it would not put cvextern.dll into my app dir automatically. Totally unnerving!!!