r1me / TTesseractOCR4

Object Pascal binding for tesseract-ocr - an optical character recognition engine
MIT License
145 stars 46 forks source link

64-bit DLL? #17

Closed tedsmith closed 3 years ago

tedsmith commented 3 years ago

In my endeavors to resolve issue https://github.com/r1me/TTesseractOCR4/issues/16 I am thinking part of my problem might be the expectation of 64-bit compilation for the API I am using to interract with TesseractOCR4. But to use the 64-bit edition, I need 64-bit DLL's of this library.

Do you know where I might find those? Compiling them from source on WIndows looks painfully tedious, with several other tools requring download and installation etc.

r1me commented 3 years ago

https://digi.bib.uni-mannheim.de/tesseract/

tedsmith commented 3 years ago

Hi and thanks for the link above.

My problem is that I am using this library to create a plugin that utilises a commercial API for a mainstream tool. That tool does come in both 32 and 64-bit versions, but, most users use the 64-bit version and as such my "plugin" needs to come in both a 32-bit but especially a 64-bit version.

For 32-bit, everything is working well with what is provided here. But, for 64-bit, I have first installed the 64-bit version of the MS Redistributable package. I have then gone and compiled 64-bit DLL's of BOTH the Leptonica DLL and TesseractOCR DLL using MSYS2. Specifically, these two :

https://packages.msys2.org/package/mingw-w64-x86_64-leptonica?repo=mingw64 https://packages.msys2.org/package/mingw-w64-x86_64-tesseract-ocr?repo=mingw64

by triggering the following pacman commands :

pacman -S mingw-w64-x86_64-tesseract-ocr pacman -S mingw-w64-x86_64-leptonica

These seem to have executed OK and I have two DLL's that I have copied to the bin subfolder and I have replaced the names of these DLL's in the tesseractocr.consts file, as follows :

{$IFDEF FPC}
type
  PUTF8Char = PAnsiChar;
{$ENDIF}

{$DEFINE USE_CPPAN_BINARIES}

const
  {$IFDEF USE_CPPAN_BINARIES}
  libleptonica = {$IFDEF Linux}'libpvt.cppan.demo.danbloomberg.leptonica-1.76.0.so'{$ELSE}'libleptonica-5-x64.dll'{$ENDIF}; // 'pvt.cppan.demo.danbloomberg.leptonica-1.76.0.dll'{$ENDIF};
  libtesseract = {$IFDEF Linux}'libpvt.cppan.demo.google.tesseract.libtesseract-master.so'{$ELSE}'libtesseractocr-4-1-x64.dll'{$ENDIF}; // 'pvt.cppan.demo.google.tesseract.libtesseract-master.dll'{$ENDIF};
  {$ELSE}
  libleptonica = {$IFDEF Linux}'liblept.so.5'{$ELSE}'liblept-5.dll'{$ENDIF};
  libtesseract = {$IFDEF Linux}'libtesseract.so.4'{$ELSE}'libtesseract-4.dll'{$ENDIF};
  {$ENDIF}        

I have used the 64-bit version of Lazarus, using "Default" in the target sections of the project (as that will create a 64-bit exe or DLL when running on 64-bit Windows) to re-compile my "plugin" for the commercial tool. All compiles OK. But when I run it with the debugger, the LoadLibrary call now fails here:

if (hTesseractLib = 0) then raise Exception.Create('Tesseract library is not loaded');

I have uploaded said DLL's in case anyone can prove their validity for use with this library. And if I've just made a mistake somewhere then maybe they can be used to help others who need them. I am guessing\assuming its something to do with CPPAN? I don't even know what that is, but I haven't used it and according to what I could find it looks like CPPAN no longer exists, or has been taken over by a networks project? That said I did also try commenting out the compiler ifdef for cppan and replacing the bottom two variable declaration lines with the names of my new 64 bit dll instead (as the existing entries suggest that's why they are there) but sadly that also did not work.

Is there anything anyone can suggest to get this working? Or is getting a 64-bit DLL of BOTH libraries too tricky?

Many thanks DLLs.zip

tedsmith commented 3 years ago

It turned out my calling method was off. By switching from LoadLibrary to using the Windows API LoadLibraryA function and passing the full path to the 64-bit DLL, it works.