The type initializer for 'Emgu.CV.CvInvoke'

2019-01-09 10:04发布

I'm getting this error

The type initializer for 'Emgu.CV.CvInvoke' threw an exception.

when I try to use Emgu CV. I've tried everything I can think of to fix this but it's still giving the same error, and when I click a button it shows

Object reference not set to an instance of an object.

This is the code I'm trying:

void ProcessFunction(object sender, EventArgs e)
{
    imgOrg = capturecam.QueryFrame();
    if (imgOrg == null) return;
    imgProc = imgOrg.InRange(new Bgr(50, 50, 50), new Bgr(255, 255, 255));
    imgProc = imgProc.SmoothGaussian(9);
    imageBox1.Image = imgOrg;
    imageBox2.Image = imgProc;
}

What might I have done wrong and how can I debug this further? Thanks!

标签: c# emgucv
10条回答
太酷不给撩
2楼-- · 2019-01-09 10:06

Copy and paste all the unmanaged dlls in the bin folder of your EMGU installation to where your exe file is (Release or Debug folder of your project folder).
In my case, unmanaged dlls are at "C:\Emgu\emgucv-windows-universal-cuda 2.9.0.1922\bin\x86"

查看更多
家丑人穷心不美
3楼-- · 2019-01-09 10:08

It's probably failing to load the unmanaged DLL dependencies. A couple of suggestoins:

  1. Make sure your .NET project is targeting x86 rather than AnyCPU, since you likely have the x86 build of OpenCV.
  2. Make sure the OpenCV dlls are in your PATH (or directly in the bin directory, if this is a Console/WinForms/WPF app.)
查看更多
混吃等死
4楼-- · 2019-01-09 10:13

I Had the same problem in my 32 bit machine for 3 days. I resolved this by simply copying all dlls into system32 folder from the bin and x86 folders and it worked. It looks like there are dlls that depend on other dlls and the moment you transfer all it works. I did not have time to find out which one.

查看更多
\"骚年 ilove
5楼-- · 2019-01-09 10:15

First you have to add three libraries to your project. opencv_core290.dll,opencv_highgui290.dll,opencv_imgproc290.dll. In here 290 refers that your opencv version. After that change in their property "Do not copy" to "copy always". than save your project. After that go to following location. If your machine is 64 bit than go to following folder "C:\Emgu\emgucv-windows-universal-cuda 2.9.0.1922\bin\x64" or if your using 32 bit os than go to "C:\Emgu\emgucv-windows-universal-cuda 2.9.0.1922\bin\x86" and copy all the dlls in that folder and paste that into your Your Project/bin/debug/ folder. than rebuild your project. Than it will works fine.

Best of luck!!!!

查看更多
干净又极端
6楼-- · 2019-01-09 10:20

you could using LD_LIBRARY_PATH to solve it:

  1. open the warning and check what lib your program lack

  2. locate the path

    $ locate # to find the library path

  3. In your IDE, set the environment variable LD_LIBRARY_PATH to the lib path,(I use monodevelop, the path is Run-->Run With-->Custom Parameters...)

it work quit good now :)

查看更多
闹够了就滚
7楼-- · 2019-01-09 10:21

Found this on c#,VS 2017, emgu version 3.2.0.2682

Tried a simple build on AnyCPU and received the bad format exception. So I tried x86 bad format exception because of possible suggestions in the comments. Finally I put it as x64 and it worked fine.

查看更多
登录 后发表回答