Delphi / Tesseract OCR: Can someone help me get this new DLL working in Delphi?

There is a large open source OCR component that Google is developing: http://code.google.com/p/tesseract-ocr/

They have a new version (version 3) in early October 2010.

But this new version no longer has a working C shell, and it’s up to someone from the Delphi community to make it work from within Delphi - I try to do this because I feel very bad and no one else is in a hurry, but I don’t know what I do when it comes to DLLs and converts C to Delphi. This is where I could use your help.

The keys I chose are what I need for Dependency Walker to somehow prevent "name manipulation" (I don't know what that means). The actual DLL API methods are in the C files - and presumably the DLL function names that you see in Dependency-Walker will correspond to the functions in the API file.

Here you will need to help: You will need a folder with tessdll.dll, and leptonlib.dll just should be there. You will need a subfolder called "tessdata", and inside the folder will be your "language data files" - [check the download page on the site]

Here's the Windows installer so you can see the DLL in action: [check the download page on the site]

To get this working for Delphi, you get the executable in the same folder as the DLL. Then you need to know what you need to call in the DLL, and for this you can look in the source C files: [check the source files on the download page on the site]

Thanks for any help.

+3
source share
3 answers

At first glance, this can be difficult. Since the API is explicitly encapsulated in a C ++ class, the only clean way to do this would be:

Embed a DLL wrapper in C that provides a flat class interface so you can write a Delphi block to use it.

The principle is stated here:

http://rvelthuis.de/articles/articles-cppobjs.html

++ API . , ++, DLL ( Visual Studio 2008 Express).

, - DLL C API, Visual ++ 2008 Express.

:

, , .

"SetDllDirectory" kernel32.dll. Delphi, ++ . "_ZN · 9wikipedia · 7article · 6format · E" ( : http://en.wikipedia.org/wiki/Name_mangling)

, .

, ++ extern "C" {.

:

  • ++ Delphi
  • ++ this (, Self in Delphi)

, , .

++ Dll, C API ( mangling C), :

extern "C" {

void* MakeAnInstanceOfDesiredClass(void)
{
    return new DesiredClass();
}

void DestroyInstanceOfDesiredClass(void* instance)
{
    delete instance;
}

int SomeMethodOfDesiredClass(void* instance)
{
    return reinterpret_cast<DesiredClass*>(instance)->SomeMethod();
}

}

, - , Visual Studio , .

+6

, , , C API , , Delphi:

BOOL APIENTRY  DllMain (HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 
TESSDLL_API void __cdecl  TessDllRelease () 
TESSDLL_API void *__cdecl  TessDllInit (const char *lang) 
TESSDLL_API int __cdecl  TessDllBeginPageBPP (uinT32 xsize, uinT32 ysize, unsigned char *buf, uinT8 bpp) 
TESSDLL_API int __cdecl  TessDllBeginPageLangBPP (uinT32 xsize, uinT32 ysize, unsigned char *buf, const char *lang, uinT8 bpp) 
TESSDLL_API int __cdecl  TessDllBeginPageUprightBPP (uinT32 xsize, uinT32 ysize, unsigned char *buf, const char *lang, uinT8 bpp) 
TESSDLL_API int __cdecl  TessDllBeginPage (uinT32 xsize, uinT32 ysize, unsigned char *buf) 
TESSDLL_API int __cdecl  TessDllBeginPageLang (uinT32 xsize, uinT32 ysize, unsigned char *buf, const char *lang) 
TESSDLL_API int __cdecl  TessDllBeginPageUpright (uinT32 xsize, uinT32 ysize, unsigned char *buf, const char *lang) 
TESSDLL_API void __cdecl  TessDllEndPage (void) 
TESSDLL_API ETEXT_DESC *__cdecl  TessDllRecognize_a_Block (uinT32 left, uinT32 right, uinT32 top, uinT32 bottom) 
TESSDLL_API ETEXT_DESC *__cdecl  TessDllRecognize_all_Words (void) 
TESSDLL_API void __cdecl  ReleaseRecognize () 
TESSDLL_API void *__cdecl  InitRecognize () 
TESSDLL_API int __cdecl  CreateRecognize (uinT32 xsize, uinT32 ysize, unsigned char *buf) 
TESSDLL_API ETEXT_DESC *__cdecl  reconize_a_word (uinT32 left, uinT32 right, uinT32 top, uinT32 bottom) 

, , .

+2

, Jens, . C Delphi (http://www.drbob42.com/delphi/headconv.htm, http://cc.embarcadero.com/item/26951). , 60-80% , . , , VB- . , C, VB2Delphi , , (http://www.marcocantu.com/tools/vb2delphi.htm).

+1

Source: https://habr.com/ru/post/1772139/


All Articles