tesseract: Unable to reproduce compatible binaries of tesseract

I’m trying to produce the same tesseract and leptonica binaries as supplied in \src\Tesseract\x64.

These binaries works but I would like to test parallel OCR perfomance without OpenMP (my case is to recognize simultaneously a few dozens of rather small images, trying to do it in parallel loop).

I have tried to build master branch of tesseract according to their wiki (used cmake). Unfortunately, the produced dll’s:

ambiguous_words.exe*                                          pvt.cppan.demo.freetype-2.9.1.dll*                 pvt.cppan.demo.tiff-4.0.9.dll*
classifier_tester.exe*                                        pvt.cppan.demo.gnome.glib.glib-2.56.1.dll*         pvt.cppan.demo.unicode.icu.common-62.1.0.dll*
cntraining.exe*                                               pvt.cppan.demo.gnome.glib.gobject-2.56.1.dll*      pvt.cppan.demo.unicode.icu.data-62.1.0.dll*
combine_lang_model.exe*                                       pvt.cppan.demo.gnome.pango.pango-1.42.3.dll*       pvt.cppan.demo.unicode.icu.i18n-62.1.0.dll*
combine_tessdata.exe*                                         pvt.cppan.demo.gnome.pango.pangocairo-1.42.3.dll*  pvt.cppan.demo.webp-0.6.1.dll*
dawg2wordlist.exe*                                            pvt.cppan.demo.gnome.pango.pangoft2-1.42.3.dll*    pvt.cppan.demo.weltling.winlibs.libffi-3.2.1.dll*
lstmeval.exe*                                                 pvt.cppan.demo.gnu.fribidi.fribidi-1.0.5.dll*      pvt.cppan.demo.xz_utils.lzma-5.2.4.dll*
lstmtraining.exe*                                             pvt.cppan.demo.gnu.gettext.intl-0.19.8.dll*        set_unicharset_properties.exe*
mftraining.exe*                                               pvt.cppan.demo.gnu.iconv.libcharset-1.15.0.dll*    shapeclustering.exe*
pvt.cppan.demo.behdad.harfbuzz-1.8.8.dll*                     pvt.cppan.demo.gnu.iconv.libiconv-1.15.0.dll*      tesseract.exe*
pvt.cppan.demo.bzip2-1.0.6.dll*                               pvt.cppan.demo.jpeg-9.2.0.dll*                     tesseract40.dll*
pvt.cppan.demo.cairographics.cairo-1.15.12.dll*               pvt.cppan.demo.madler.zlib-1.2.11.dll*             text2image.exe*
pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll*             pvt.cppan.demo.openjpeg.openjp2-2.3.0.dll*         unicharset_extractor.exe*
pvt.cppan.demo.expat-2.2.5.dll*                               pvt.cppan.demo.pcre.pcre-8.42.0.dll*               wordlist2dawg.exe*
pvt.cppan.demo.freedesktop.fontconfig.fontconfig-2.13.0.dll*  pvt.cppan.demo.png-1.6.35.dll*

are causing DllNotFoundExceptions (of course, I have changed libraries names constants in C# sources). Trace output (couldn’t make the actual trace output work, replaced with console writes):

C:/Users/arxen42/source/repos/OcrTest/OcrTest/bin/Debug/OcrTest.exe
INF Current OS: Windows
INF Current OS: Windows
INF Current OS: Windows
INF Current platform: x86
INF Custom search path is not defined, skipping.
INF Checking executing application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Current platform: x86
INF Current OS: Windows
INF Custom search path is not defined, skipping.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
INF Checking executing application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Current platform: x86
INF Custom search path is not defined, skipping.
INF Checking executing application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF Checking current application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF Checking current application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
INF Current platform: x86
INF Custom search path is not defined, skipping.
INF Checking executing application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF Checking current application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF No bin directory exists under the current application domain's location, skipping.
INF Checking working directory 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF No bin directory exists under the current application domain's location, skipping.
INF Checking working directory 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF Checking current application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF No bin directory exists under the current application domain's location, skipping.
INF Checking working directory 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF No bin directory exists under the current application domain's location, skipping.
INF Checking working directory 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF Current platform: x86
INF Custom search path is not defined, skipping.
INF Checking executing application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF Checking current application domain location 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.
INF No bin directory exists under the current application domain's location, skipping.
INF Checking working directory 'C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug' for 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll' on platform x86.
INF Trying to load native library 
"C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll"...
ERR Failed to load native library "C:\Users\arxen42\source\repos\OcrTest\OcrTest\bin\Debug\x86\pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll".
Check windows event log.

Необработанное исключение: System.AggregateException: Произошла одна или несколько ошибок. ---> System.Reflection.TargetInvocationException: Адресат вызова создал исключение. ---> System.DllNotFoundException: Failed to find li
brary "pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll" for platform x86.
   в InteropDotNet.LibraryLoader.LoadLibrary(String fileName, String platformName)
   в InteropRuntimeImplementer.LeptonicaApiSignaturesInstance.LeptonicaApiSignaturesImplementation..ctor(LibraryLoader loader)
   --- Конец трассировки внутреннего стека исключений ---
   в System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   в System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   ...

The CPU is Core i7-3520M (no AVX2 support), but the produced tesseract.exe works properly (version info, actual recognition), Debug build (should have solved AVX2 problem, right?) doesn’t work as well. There is no difference in the results when using x64 and x86 builds.

Tried to run on the newer laptop with Core i3 5010U, same results.

Sorry for such a dumb question, but I can’t figure out how the commits like 231992a9de2c3a1bc7056b7e3fb7b59c532c3a64 are produced. I think the brief hint on wiki would be nice, so that information will be esily accessible.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Yes, I changed that flags. Below are the steps needed to build libtesseract compatible with wrapper. AFAIK github does not allow PR for wikis, so I will leave it here. If the following information is correct, it might be a good idea to create the wiki page, so that this information will be on a notable place.

Building libtesseract and leptonica

Sometimes custom versions of tesseract library might be needed. To produce the valid libtesseract and leptonica dll’s, each library must be built with statically linked dependencies and then placed in x64/x86 directory from where the C# wrapper will load it.

Note: AVX optimizations are currently disabled for the builds supplied with this wrapper as they are known to cause DllNotFoundException on some configurations. Using custom build might increase perfomance on modern CPU’s.

Libtesseract

See the Compiling#windows tesseract page for the full description of the building process and this issue which describes static linking.

Clone master branch of tesseract repo and edit cppan.yml file:

local_settings:
    short_local_names: true <-- optional, uncomment to produce dll without long prefixes in filename
    generator: Visual Studio 15 2017 Win64 <-- Uncomment and set your generator
    use_shared_libs: false
projects:
    libtesseract:
        shared_only: true

Run (you need to have cppan.exe be in your $PATH):

cppan --build .

cppan will create link to the Visual Studio solution and build it. Alternatively, cppan --generate . can be used to only generate solution. Then, build can be started manually from the Visual Studio (building only libtesseract project is enough).

Note: cppan generated Win32 project for me despite Visual Studio 15 2017 Win64 generator. Neither setting current_build: vs2017_64 nor setting generator under build section worked, so I had to change

builds:
    vs2017:
        generator: Visual Studio 15 2017 Win64

libtesseract.dll will be in the bin directory of the generated solution.

Leptonica

git clone https://github.com/DanBloomberg/leptonica.git
cd leptonica
cppan
mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" -DCPPAN_BUILD_SHARED_LIBS=0 ..
cmake --build . --config Release

The produced leptonica dll will reside in the bin directory of the generated solution.