You have to use a dll wrapper.
for example the one i made
cTessdll.h
#ifndef tess_dllH
#define tess_dllH
//---------------------------------------------------------------------------
#include <Windows.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
//---------------------------------------------------------------------------
typedef struct
{
Word char_code;
short left;
short right;
short top;
short bottom;
short font_index;
Byte confidence;
Byte point_size;
Shortint blanks;
Byte formatting;
} TEANYCODE_CHAR;
//---------------------------------------------------------------------------
typedef struct
{
short count;
short progress;
Shortint more_to_come;
Shortint ocr_alive;
Shortint err_code;
void *cancel;
void *cancel_this;
int end_time;
::TEANYCODE_CHAR text[32000];
} TETEXT_DESC;
//---------------------------------------------------------------------------
// TESSDLL Class
//---------------------------------------------------------------------------
class TessDLL
{
private:
bool LoadDLL(void);
public:
TessDLL();
~TessDLL();
AnsiString ConvertText(TETEXT_DESC *EText_Desc);
int __cdecl (*TessDllBeginPage)(unsigned xsize, unsigned
ysize, void * buf);
int __cdecl (*TessDllBeginPageLang)(unsigned xsize, unsigned
ysize, void * buf, const char * lang);
int __cdecl (*TessDllBeginPageUpright)(unsigned xsize,
unsigned ysize, void * buf, const char * lang);
int __cdecl (*TessDllBeginPageBPP)(unsigned xsize, unsigned
ysize, void * buf, Byte bpp);
int __cdecl (*TessDllBeginPageLangBPP)(unsigned xsize,
unsigned ysize, void * buf, const char * lang, Byte bpp);
int __cdecl (*TessDllBeginPageUprightBPP)(unsigned xsize,
unsigned ysize, void * buf, const char * lang, Byte bpp);
int __cdecl (*TessDllEndPage)(void);
::TETEXT_DESC * __cdecl (*TessDllRecognize_a_Block)(unsigned
left, unsigned right, unsigned top, unsigned bottom);
::TETEXT_DESC * __cdecl (*TessDllRecognize_all_Words)(void);
int __cdecl (*TessDllRelease)(void);
HANDLE TessHandle;
bool TessDLLLoaded;
};
//---------------------------------------------------------------------------
#endif
cTessdll.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "cTessdll.h"
//---------------------------------------------------------------------------
TessDLL::TessDLL()
{
TessDLLLoaded = false;
TessDLLLoaded = LoadDLL();
}
//---------------------------------------------------------------------------
TessDLL::~TessDLL()
{
if (TessDLLLoaded){
TessDllRelease();
FreeLibrary(TessHandle);
}
}
//---------------------------------------------------------------------------
bool TessDLL::LoadDLL(void)
{
if (TessDLLLoaded)
return(true);
TessHandle = LoadLibrary("TESSDLL.DLL");
if(TessHandle != NULL) {
TessDllBeginPage = (int (*)(unsigned int,unsigned
int,void *))
GetProcAddress((HINSTANCE)TessHandle,"TessDllBeginPage");
TessDllBeginPageLang = (int (*)(unsigned int,unsigned
int,void *,const char *))
GetProcAddress((HINSTANCE)TessHandle,"TessDllBeginPageLang");
TessDllBeginPageUpright = (int (*)(unsigned
int,unsigned int,void *,const char *))
GetProcAddress((HINSTANCE)TessHandle,"TessDllBeginPageUpright");
TessDllBeginPageBPP = (int (*)(unsigned int,unsigned
int,void *,unsigned char))
GetProcAddress((HINSTANCE)TessHandle,"TessDllBeginPageBPP");
TessDllBeginPageLangBPP = (int (*)(unsigned
int,unsigned int,void *,const char *,unsigned char))
GetProcAddress((HINSTANCE)TessHandle,"TessDllBeginPageLangBPP");
TessDllBeginPageUprightBPP = (int (*)(unsigned
int,unsigned int,void *,const char *,unsigned char))
GetProcAddress((HINSTANCE)TessHandle,"TessDllBeginPageUprightBPP");
TessDllEndPage = (int (*)())
GetProcAddress((HINSTANCE)TessHandle,"TessDllEndPage");
TessDllRecognize_a_Block = (TETEXT_DESC * (*)(unsigned
int,unsigned int,unsigned int,unsigned int))
GetProcAddress((HINSTANCE)TessHandle,"TessDllRecognize_a_Block");
TessDllRecognize_all_Words = (TETEXT_DESC * (*)())
GetProcAddress((HINSTANCE)TessHandle,"TessDllRecognize_all_Words");
TessDllRelease = (int (*)())
GetProcAddress((HINSTANCE)TessHandle,"TessDllRelease");
if(TessDllBeginPage && TessDllBeginPageLang &&
TessDllBeginPageUpright && TessDllBeginPageBPP
&&
TessDllBeginPageLangBPP &&
TessDllBeginPageUprightBPP &&
TessDllEndPage && TessDllRecognize_a_Block &&
TessDllRecognize_all_Words && TessDllRelease){
return(true); //Succeeded
} else {
FreeLibrary(TessHandle);
return(false);
}
} else {
return(false);
}
}
//---------------------------------------------------------------------------
AnsiString TessDLL::ConvertText(::TETEXT_DESC *EText_Desc)
{
TEANYCODE_CHAR ch;
AnsiString Result = "";
for (int i = 0; i < EText_Desc->count; i++){
ch = EText_Desc->text[i];
for (int b = 0; b < ch.blanks; ++b)
Result = Result + " ";
Result = Result + char(ch.char_code);
if (ch.formatting & 64)
Result = Result + "\r\n";
if (ch.formatting & 128)
Result = Result + "\r\n";
}
return Result;
}
//---------------------------------------------------------------------------
then you can use it in a program like
TessDLL *Tesseract = new TessDLL();
AnsiString result;
if (Tesseract->TessDLLLoaded){
Graphics::TBitmap *bmOCR = new Graphics::TBitmap();
bmOCR->LoadFromFile("test.bmp");
int BytesPerLine = int(bmOCR->ScanLine[0])-
int(bmOCR->ScanLine[1]);
int bpp, VirtualWidth;
bmOCR->HandleType = bmDIB;
switch (bmOCR->PixelFormat) {
case pfDevice :
bmOCR->PixelFormat = pf24bit;
bpp = 24;
break;
case pf1bit :
bpp = 1;
break;
case pf4bit :
bmOCR->PixelFormat = pf8bit;
bpp = 8;
break;
case pf8bit :
bpp = 8;
break;
case pf15bit :
bmOCR->PixelFormat = pf24bit;
bpp = 24;
break;
case pf16bit :
bmOCR->PixelFormat = pf24bit;
bpp = 24;
break;
case pf24bit :
bpp = 24;
break;
case pf32bit :
bmOCR->PixelFormat = pf24bit;
bpp = 24;
break;
}
switch (bpp) {
case 1 :
VirtualWidth = BytesPerLine * 8;
break;
case 8 :
VirtualWidth = BytesPerLine;
break;
case 24 :
bmOCR->Width = 4*((bmOCR->Width+3) /
4);
VirtualWidth = bmOCR->Width;
break;
}
try {
try {
Tesseract-
>TessDllBeginPageLangBPP(VirtualWidth,
bmOCR->Height,
bmOCR->ScanLine[bmOCR-
>Height-1],
NULL,
bpp);
TETEXT_DESC *RecognizedText;
RecognizedText = Tesseract-
>TessDllRecognize_all_Words();
result = Tesseract-
>ConvertText(RecognizedText);
}
__finally {
Tesseract->TessDllEndPage();
}
}
__except (true) {
result = ".ERROR.";
}
delete bmOCR;
}
delete Tesseract;
etc.....
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tesseract-ocr" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/tesseract-ocr?hl=en
-~----------~----~----~----~------~----~------~--~---