3

In my winforms application I need to use some Emgu.CV libraries (I have installed Emgu 2.9).

Problem is that I get the following error:

System.TypeInitializationException was unhandled
     HResult=-2146233036
     Message=The type initializer for 'Emgu.CV.OCR.Tesseract' threw an exception.
     Source=Emgu.CV.OCR
     TypeName=Emgu.CV.OCR.Tesseract
     StackTrace:
         at Emgu.CV.OCR.Tesseract..ctor(String dataPath, String language, OcrEngineMode mode)
         at ANPR.LicensePlateDetector..ctor(String dataPath) in c:\Users\blabla\Visual Studio 2012\Projects\ANPR\ANPR\LicensePlateDetector.cs:line 30
         at ANPR.Form1..ctor() in c:\Users\blabla\Visual Studio 2012\Projects\ANPR\ANPR\Form1.cs:line 22

   InnerException: System.TypeInitializationException
   HResult=-2146233036
   Message=The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
   Source=Emgu.CV
   TypeName=Emgu.CV.CvInvoke
   StackTrace:
        at Emgu.CV.CvInvoke.CV_MAKETYPE(Int32 depth, Int32 cn)
        at Emgu.CV.OCR.Tesseract..cctor() in c:\Emgu\emgucv-windows-universal-cuda 2.9.0.1922\Emgu.CV.OCR\Tesseract.cs:line 26

   InnerException: System.DllNotFoundException
        HResult=-2146233052
        Message=Unable to load DLL 'opencv_core290': 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-universal-cuda 2.9.0.1922\Emgu.CV\PInvoke\CvInvoke.cs:line 266

This happens when trying to instantiate a new Tesseract object:

var tesseract = new Tesseract("", "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);

Since referencing "opencv_core290" does not work, I tried the workaround provided here. Basically, I copied the .dll to my project, added it by using "Add existing resource" and modified it's property to "Copy always". This did not work however. Thanks for any help!

Mirel Vlad
  • 2,032
  • 3
  • 27
  • 35

3 Answers3

9

I had this problem too. You should copy DLLs in x86 or x64 folders from "yourEmguFolder/bin" to your project's output directory. Then build project again and run.

I solved it according to the description on this page EMGU WIKI

Community
  • 1
  • 1
Grzegorz Pasnik
  • 164
  • 2
  • 7
  • but what to do when you are publishing your project. where to put these unmanaged dlls –  May 03 '14 at 12:39
  • that's a "brute force" solution since you don't need all the files, though +1 for reaching the objective – chouaib May 28 '14 at 02:58
8

Exactly,the opencv dlls should be present in your applications bin\debug or bin\release folder. The main thing you have to care about is that the folder structure for dlls for x64 and x86 dlls should be maintained.

i.e Copy both x86 and x64 folders from your emgu\bin folder to the debug folder of the application as it is.

For publishing - Add these two folders to your project in VS and then set their properties to "Copy Always", which will automatically take care of the folder structure.

I too faced the same issue and this solution worked for me.

Kartik Sharma
  • 363
  • 2
  • 10
1

When I add opencv_core290.dll, opencv_highgui290.dll, opencv_imgproc290.dll, I had a same problem below:

System.DllNotFoundException: Unable to load DLL 'opencv_core290': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Emgu.CV.CvInvoke.cvRedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)

After figuring out this problem, I added one dll file, named cudart64_55.dll, and solved the problem.

고승현
  • 46
  • 2