Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,I'm trying to use emgucv in C#.when using the following code,I got the exception "The type initializer for 'Emgu.CV.CvInvoke' threw an exception."please help me.as I'm new in this field,If any one gives me some more information,I would be so thankful.
C#
using Emgu.CV.Structure;
using Emgu.CV;

IntPtr ima = Emgu.CV.CvInvoke.cvCreateImage(s, Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_16S, 10);
Posted
Updated 29-Sep-11 8:34am
v2
Comments
C_Johnson 20-Sep-11 12:52pm    
I have written an article to help you and others ins setting up an EMGU project. It is available here

http://www.codeproject.com/KB/cs/EMGU_Image_Processing.aspx

I hope it helps
Cheers
Chris
ready to learn 22-Sep-11 10:28am    
Thanks a lot Chris.Your article helped me a lot,as I found your answer the best one,I want to ask you another guestion:"what does each class in emgucv do and how can I use them?"Is there an e-book which can help?Thanks again in advance
C_Johnson 29-Sep-11 14:21pm    
Hi Sorry I was doing a little housework re-tagging questions and I've only just found your comment. Unfortunately I can't tell you what classes do exactly what it doesn't really matter either, if you use the basic two opencv_core220.dll and opencv_imgproc220.dll you can do most simple tasks start a project with them and keep programming until you get an error asking for cvextern.dll at this point you need to add almost all of them as it looks for all of them to work. As for books on EMGU well there are none :s however there are two for opencv if you get these from a library or on-line then they can act as a guide you will hoever have to convert the code. This is easier than it sounds all cv functions are available by calling cvInvoke.FunctionName(...) hope this helps, the links for the books are: [1]http://www.google.co.uk/products/catalog?hl=en&q=Opencv+book&gs_upl=2796l4400l2l4659l7l7l0l0l0l2l199l1051l1.6l7l0&bav=on.2,or.r_gc.r_pw.&biw=1280&bih=736&um=1&ie=UTF-8&tbm=shop&cid=7984438732523221659&sa=X&ei=JrWETvn4Bo7t-gbK7ZAa&ved=0CFQQ8wIwAQ [2]http://www.google.co.uk/products/catalog?hl=en&q=Opencv+book&gs_upl=2796l4400l2l4659l7l7l0l0l0l2l199l1051l1.6l7l0&bav=on.2,or.r_gc.r_pw.&biw=1280&bih=736&um=1&ie=UTF-8&tbm=shop&cid=15231969889310013850&sa=X&ei=JrWETvn4Bo7t-gbK7ZAa&ved=0CFAQ8wIwAA

EMGU [^]

On that page, you'll find a link to the api documentation AND a tutorial.
 
Share this answer
 
Hi,

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.


METHOD 1

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 or bin\Release folder of your c# project.

Now this make your release harder however makes the project less clutered in Visual Studio


METHOD 2

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.


NOTE

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:

cudart64_32_16.dll
cufft64_32_16.dll
ZedGraph.dll

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:
http://www.emgu.com/wiki/index.php/Download_And_Installation[^]

Hope this Help,

Take Care
Chris
 
Share this answer
 
I meet the same question. I find that the program from here runs very well, but when I write the same program and download opencv_XXXX242.dll files from the latest version, it can not work. Then I delete the latest one, and add the program's file,opencv_XXXX231.dll. It run very well.
 
Share this answer
 
you need some DLLs;
to find which DLLs you need, copy all dlls from "...emgucv\bin\x86" to "...\bin\Debug" folder.
run your program.
try to delete all dll while your program is open!!
windows delete all dlls that dont used!
all remaining dlls are necessary.


for me this DLLs was needed:
cudart32_55.dll
Emgu.CV.dll
Emgu.Util.dll
opencv_core290.dll
opencv_highgui290.dll
opencv_imgproc290.dll
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900