header photo

'Emgu.CV.Invoke' threw an exception? -SOLUTION

June 22, 2011

 LEARNING OBJECTIVE:

'Emgu.CV.CvIvoke' threw an exception!!!?!
Working in EmguCV? and you also got this BUGGING error? especially when working with a web cam?

<<<
 You might have tried various sites to find the solution to this problem. we did and trust me we couldn't find anything that worked or provided easy guidance!
Below I've provided you with a simple step-by-step guide to solve your problem. >>>

Photobucket

The image above is taken from a
Camera Capture application we have been making in this level 1 tutorial
This error here is telling you that your application just CAN'T connect to your Web cam!
 

A.) SOME CHECKS YOU  *MUST* DO BEFOREHAND:
Don't worry, here are some checks for you to do:

1.Are the Emgu CV's own examples related to your project working perfectly? 
you can find those examples in the Emgu.CV.Example  folder where you have installed Emgu CV.
Go there and open the example's .csproj file(or .sln file if its there).
It will open the Example's Solution for you. debug this solution and see if the application works or not.
if its related to a web cam and is showing you stream from your webcam perfectly, then congratulations, at least your camera's working!

2.Did you have any OTHER errors at build or debug?
if your code is error free, then there should be no errors in the project's Error List at the time you build and debug project.
if there are errors then you just made a mistake somewhere most probably. resolve those issues first until only 'Emgu.Cv.Invoke' error remains.

3. Did you add the required EmguCV .dll files to your Project's 'References'?
if not then you must! in case you don't know how to add them, then SEE STEP 3 & 4 of THIS TUTORIAL.
Which ones to add other than the 3 mentioned there?
That depends on what project you're doing.you should find out what functionality requires which dll references.
Once you've added your references,then Debug your solution. The .dll files will be added to the folder where your .exe file is; So See your Debug folder(or Release folder if you have one), the Emgu.Cv .dlls will be present there. Like in the CameraCapture's Debug folder (second image below.it is from the same level-1 tutorial).

B.) THE ACTUAL SOLUTION:
As we mentioned, the people over the internet just talked about adding managed and unmanged code and .dlls as a solution and what not.
well they were RIGHT.
BUT all they missed was the fact that WHICH .dlls they were talking about and exactly where n how to put them! so here's the SIMPLE way   to do it:

 Step 1: Add the Managed code to the folder where your .exe file is: 
I asked you to add the Emgu References, right?  that's it! they're the managed code you MUST add to your project. that's why i made you do that in the before coming to this step!

Step 2: Add the Unmanaged code to the folder where your .exe file is:

THIS IS THE SOLUTION TO YOUR PROBLEM DEAR FRIENDS!
there are some opencv_xxx220.dlls in the bin folder of EmguCV directory.other than managed dlls we talked about, these are also NECESSARY to be present with your .exe file so that application works perfectly! 

see the image below? that's where you can get them. 
Photobucket

which ones to add to you project? 
well for Camera application these 2 as marked above are required: opencv_core220.dll andopencv_highgui220.dll. for other applications,i haven't much experience with yet so don't exactly know which others along with these you might have to add. so as a crude solution to this problem, just copy-paste all the opencv_xxx220.dll

Now paste it in your project's folder where your .exe file will execute, i.e the DEBUG folder, as shown below just paste the dlls you copied

Photobucket

VERY IMPORTANT! - Which is the folder where your .exe file is?
well mostly & usually  its the DEBUG folder in you project's BIN folder. as we have in our CameraCapture project.
but in the BIN folder,some of you might also have a RELEASE folder along with DEBUG   folder.
in this case, copy-paste the unmanaged code(the opencv_xxx220.dlls) to your Release folder as well!

Step-3: Now once again open your solution file, and Debug your project. this time you should be able to see the camera working (for our camera capture project)and showing a video stream in the form! or your own application finally running without any error :)

Photobucket 

if so then,
CASE SOLVED!!!
CONGRATULATIONS!!! ^_^

--------------------------------------------------------------------------------------------------------------------------------------------------------------
IF YOU LIKE THIS TUTORIAL. PLEASE LEAVE YOUR KIND COMMENTS BELOW :)

BUT ASK YOUR QUESTIONS ONLY AT THE FOLLOWING LINK. ANY QUESTIONS IN COMMENTS WILL BE IGNORED.

SEE YOU IN THE NEXT TUTORIAL :)

**********************
Tutorial by: Mahvish

 

which ones to add other than the 3 mentioned here,you should find that out in regards to what your project is doing

Go Back

I tried to run the program CameraCapture. Resolved all the errors and I got the form. When I clicked on Start Capture button I got the 'Emgu.CV.CvIvoke' error, Can you think of anything else. I have all the dll files as mentioned in Level 1.

Thanks in advance.

Awesome solution. TY

never mind, its working already. i just downloaded emgucv for win xp 64bit :D



Comment