charlesw / tesseract

A .Net wrapper for tesseract-ocr
Apache License 2.0
2.26k stars 741 forks source link

Failed to find library "liblept168.dll" for platform x86. #181

Closed FlorinMax closed 9 years ago

FlorinMax commented 9 years ago

I receive this error and I cannot pass it. I am try to use Tesseract with coded ui project and it still display the bellow error. I passed through the items from the https://github.com/charlesw/tesseract/wiki/Error-2, and I still receive the error . There is any solution for this ? Tesseract is working only for console projects? or also for coded ui ?

If I run the same code with a console project it is working. But if I am using a coded ui project it is not working.

public void readOCR() { var pathToLangFolder = @"D\OCRTest\Tesseract-OCR"; var fileName = @"C:\banner2.png";

        using (var engine = new TesseractEngine(pathToLangFolder, "eng", EngineMode.Default))
       // using (var engine = new TesseractEngine(null, "eng"))
        {
            using (var image = new Bitmap(fileName))
            {
                using (var pix = PixConverter.ToPix(image))
                {
                    using (var page = engine.Process(pix))
                    {
                        Console.WriteLine(page.GetMeanConfidence() + " : " + page.GetText());
                    }
                }
            }
        }
    }

Result Message: Test method OCRTest.CodedUITest1.CodedUITestMethod1 threw exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Failed to find library "liblept168.dll" for platform x86. Result StackTrace:
at InteropDotNet.LibraryLoader.LoadLibrary(String fileName, String platformName) at InteropRuntimeImplementer.LeptonicaApiSignaturesInstance.LeptonicaApiSignaturesImplementation..ctor(LibraryLoader loader) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args) at InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]() at Tesseract.Interop.LeptonicaApi.Initialize() at Tesseract.Interop.TessApi.Initialize() at Tesseract.Interop.TessApi.get_Native() at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode, IEnumerable`1 configFiles) at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode) at OCRTest.UIMap.readOCR() in d:\Automation Tests\OCRTest\OCRTest\UIMap.cs:line 28 at OCRTest.CodedUITest1.CodedUITestMethod1() in d:\Automation Tests\OCRTest\OCRTest\CodedUITest1.cs:line 28

VMaxx commented 9 years ago

do you have the d:\Automation Tests\OCRTest\OCRTest\x86 and d:\Automation Tests\OCRTest\OCRTest\x64 folders setup with these files: liblept168.dll liblept168.so liblept170.dll libtesseract302.dll libtesseract302.so libtesseract303.dll

charlesw commented 9 years ago

Also enable the System.Diagnostics source for tesseract as indicated on the "Error 2" page. This will tell you where it's looking for the tesseract files. Note for 2.3 on windows only liblept168.dll and libtesseract302.dll are needed and if the program is only going to run using the x86 architecture you won't need the x64 libraries though leave them in for now until you have it working.

Finally have you tried running the samples or integration (nunit) tests that are included in the source? They do work out of the box provided you've installed the VS 2012 runtime for the correct platform. If they're throwing the same error it's probably a good indication that the problem is environment related.

FlorinMax commented 9 years ago

I have only two files from the list: liblept168.dll and libtesseract302.dll . from where should I take the other ones ?

FlorinMax commented 9 years ago

So, here are the logs from System Diagnostic

Tesseract Information: 0 : Current OS: Windows Tesseract Information: 0 : Current platform: x86 Tesseract Information: 0 : Custom search path is not defined, skipping. Tesseract Information: 0 : Checking executing application domain location 'D:\Automation Tests\OCRTest\TestResults\FLORIN-PC 2015-06-19 09_46_02\Out' for 'liblept168.dll' on platform x86. Tesseract Information: 0 : Checking current application domain location 'D:\Automation Tests\OCRTest\TestResults\FLORIN-PC 2015-06-19 09_46_02\Out' for 'liblept168.dll' on platform x86. Tesseract Information: 0 : No bin directory exists under the current application domain's location, skipping. Tesseract Information: 0 : Checking working directory 'D:\Automation Tests\OCRTest\TestResults\FLORIN-PC 2015-06-19 09_46_02\Out' for 'liblept168.dll' on platform x86.

From what I see, it doesn't look in the correct path for our dll. It looks in the TestResults of the project. This is strange. So I have to change the main path , I guess... or not ?

I saw something on this issue to how to change the path : https://github.com/charlesw/tesseract/issues/103. But I didn't have any success

charlesw commented 9 years ago

Sorry, I missed your replies. My guess is that test framework (MSTest?) is not copying the native tesseract (libtesseract302.dll) and leptonica (liblept168.dll) libraries to the test results directory (D:\Automation Tests\OCRTest\TestResults\FLORIN-PC <timestamp>\Out) along with the other dlls. The easiest way to fix this, if you can't get the native dlls to be copied across too, would be to change the path to a hard coded value BEFORE any tests are run. The diagnostic log will say if it loaded from the custom search path.

FlorinMax commented 9 years ago

Yes, it is MS for Test. So , I used your first solution and it works. Thx for help.