question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to reproduce compatible binaries of tesseract

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ArXen42commented, Aug 20, 2018

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.

0reactions
kamrapoojacommented, Aug 17, 2019

Hi, I have tried building tesseract with vcpkg also. When i build the tesseract using vcpkg it does not statically link leptonica. And when i try to load tesseract using loadlibrary function it fails. But when i build tesseract using cppan and did following changes in 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 it is generating tesseract with statically linking leptonica. This increases size of tesseract.dll.

Now my program uses both leptonica and tesseract. So i need to do loadlibrary for both leptonica and tesseract. Could not i load tesseract without statically linking leptonica. Because leptonica is already being used. Please help

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot compile tesseract on mac
I was able to go through all of the steps installing tesseract 5.0 with Homebrew as listed here # Packages which are always...
Read more >
Pytesseract : "TesseractNotFound Error: tesseract is not ...
On Windows 64 bits, just add the following to the PATH environment variable: "C:\Program Files\Tesseract-OCR" and it will work.
Read more >
ubii-processing-module-ocr
"Ubi Interact Processing Module to perform OCR tasks via Tesseract" ... :warning: On windows tesserocr can't be installed from PyPi.
Read more >
Image To Text Conversion With React And Tesseract.js ...
The inability to extract text from images was a data processing ... The image format supported by Tesseract are jpg, png, bmp and...
Read more >
Tesseract OCR (Install) 5.3.0.20221222
Compatibility with. Tesseract 3 is enabled by using the Legacy OCR Engine mode (--oem 0). It also needs traineddata files which support the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found