Recent

Author Topic: [SOLVED] Difficulties with TTesseractOCR4 and LoadLibrary Call  (Read 4282 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Hi all

Just trying to check where things are wrong here. I am trying to launch the example demo of the TTesseractOCR4 library (https://github.com/r1me/TTesseractOCR4) using Lazarus 2.0.10 and FPC 3.2.0.

I have all the DLL's copied to /bin folder as directed, specifically, 'pvt.cppan.demo.google.tesseract.libtesseract-master.dll'. And I have checked that its name in my folder matches how it is written in code. I also have the 'tessdata' folder setup and I downloaded the files stated into that.

The example compiles OK, and I try to run the exe from the root of the bin folder as directed, where the DLLs are, and where the tessdata fiolder is, and where the sample file is. But, it keeps throwing an exception because LoadLibrary is failing to load the 'pvt.cppan.demo.google.tesseract.libtesseract-master.dll' library.

The syntax in the project on Line 469 of tesseractocr.capi.pas shows :

Code: Pascal  [Select][+][-]
  1. hTesseractLib := LoadLibrary({$IFDEF FPC}libtesseract{$ELSE}PChar(libtesseract){$ENDIF});
  2.     if (hTesseractLib <> 0) then  ...
  3.  
   
and libtesseract is populated by Line 38 in tesseractocr.consts.pas :

Code: Pascal  [Select][+][-]
  1. {$DEFINE USE_CPPAN_BINARIES}
  2.  
  3. const
  4.   {$IFDEF USE_CPPAN_BINARIES}
  5.   libleptonica = {$IFDEF Linux}'libpvt.cppan.demo.danbloomberg.leptonica-1.76.0.so'{$ELSE}'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll'{$ENDIF};
  6.   libtesseract = {$IFDEF Linux}'libpvt.cppan.demo.google.tesseract.libtesseract-master.so'{$ELSE}'pvt.cppan.demo.google.tesseract.libtesseract-master.dll'{$ENDIF};
  7.   {$ELSE}
  8.  

Can anyone see why the compiled exe might not be working and throwing the error 'Tesseract library is not loaded' as defined in Line 163 of tesseractocr.pas? More to the point, do any of you have the time to try it to see if the same thing happens on your systems?

Many thanks
« Last Edit: March 12, 2021, 10:49:02 am by Gizmo »

balazsszekely

  • Guest
Re: Difficulties with TTesseractOCR4 and LoadLibrary Call
« Reply #1 on: March 10, 2021, 03:13:48 pm »
The usual suspect is bitness. You're trying to load a 64 bit dll into a 32 bit application or vice versa. If this not solve the issue, please try the following:
Code: Pascal  [Select][+][-]
  1. hTesseractLib := LoadLibrary({$IFDEF FPC}libtesseract{$ELSE}PChar(libtesseract){$ENDIF});
  2. f (hTesseractLib <> 0) then
  3. begin
  4.   //....
  5. end
  6. else
  7.   ShowMessage(SysErrorMessage(GetLastError))
  8.  

What is the error message?

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: Difficulties with TTesseractOCR4 and LoadLibrary Call
« Reply #2 on: March 10, 2021, 03:22:18 pm »
Ah, of course. That makes sense; the example Lazarus project itself was saved as Win32 that I had then changed to 'Default' (thus x64) already. So after reading your note I hoped that if I reverted it back to Win32 and CPU to i386 and recompile it would then work. But sadly it still does it even as a 32-bit exe

The error is :

An unhandled exception occurred at $0042E2F3:
Exception: Tesseract library is not loaded

UPDATE : Tried deleting, re-downloaded, kept CPU and Target OS as Win32 and i386, to compile a 32-bit exe. Compiled it and then re-executed. Same error though. The DLL's are the ones supplied with the project in the tessdata-master.zip file which I assume must be 32-bit too if the project is. 
« Last Edit: March 10, 2021, 03:36:40 pm by Gizmo »

balazsszekely

  • Guest
Re: Difficulties with TTesseractOCR4 and LoadLibrary Call
« Reply #3 on: March 10, 2021, 05:17:23 pm »
It works here...
1. Extract dlls to the bin folder(screenshot1)
2. Extract https://github.com/tesseract-ocr/tessdata/ to "..\bin\tessdata\"
3. Build "..\examples\lazarus-console-simple\lazarus-console-simple.lpi"
4. Start cmd, change folder to "..\bin\", type lazarus_console_simple, then press enter(screenshot2)

olly

  • New Member
  • *
  • Posts: 42
Re: Difficulties with TTesseractOCR4 and LoadLibrary Call
« Reply #4 on: March 10, 2021, 05:23:57 pm »
Unrelated to your issue, but I built a single binary with basic tesseract exports here:
https://github.com/ollydev/libTesseract

Something like this should work:
Code: Pascal  [Select][+][-]
  1. function Tesseract_Init: Int32(ptr: Pointer; datapath, language: PChar); external 'libtesseract32.dll';
  2. //etc...
Could be useful.

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: Difficulties with TTesseractOCR4 and LoadLibrary Call
« Reply #5 on: March 10, 2021, 08:02:39 pm »
GetMem

Thank you for going to the trouble and for confirming that the issue is clearly my end. That helps me a lot.

Can I ask what your project options were in regard to 'Config and target'? I am using Windows 10 x64, and using Lazarus 2.0.10 and have both the 32 and 64-bit compilers. So if I have project options for Target OS and Target CPU to default, it creates a 64 bit exe, 32-bit otherwise. So given we both have the same DLLs, what are you setting the "Target OS" value and "Target CPU family" with yours? Default, or changing them to something?

Olly : thanks for your input here. I do like the fact that you have both 32 and 64 bit bundled DLLs and I may resort to those. I'd like ideally to use the main project if I can for now though.
« Last Edit: March 10, 2021, 10:58:23 pm by Gizmo »

balazsszekely

  • Guest
Re: Difficulties with TTesseractOCR4 and LoadLibrary Call
« Reply #6 on: March 10, 2021, 08:14:51 pm »
Quote
Can I ask what your project options were in regard to 'Config and target'?
OS: Windows10(64 bit)
Lazarus: 2.0.12/Trunk(32 bit)
FPC: 3.2.0(32 bit)
Project Options: Default

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: [SOLVED] Difficulties with TTesseractOCR4 and LoadLibrary Call
« Reply #7 on: March 12, 2021, 10:50:42 am »
Folks

Sorry for this post. After a few days of wrestling, re-trying, and even installing the pure 32-bit Lazarus etc and still not getting anywhere, I noticed something I had not paid sufficient attention to at that is step 2 where it does say, clear as day "Microsoft Visual C++ 2017 Redistributable x86 must be installed on the computer.". I thought I had that installed, but I hadn't. As soon as I installed it, it worked!

https://go.microsoft.com/fwlink/?LinkId=746571

Sorry for wasting folks time

 

TinyPortal © 2005-2018