This is a very common problem it is down to the correct dll's not being present in the output folder. EMGU is a wrapper for opencv which means you need the EMGU dll for the c# code (that has been written to deal with the images) and the dll from opencv. Now as Opencv is in fact c++ they can't be referenced as normally in c#.
To see what files are missing when the error pops up at the bottom are Actions
: if you select View Details
and expand System.TypeInitializedException
using the small arrow to the left. The InnerException
will show you which dll.
Now the easy way is to go into "bin
folder of the EMGU extraction folder and copy all of the .dll files except for those starting with EMGU and paste them into your bin\Debug
folder of your c# project.
Now this make your release harder however makes the project less clutered in Visual Studio
More complicated but preferred start with opencv_core220.dll and opencv_imgproc220.dll. These are the two minimal items you will require to load and display an image.
Right click on your project in solution explorer and select Add >> Existing Item...
or menu item Project>Add Existing Item
Find the two files and add them to your project.
Now select them within the solution explorer and go to there properties. You need to change the Copy to Output Directory
option to Copy Always
This will copy the dll every time you compile your project be it a release or debug compilation.
The two suggested dll's will not do a majority of the more complex algorithms. You will get an error of Unable to load cvextern.dll in this case you will have to add a majority of the other opencv dll's. You will need all but:
Unless you are using CUDA then you will need the first two ZedGraph is used to plot graphs in c# and usually copied automatically anyway.
There are additional instructions here if you get stuck:
Hope this Help,