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!
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"
It's probably failing to load the unmanaged DLL dependencies. A couple of suggestoins:
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.
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!!!!
you could using
LD_LIBRARY_PATH
to solve it:open the warning and check what lib your program lack
locate the path
$ locate # to find the library path
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 :)
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.