Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

emgucv

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!

like image 377
Dilshan Zuhdi Avatar asked Jun 24 '13 11:06

Dilshan Zuhdi


3 Answers

I had the same problem. My inner exception was "Unable to load DLL 'opencv_core290'".

You need to copy x86 and x64 folders from "yourEmguFolder/bin" to your project's output(bin) directory. Then build project again and run.

According to emgu wiki

like image 72
Muhammed Tanriverdi Avatar answered Nov 18 '22 03:11

Muhammed Tanriverdi


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.)
like image 10
jlew Avatar answered Nov 18 '22 03:11

jlew


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"

like image 5
Subodha Charles Avatar answered Nov 18 '22 04:11

Subodha Charles