charlesw / tesseract

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

Can't load tesseract dlls in Azure Function Environment #334

Open joshlincoln opened 7 years ago

joshlincoln commented 7 years ago

Has anyone tried using Tesseract within Azure Functions? I installed the Tesseract nuget package 3.0.2.0 into my project. I have no issue running the project and loading Tesseract locally, but when I try and run it within the Azure Function container, I get the Failed to find library "liblept172.dll" for platform x86 error. I've spoke with a engineer at Microsoft, and they say that the VS C++ 2015 Redist are installed in the environment, and as far as I know, I am copying the DLLs to the correct location.

Here is the stack trace from the exception:

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)\r\n at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)\r\n at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)\r\n at System.Activator.CreateInstance(Type type, Object[] args)\r\n at InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]()\r\n at Tesseract.Interop.LeptonicaApi.Initialize()\r\n at Tesseract.Interop.TessApi.Initialize()\r\n at Tesseract.Interop.TessApi.get_Native()\r\n at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode, IEnumerable1 configFiles, IDictionary2 initialOptions, Boolean setOnlyNonDebugVariables)\r\n at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode)\r\n at ClFunctionsOcr.TesseractAPI.TesseractOcr.PerformOcr(List`1 images) in C:\Workspace\CLFunctions\CLFunctions\ClFunctionsOcr\TesseractAPI\TesseractOcr.cs:line 28

Inner Exception:

"Failed to find library \"liblept172.dll\" for platform x86."

Anyone else have any trouble with this?

harinath141 commented 7 years ago

1.you need to install vc_resdist x64 / vc_redist x86, 2.You need dotnet framework installed. 3.Check whether your placing .dll files in bin folder 4.Check With data files of tesseract in correct path I have couple of succesfully Running application in Azure environment..

joshlincoln commented 7 years ago

I don't mean within any Azure environment VM, I mean within an Azure Function, which is some docker container managed by Azure.

AnQueth commented 6 years ago

did you ever get thus working in a function app ?

Morcatko commented 5 years ago

I was able to use v4 (Tesseract-test 4.0.0-beta15) in Azure Functions v2. The only "hack" I had to do was to set CustomSearchPath as Az Func build ouptut has slightly different folder structure than normal netstandard project and the native DLLs are not where expected by default.

InteropDotNet.LibraryLoader.Instance.CustomSearchPath = Path.GetFullPath(PathToNetDlls + "\\..");

AvailCat commented 5 years ago

https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#win32ksys-user32gdi32-restrictions

and

https://azure.microsoft.com/en-us/blog/announcing-the-public-preview-of-windows-container-support-in-azure-app-service/

You are not able to use GDI in Azure Function which used by Tesseract?

huzefaqubbawala commented 4 years ago

I was able to use v4 (Tesseract-test 4.0.0-beta15) in Azure Functions v2. The only "hack" I had to do was to set CustomSearchPath as Az Func build ouptut has slightly different folder structure than normal netstandard project and the native DLLs are not where expected by default.

InteropDotNet.LibraryLoader.Instance.CustomSearchPath = Path.GetFullPath(PathToNetDlls + "\\..");

Can you please give me the details here . It would really help if you can attach the function.cs file.

I am trying to run the tessract in azure functions and getting strange issues. I also tried running tesseract.exe in azure function but no luck.