TW_OCR32调用

130 篇文章 1 订阅

TW_OCR32.dll下载


//回调函数

long FAR PASCAL ProgressStart()

{
return 1;
}


long FAR PASCAL ProgressEnd()
{
return 1;
}


long FAR PASCAL ProgressSetStage(int wStageNumber, byte& Name)
{
//StageName = Array("读取图象", 版面分析, "倾斜校正", "识别", "后处理")
//' Select Case wStageNumber
//'    Case 0
//ProgressForm.Label1 = "正在" & StageName(wStageNumber)
return 1;
}


long FAR PASCAL ProgressSetPercent(int percent)
{
//ProgressForm.Label2 = percent & "%"
//ProgressForm.ProgressBar1.Value = percent
return 1;

}


别人调用和声明的例子:

/*
procedure TTFOcr.GetOcrInformation(nLine, nPos: Integer; var FRect: TRect);
var
 FGetInofrmation:TTW_GetNodeInformation;
 FFont:Word;
 trust:array[0..10] of Byte;
 simword:String[11];
 begin
 if FLibHandle= 0 then
 FLibHandle :=  LoadLibrary(PChar(FLibName));
 @FGetInofrmation:= GetProcAddress(FLibHandle, 'TW_GetNodeInformation');
 FGetInofrmation(nLine,nPos,FFont,FRect,@simword[0],@trust[0]);
 end;
 
procedure TTFOcr.InitalizeOCRInstance;
begin
inherited;
FLibName:= ExtractFilePath(Application.ExeName) + DEF_LIBNAME;
end;

 procedure TTFOcr.OCR(ALanguageID: Integer; KeepLayer: Boolean);
 var
 AStrings:TStrings;
 sTxtF,sImgF:string;
 i:integer;
 FStart:TTW_Start;
 FEnd:TTW_End;
 FRecgF:TTW_RecogFile;
 FCallBack: TTW_CallBackAddress;
 FCloseImg:TTW_CloseImage;
 FLoadTrace:TTW_LoadTrace;
 FUnLoadTrace:TTW_UnloadTrace;
 err:integer;
 
begin
inherited;
AStrings:= TStringList.Create;
if FLibHandle= 0 then
FLibHandle :=  LoadLibrary(PChar(FLibName));

 @FStart:= GetProcAddress(FLibHandle, 'TW_Start');
 @FEnd:= GetProcAddress(FLibHandle, 'TW_End');
 @FRecgF:= GetProcAddress(FLibHandle, 'TW_RecogFile');
 @FCallBack:= GetProcAddress(FLibHandle, 'TW_CallBackAddress');
 @FCloseImg:= GetProcAddress(FLibHandle, 'TW_CloseImage');
 @FUnLoadTrace:= GetProcAddress(FLibHandle, 'TW_UnloadTrace');
 @FLoadTrace:= GetProcAddress(FLibHandle, 'TW_LoadTrace');
 try
 FUnLoadTrace;
 err:= FStart(0,ALanguageID,0, 0);
 if err<>0 then
 Raise Exception.Create('ê?±e′í?ó£?′í?óo?£o'+IntToStr(err));
 err:= FCallBack(Longint(@ProgressStart),Longint(@ProgressFinish), Longint(@ProgressSetStage),Longint(@ProgressSetPerc));
 if err<>0 then
 Raise Exception.Create('ê?±e′í?ó£?′í?óo?£o'+IntToStr(err));
 STxtF:= ChangeFileExt(FFileName,'.TXT');
 err:= FRecgF(PChar(FFileName), PChar(STxtF), 0);
 if err<>0 then begin
 Raise Exception.Create('ê?±e′í?ó£?′í?óo?£o'+IntToStr(err));
 end;
 FLoadTrace(PChar(FFileName));
 FCloseImg;
 FEnd;
 except
 on E: Exception do
 begin
 FLogs.Add(E.Message);
 DeleteTem(FFileName,False);
 end;
 end;
 
sTxtF:= ChangeFileExt(FFileName,'.txt');
if FileExists(sTxtF)  then
begin
//if Append then

 AStrings.LoadFromFile(sTxtF);
 if not KeepLayer then
 for i:= 0 to  AStrings.Count -1 do
 FText:= FText + #13 + AStrings.Strings[i]
 else
 FText:= AStrings.Text;
 end;
 DeleteTem(FFileName,False);
 AStrings.Free;
 end;
 

 
procedure TTFOcr.SetLibName(const Value: string);
begin
FLibName := Value;
if FLibHandle= 0 then
FLibHandle :=  LoadLibrary(PChar(FLibName));
end;

 procedure TTFOcr.SetLogs(const Value: TStrings);
 begin
 FLogs := Value;
 end;
 
end.
*/
/*Public Declare Function TW_CallBackAddress Lib "tw_ocr32.dll" (ByVal start As Long, ByVal finish As Long, ByVal stage As Long, ByVal percent As Long) As Long
---------
Function ProgressStart() As Long
ProgressForm.Show
ProgressForm.Label1 = "正在调识别库"
DoEvents
ProgressStart = 1
End Function


Function ProgressEnd() As Long
Unload ProgressForm
ProgressEnd = 1
End Function


Function ProgressSetStage(ByVal wStageNumber As Integer, ByRef Name As Byte) As Long
Dim StageName As Variant
StageName = Array("读取图象", 版面分析, "倾斜校正", "识别", "后处理")
' Select Case wStageNumber
'    Case 0
ProgressForm.Label1 = "正在" & StageName(wStageNumber)
ProgressSetStage = 1
End Function


Function ProgressSetPerc(ByVal percent As Integer) As Long
ProgressForm.Label2 = percent & "%"
ProgressForm.ProgressBar1.Value = percent
ProgressSetPerc = 1
End Function
---------------------
TW_CallBackAddress(AddressOf Progress.ProgressStart, AddressOf Progress.ProgressEnd, AddressOf Progress.ProgressSetStage, AddressOf Progress.ProgressSetPerc)*/

//TW_CloseImage, TW_End, TW_ExportFile, TW_GetNodeInformation, TW_Layout, TW_LoadImage, TW_LoadTrace, TW_RecogFile, 
//TW_RecogRegions, TW_Start, TW_UnloadTrace


//int TW_Start(int nCode, int nFont, BOOL bOutFull, HANDLE hApplicationInstance);
//err:= FStart(0,ALanguageID,0, 0);
//int TW_CallBackAddress(LPFNTW_ProgressStart, LPFNTW_ProgressEnd, LPFNTW_ProgressSetStage, LPFNTW_ProgressSetPercent);
//err:= FCallBack(Longint(@ProgressStart),Longint(@ProgressFinish), Longint(@ProgressSetStage),Longint(@ProgressSetPerc)); 
//int TW_RecogFile(LPSTR lpstrImageFileName,LPSTR lpstrTextFileName,int nOption);
//err:= FRecgF(PChar(FFileName), PChar(STxtF), 0);
//int TW_LoadTrace(LPCSTR lpszFileName);
//FLoadTrace(PChar(FFileName));
//void TW_CloseImage();
//FCloseImg;
//int TW_ExportFile(LPCSTR *lpTifList, DWORD *dwErrCode, int nTifCount, LPCSTR lpPdfPathName, DWORD option);
//void TW_End();
/*int ProcessTiff2PDFFromTHOCR(
LPCSTR *lpTifList, // Tif文件列表
DWORD *dwErrCode, // 相应的错误码
int nTifCount, // Tif文件个数
LPCSTR lpPdfPathName, // 生成的PDF文件名
DWORD option
);*/
/*TW_Start(0,5,0,0);   
TW_CallBackAddress(ProgressStart,ProgressEnd,   0,   ProgressStart);     //   
TW_RecogFile(PChar('E:\TemOCR.bmp'),   PChar('E:\TemOCR.TXT'),   0);   
    TW_End;*/  


整理后的API声明和调用:

typedef int (FAR PASCAL *LPFNTW_Start)(int ,int ,BOOL ,HANDLE);
typedef void (FAR PASCAL *LPFNTW_End)();
typedef long (FAR PASCAL *LPFNTW_ProgressStart)();
typedef long (FAR PASCAL *LPFNTW_ProgressEnd)();
//typedef long (FAR PASCAL *LPFNTW_ProgressSetStage)(int wStageNumber, byte& Name);
typedef long (FAR PASCAL *LPFNTW_ProgressSetStage)(int, byte&);
//typedef long (FAR PASCAL *LPFNTW_ProgressSetPerc)(int percent);
typedef long (FAR PASCAL *LPFNTW_ProgressSetPercent)(int);
typedef int (FAR PASCAL *LPFNTW_CallBackAddress)(
LPFNTW_ProgressStart, LPFNTW_ProgressEnd, LPFNTW_ProgressSetStage, LPFNTW_ProgressSetPercent);
typedef int (FAR PASCAL *LPFNTW_RecogFile)(LPSTR, LPSTR, int);


typedef int (FAR PASCAL *LPFNTW_LoadTrace)(LPCSTR);
    typedef int (FAR PASCAL *LPFNTW_GetNodeInformation)(int, int, WORD&, RECT&, LPWORD ,LPBYTE);
typedef void (FAR PASCAL *LPFNTW_UnloadTrace)();


typedef void (FAR PASCAL *LPFNTW_TW_CloseImage)();

LPFNTW_Start lpfnTW_Start = NULL;
LPFNTW_CallBackAddress lpfnTW_CallBackAddress = NULL;
LPFNTW_RecogFile lpfnTW_RecogFile = NULL;
LPFNTW_End lpfnTW_End = NULL;

LPFNTW_LoadTrace lpfnTW_LoadTrace = NULL;
LPFNTW_GetNodeInformation lpfnTW_GetNodeInformation = NULL;
LPFNTW_UnloadTrace lpfnTW_UnloadTrace = NULL;


LPFNTW_TW_CloseImage lpfnTW_CloseImage = NULL;

HMODULE hModule = LoadLibrary(_T("Tw_ocr32.dll"));
if(hModule) {


lpfnTW_Start = (LPFNTW_Start)GetProcAddress(hModule,"TW_Start");
lpfnTW_CallBackAddress = (LPFNTW_CallBackAddress)GetProcAddress(hModule,"TW_CallBackAddress");
lpfnTW_RecogFile = (LPFNTW_RecogFile)GetProcAddress(hModule,"TW_RecogFile");
lpfnTW_End = (LPFNTW_End)GetProcAddress(hModule,"TW_End");
lpfnTW_LoadTrace = (LPFNTW_LoadTrace)GetProcAddress(hModule,"TW_LoadTrace");
lpfnTW_GetNodeInformation = (LPFNTW_GetNodeInformation)GetProcAddress(hModule,"TW_GetNodeInformation");
lpfnTW_UnloadTrace = (LPFNTW_UnloadTrace)GetProcAddress(hModule,"TW_UnloadTrace");
lpfnTW_CloseImage = (LPFNTW_TW_CloseImage)GetProcAddress(hModule,"TW_CloseImage");

if(lpfnTW_Start && lpfnTW_RecogFile && lpfnTW_End) {
lpfnTW_UnloadTrace();
lpfnTW_Start(0, 5, 0, 0);
lpfnTW_CallBackAddress(ProgressStart, ProgressEnd, ProgressSetStage, ProgressSetPercent);
lpfnTW_RecogFile("D:\\tw_ocr32\\orderNo.tif", "D:\\tw_ocr32\\resultFile.txt", 0);
lpfnTW_End();
lpfnTW_LoadTrace("D:\\tw_ocr32\\orderNo.tif");
lpfnTW_CloseImage();
}


FreeLibrary(hModule);
hModule = NULL;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值