An unhandled exception of type 'System.TypeInitializationException' occurred in Emgu.CV.World.dll

1.2k Views Asked by At

Using Emgu.CV in Visual Studio 2015, I have a simple function to load a bitmap to an Emgu.CV.Mat onject.

    static Emgu.CV.Mat BitmapToMat(System.Drawing.Bitmap Bmp)
    {
        int stride = 0;

        System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, Bmp.Width, Bmp.Height);
        System.Drawing.Imaging.BitmapData bmpData = Bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, Bmp.PixelFormat);

        System.Drawing.Imaging.PixelFormat pf = Bmp.PixelFormat;
        if (pf == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
        {
            stride = Bmp.Width * 4;
        }
        else
        {
            stride = Bmp.Width * 3;
        }

        /*Exception thrown in next line...*/
        Emgu.CV.Image<Emgu.CV.Structure.Bgra, byte> cvImage = new Emgu.CV.Image<Emgu.CV.Structure.Bgra, byte>(Bmp.Width, Bmp.Height, stride, (IntPtr)bmpData.Scan0); 

        Bmp.UnlockBits(bmpData);

        return cvImage.Mat;
    }

An unhandled exception of type 'System.TypeInitializationException' occurred in Emgu.CV.World.dll

In an find so many videos and tips in the internet, that I have to take care if I'm using x64 for the x64 library, that I have to copy all the cvxxx.dlls to the folder of the executable - but I still this message occures. And on the other side, coping all the dlls to this folder means, to copy about 500 MB - that can't be it, If I only want to create an Emgu.CV.Mat object.

I have the impression, that many of those guys didn't know exactly what they did.

I downloaded the library from here: https://sourceforge.net/projects/emgucv/files/emgucv/3.3/

I chose the first file named libemgucv-windesktop_x64-cuda-3.3.0.2826.zip.selfextract.exe

Can anybody explain me, why I get this error and how can I fix it without blind coping all the libraries.

I also defined the path, where the dlls from Emgu are stored (the x64 folder) to my Environmentalvariable Path

Regards and thank you, Jan

EDIT: I have futher information. Executing the compiled Executable, I get the message, that he cannot find cvextern.dll. But it's contained in the folder of the executable?!?

enter image description here

1

There are 1 best solutions below

0
On

Ok, got it. I downloaded the latest version 3.3.0 - and in this version - however - the problematic file has just 4.8 MB.

The solution was, to go back to version 3.2.0.2682 - here, the file cvextern.dllhas 13.1 MB !!! Now, everything works fine!