7

I'm trying to start using emgu CV open CV for C#. But I'm having trouble making it work. I'm following this guide to make simple program using emgu CV Link but I get following error: (any idea what I'm doing wrong?)

    System.TypeInitializationException was unhandled
      Message=The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
      Source=Emgu.CV
      TypeName=Emgu.CV.CvInvoke
      StackTrace:
       at Emgu.CV.Image`2..ctor(String fileName) in c:\Emgu\emgucv-windows-x86-gpu 2.4.2.1777\Emgu.CV\Image.cs:line 144
       at TEST.Form1.button1_Click(Object sender, EventArgs e) in c:\documents and settings\laci\my documents\visual studio 2010\Projects\TEST\TEST\Form1.cs:line 28
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at TEST.Program.Main() in c:\documents and settings\laci\my documents\visual studio 2010\Projects\TEST\TEST\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.DllNotFoundException
       Message=Unable to load DLL 'opencv_core242': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
       Source=Emgu.CV
       TypeName=""
       StackTrace:
            at Emgu.CV.CvInvoke.cvRedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)
            at Emgu.CV.CvInvoke..cctor() in c:\Emgu\emgucv-windows-x86-gpu 2.4.2.1777\Emgu.CV\PInvoke\CvInvoke.cs:line 166
       InnerException: 
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Laci
  • 85
  • 1
  • 1
  • 5
  • 1
    What is your code? What have you tried? Be spesific. – Soner Gönül Dec 14 '12 at 09:07
  • :( Don't know to post core in readable way... But it was simple code load image from file and convert it to another format on a button click. – Laci Dec 14 '12 at 09:14
  • possible duplicate of [Emgu.CV.CvInvoke threw an exception](http://stackoverflow.com/questions/12509582/emgu-cv-cvinvoke-threw-an-exception) – Peter O. Dec 15 '12 at 03:36

7 Answers7

9

Since Emgu.CV is just a .NET wrapper (see http://en.wikipedia.org/wiki/Wrapper_library), you need to put the native .DLL files of OpenCV in your application output directory.

You can find the required files by downloading the corresponding version of OpenCV at http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.2/OpenCV-2.4.2.exe/download

Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55
Didac Perez Parera
  • 3,734
  • 3
  • 52
  • 87
  • I did put two dlls mentioned in link in my application output directory. – Laci Dec 14 '12 at 09:16
  • 3
    Laci, when a .DLL also requires another .DLL, you will not see the another .DLL in the error message. For instance, 1.dll requires 2.dll and your C# wrapper uses 1.dll. The error message will show that 1.dll is not found, since 1.dll can not be loaded. Thus, I recommend you to add all the .DLL files of OpenCV that you think Emgu uses and, once your app compiles, try removing the non used files until you only have required files. Good luck. – Didac Perez Parera Dec 14 '12 at 09:20
  • 1
    You can also use DependencyWalker to find out which .DLL files are missing. – Didac Perez Parera Jan 13 '14 at 10:31
  • Looks like OpenCV doesn't host the 2.4.2 download anymore, but the EMGU library still depends on that? Does anyone have recommendations for getting OpenCV 2.4.2, or migrating EMGU? – bjornruffians Feb 15 '18 at 15:46
  • The below comment about copying nvcuda.dll to the bin/ directory fixed my runtime issues. I also needed DLLs from EMGU libs/ folder based on my platform. – bjornruffians Feb 15 '18 at 16:48
3

I will save you all a lot of time. for EMGU CV version 2.4.* the missing dll is "nvcuda.dll" which is not part of the Binaries of EMGU but its usually located in system32 folder (maybe you need to have nvidia driver installed, if not just look for the dll online)

  • 1
    exactly in my case. Just download nvcuda.dll from http://sourceforge.net/projects/emguexample/files/ then folow the instructions and copy nvcuda.dll into your working directory (in my case is the Debug folder - I'm using Emgu CV with Visual Studio 2012). – Lê Quang Duy Oct 21 '15 at 03:38
1

You might solve this problem by Using Dependency Walker -> http://www.dependencywalker.com/ on "opencv_core242.dll" to find any missing DLLs.

For me, It show that I didn't has tbb.dll as Thread here tbb.dll not found

Just download from https://www.threadingbuildingblocks.org/ and copy tbb*.dll to working directory or "System32" it will be fine

Community
  • 1
  • 1
Kookkoog
  • 11
  • 2
1

Old one, but I had the same problem. Turns out that 2.4.0 has GPU integration and if you don't have an Nvidia card, nvcuda.dll is missing and opencv_core242.dll fails to load. Tried everything, the only solution was to go back to 2.3.0 and everything worked fine.

smirkingman
  • 6,167
  • 4
  • 34
  • 47
0

Exactly as the error states - it can't find the native DLL in the working directory of your applcation. Make sure the opencv_core242.dll library is copied to the output directory and working directory of your application.

Vaughan Hilts
  • 2,839
  • 1
  • 20
  • 39
  • Are you sure it's in the WORKING directory? You can verify this with "Environment.WorkingDirectory". Check the path and check to see if the DLL exists along that path. – Vaughan Hilts Dec 14 '12 at 09:20
0

Download dependency walker from http://www.dependencywalker.com/ and open the .dll claiming to not load. Then look for the dependencies, if one or more are missing from the directory of the app of even your system folder (system32 or syswow64) then they need to be in there.

Maks3w
  • 6,014
  • 6
  • 37
  • 42
Inammathe
  • 103
  • 1
  • 5
0

here are proper steps to solve the problem.

visit : https://sourceforge.net/project/emgucv/emgucv/2.4.2/
download specific version of emgucv 2.4.2 according to your operating system like for windows x86 you can download : libemgucv-windows-x86-gpu-2.4.2.1777.exe

install it some where like C:\Emgu after that go to C:\Emgu\emgucv-windows-x86-gpu 2.4.2.1777\bin\x86 and copy all opencv dll files and paste it in your application exe output directory.

  • to remove unnecessary opencv dll files you , run your application and then press ctrl+A and try to delete the files , those files which are used by your app you will not be able to delete as your app is running and they are in use and the reset unused dll files will be deleted , other than that you can use dependency walker app (http://www.dependencywalker.com/ ) which is outdated may or may not work
user889030
  • 4,353
  • 3
  • 48
  • 51