#define EZOCR_ENGINE_NONE 0 // ‘null’ OCR engine - turns off OCR.
#define EZOCR_ENGINE_TRANSYM 1 // TOCR engine by Transym Ltd.
static cDirectory
static aFiles
static lRunBarcode
static lRunOCR
// Change the values below to designate area to convert/OCR/Barcode
static nAreaStartX := 1434
static nAreaStartY := 369
static nAreaWidth := 578
static nAreaHeight := 72
static nAreaFill := -1
function testscan
local lIsAvailable, nResult
local nLen
lRunOcr := .t.
lRunBarcode := .f.
lIsAvailable := TW_Avail()
if lIsAvailable
// Replace license information with your own information!!!
TW_UniversalLicense( 'My Company', nLicenseNo )
endif
nResult := TW_LoadSourceManager()
if nResult = -1
? 'Error loading source manager'
wait
quit
endif
nLen := adir( cDirectory+"*.tif" )
if nLen = 0
? "No tif files to check"
quit
endif
aFiles := array( nLen )
adir( cDirectory+"*.tif", aFiles )
gdf_barcode()
return nil
function gdf_barcode()
local nReturn, hDib, nCounter, cTestFile
local hDibOcr
local cBarValue
local nOCREngine
local cFilename
local nCountFiles
if .not. lRunOcr .and. .not. lRunBarcode
? 'No files processed'
return nil
endif
for nCountFiles := 1 to len( aFiles )
cFileName := cDirectory+aFiles[ nCountFiles ]
if empty( cFileName ) .or. !file( cFileName )
return .f.
endif
hDib := TW_LOADFROMFILENAME( cFileName )
tracelog( cFileName, TW_DibWidth(hDib), TW_DibHeight(hDib) )
cBarValue := ''
? '------------------------- '+aFiles[ nCountFiles ]
if lRunOCR .and. hDib > 0
if .not. TW_OCR_SELECTENGINE(EZOCR_ENGINE_TRANSYM) > 0
? "Dosadi OCR component is not installed"
else
//? 'OCR Engine available'
nOCREngine := TW_OCR_SELECTEDENGINE()
//? TW_OCR_ENGINENAME( nOCREngine )
nReturn := 0
hDibOcr := TW_DIBREGIONCOPY( hDib, ;
nAreaStartX, ;
nAreaStartY, ;
nAreaWidth , ;
nAreaHeight, ;
nAreaFill )
nReturn := TW_OCR_RECOGNIZEDIB( hDibOcr )
//nReturn := TW_OCR_RECOGNIZEDIBZONE( hDib, 100, 100, 578, 72 )
//nReturn := TW_OCR_RECOGNIZEDIBZONE( hDib, 1434, 369, 578, 72 )
cText := ''
do case
case nReturn > 0
cText := TW_OCR_Text()
case nReturn = -1
? 'OCR Services or selected engine not available'
case nReturn = -3
? 'Image handle is nul or void'
case nReturn = -5
? 'Internal error or OCR engine returned error'
endcase
? 'OCR Text: '
if .not. empty( cText )
//memowrit( 'test.txt', cText )
/*
? at( chr(12), cText )
? asc( substr( cText, 33, 1) )
? asc( substr( cText, 34, 1))
? asc( substr( cText, 35, 1))
*/
//? Token( cText, chr(10), 3 )
//? memoline( cText, 3 )
?? ctext
endif
TW_Free( hDibOcr )
endif
endif
if lRunBarcode .and. hDib > 0
if .not. TW_Barcode_Avail()
? "Dosadi OCR component is not installed"
else
nNoBarCodes := Tw_BARCODE_RECOGNIZE(hDib,-1,-1)
if nNoBarCodes > 0
for nCounter := 1 to nNoBarCodes
? 'Barcode'+str(nCounter,1)+": "+Tw_BARCODE_TEXT( nCounter-1 )
next
//::cBarValue := ::oScanner:BC_Text(0)
//::cBarValue := alltrim(::cBarValue)
else
? ' Barcode: None'
endif
endif
endif
if hDib > 0
TW_Free( hDib )
endif
next
hDib := nil
return nil
#pragma BEGINDUMP
#include <windows.h>
#include "eztwain.h"
#include "hbapi.h"
/*--------- Top-Level Calls -------------------------------------*/
HB_FUNC( TW_UNIVERSALLICENSE )
{
TWAIN_UniversalLicense( hb_parc(1), hb_parni(2) );
hb_ret();
}
HB_FUNC( TW_ACQUIRE ) // hWnd
{
hb_retnl( ( LONG )TWAIN_Acquire( ( HWND ) hb_parnl( 1 ) ) );
}
HB_FUNC( TW_FREE ) // hDib
{
DIB_Free( ( HANDLE ) hb_parnl( 1 ) );
hb_ret();
}
HB_FUNC( TW_SELECTIMAGESOURCE ) // hWnd
{
hb_retni( TWAIN_SelectImageSource( ( HWND ) hb_parnl( 1 ) ) );
}
HB_FUNC( TW_ACQUIRETOCLIPBOARD ) // hWnd, nPixTypes
{
hb_retl( TWAIN_AcquireToClipboard( ( HWND ) hb_parnl( 1 ), (unsigned) hb_parni(2) ) );
}
HB_FUNC( TW_ACQUIREMEMORY ) // hWnd
{
hb_retnl( ( LONG )TWAIN_AcquireMemory( ( HWND ) hb_parnl( 1 ) ) );
}
HB_FUNC( TW_ACQUIRETOFILENAME ) // hWnd, cFileName
{
hb_retni( TWAIN_AcquireToFilename( ( HWND ) hb_parnl( 1 ), hb_parc( 2 ) ) );
}
HB_FUNC( TW_ACQUIREMULTIPAGEFILE ) // hWnd, cFileName
{
hb_retni( TWAIN_AcquireMultipageFile( ( HWND ) hb_parnl( 1 ), hb_parc( 2 ) ) );
}
HB_FUNC( TW_ACQUIREFILE ) // hWnd, nFF, cFileName
{
hb_retni( TWAIN_AcquireFile( ( HWND ) hb_parnl( 1 ), hb_parni( 2 ) ,hb_parc( 3 ) ) );
}
//--------- Basic TWAIN Inquiries
HB_FUNC( TW_AVAIL )
{
hb_retl( TWAIN_IsAvailable() );
}
HB_FUNC( TW_EASYVERSION)
{
hb_retni( TWAIN_EasyVersion() );
}
HB_FUNC( TW_STATE )
{
hb_retni( TWAIN_State() );
}
HB_FUNC( TW_SOURCENAME )
{
hb_retc( TWAIN_SourceName() );
}
HB_FUNC( TW_GETSOURCENAME ) // pzName
{
TWAIN_GetSourceName( (LPSTR) hb_parc( 1 ) );
hb_ret();
}
//--------- DIB handling utilities ---------
HB_FUNC( TW_DIBWJPG ) // hDib, cName
{
hb_parni( DIB_WriteToJpeg( ( HANDLE ) hb_parnl(1), hb_parc( 2 ) ) );
}
HB_FUNC( TW_DIBWBMP ) // hDib, cName
{
hb_parni( DIB_WriteToBmp( ( HANDLE ) hb_parnl(1), hb_parc( 2 ) ) );
}
HB_FUNC( TW_DIBTOFILENAME ) // hDib, cName
{
hb_parni( TWAIN_WriteToFilename( ( HANDLE ) hb_parnl(1), hb_parc( 2 ) ) );
}
//--------- File Read/Write
HB_FUNC( TW_ISJPG )
{
hb_retl( TWAIN_IsJpegAvailable() );
}
HB_FUNC( TW_SETSAVEFORMAT )
{
hb_retni( TWAIN_SetSaveFormat( hb_parni( 1 ) ) );
}
HB_FUNC( TW_GETSAVEFORMAT )
{
hb_retni( TWAIN_GetSaveFormat() );
}
HB_FUNC( TW_SETJPEGQUALITY ) // nQuality 1...100
{
TWAIN_SetJpegQuality( hb_parni( 1 ) );
hb_ret();
}
HB_FUNC( TW_GETJPEGQUALITY )
{
hb_retni( TWAIN_GetJpegQuality() );
}
HB_FUNC( TW_WRITENATIVETOFILENAME )
{
hb_retni( TWAIN_WriteNativeToFilename( (HANDLE) hb_parnl(1), hb_parc(2) ));
}
HB_FUNC( TW_LOADNATIVEFROMFILENAME )
{
hb_retnl( (LONG) TWAIN_LoadNativeFromFilename( hb_parc( 1 ) ) );
}
HB_FUNC( TW_LOADFROMFILENAME )
{
hb_retnl( (LONG) DIB_LoadFromFilename( hb_parc( 1 ) ) );
}
HB_FUNC( TW_DIBSCALEDCOPY ) // hDib, cName
{
hb_retnl( (LONG) DIB_ScaledCopy( ( HANDLE ) hb_parnl( 1 ), hb_parni( 2 ), hb_parni( 3 ) ) );
}
HB_FUNC( TW_DIBCOPY ) // hDib, cName
{
hb_retnl( (LONG) DIB_Copy( ( HANDLE ) hb_parnl( 1 )) );
}
HB_FUNC( TW_DIBWIDTH )
{
hb_parni( DIB_Width( ( HANDLE ) hb_parnl(1) ) );
}
HB_FUNC( TW_DIBHEIGHT )
{
hb_retni( DIB_Height( (HANDLE) hb_parnl(1) ));
}
//--------- Global Options ----------------------------------------------
HB_FUNC( TW_SETMULTITRANSFER )
{
TWAIN_SetMultiTransfer( hb_parni( 1 ) );
hb_ret();
}
HB_FUNC( TW_GETMULTITRANSFER )
{
hb_retni( TWAIN_GetMultiTransfer() );
}
HB_FUNC( TW_SETHIDEUI ) // nHide
{
TWAIN_SetHideUI( hb_parni( 1) );
hb_ret();
}
HB_FUNC( TW_GETHIDEUI )
{
hb_retni( TWAIN_GetHideUI() );
}
HB_FUNC( TW_DISABLEPARENT )
{
TWAIN_DisableParent( hb_parni( 1 ) );
hb_ret();
}
HB_FUNC( TW_GETDISABLEPARENT )
{
hb_retni( TWAIN_GetDisableParent() );
}
HB_FUNC( TW_REGISTERAPP )
{
TWAIN_RegisterApp( hb_parni(1),hb_parni(2),hb_parni(3),hb_parni(4),
hb_parc(5), hb_parc(6),
hb_parc(7), hb_parc(8) );
hb_ret();
}
HB_FUNC( TW_SETAPPTITLE )
{
TWAIN_SetAppTitle( hb_parc( 1 ) );
hb_ret();
}
HB_FUNC( TW_SETAPPLICATIONKEY )
{
TWAIN_SetApplicationKey( hb_parni( 1 ) );
hb_ret();
}
//--------- TWAIN State Control ---------------------------------------
HB_FUNC( TW_LOADSOURCEMANAGER )
{
hb_retni( TWAIN_LoadSourceManager() );
}
HB_FUNC( TW_OPENSOURCEMANAGER ) // hWnd
{
hb_retni( TWAIN_OpenSourceManager( ( HWND ) hb_parnl( 1 ) ) );
}
HB_FUNC( TW_OPENDEFAULTSOURCE )
{
hb_retni( TWAIN_OpenDefaultSource() );
}
HB_FUNC( TW_GETSOURCELIST )
{
hb_retni( TWAIN_GetSourceList() );
}
HB_FUNC( TW_GETNEXTSOURCENAME )
{
hb_retni( TWAIN_GetNextSourceName( ( char * ) hb_parc( 1 ) ) );
}
HB_FUNC( TW_GETDEFAULTSOURCENAME )
{
hb_retni( TWAIN_GetDefaultSourceName( ( char * ) hb_parc( 1 ) ));
}
HB_FUNC( TW_OPENSOURCE )
{
hb_retni( TWAIN_OpenSource( hb_parc( 1 ) ) );
}
HB_FUNC( TW_ENABLESOURCE ) // hWnd
{
hb_retni( TWAIN_EnableSource( ( HWND ) hb_parnl( 1 ) ) );
}
HB_FUNC( TW_DISABLESOURCE )
{
hb_retni( TWAIN_DisableSource( ) );
}
HB_FUNC( TW_CLOSESOURCE )
{
hb_retni( TWAIN_CloseSource() );
}
HB_FUNC( TW_CLOSESOURCEMANAGER )
{
hb_retni( TWAIN_CloseSourceManager( (HWND) hb_parnl( 1 ) ) );
}
HB_FUNC( TW_UNLOADSOURCEMANEGER )
{
hb_retni( TWAIN_UnloadSourceManager() );
}
//--------- High-level Capability Negotiation Functions --------------
// These functions should only be called in State 4 (TWAIN_SOURCE_OPEN)
HB_FUNC( TW_GETCURRENTUNITS )
{
hb_retni( TWAIN_GetCurrentUnits() );
}
HB_FUNC( TW_SETCURRENTUNITS ) // nUnits
{
hb_retni( TWAIN_SetCurrentUnits( hb_parni( 1 ) ) );
}
HB_FUNC( TW_GETBITDEPTH )
{
hb_retni( TWAIN_GetBitDepth() );
}
HB_FUNC( TW_SETBITDEPTH )
{
hb_retni( TWAIN_SetBitDepth( hb_parni( 1 ) ) );
}
HB_FUNC( TW_GETPIXELTYPE )
{
hb_retni( TWAIN_GetPixelType() );
}
HB_FUNC( TW_SETCURRENTPIXELTYPE ) // nBits
{
hb_retni( TWAIN_SetCurrentPixelType( hb_parni( 1 ) ) );
}
HB_FUNC( TW_GETCURRENTRESOLUTION )
{
hb_retnd( TWAIN_GetCurrentResolution());
}
HB_FUNC( TW_GETYRESOLUTION )
{
hb_retnd( TWAIN_GetYResolution());
}
HB_FUNC( TW_SETCURRENTRESOLUTION ) // dRes
{
hb_retni( TWAIN_SetCurrentResolution( hb_parnd( 1 ) ) );
}
HB_FUNC( TW_SETXRESOLUTION )
{
hb_retni( TWAIN_SetXResolution( hb_parnd( 1 ) ) );
}
HB_FUNC( TW_SETYRESOLUTION )
{
hb_retni( TWAIN_SetYResolution( hb_parnd( 1 ) ) );
}
HB_FUNC( TW_SETCONTRATS ) //dCon
{
hb_retni( TWAIN_SetContrast( hb_parnd( 1 ) ) ); // -1000....+1000
}
HB_FUNC( TW_SETBRIGHTNESS ) //dBri
{
hb_retni( TWAIN_SetBrightness( hb_parnd( 1 ) ) ); // -1000....+1000
}
HB_FUNC( TW_SETTHRESHOLD )
{
hb_retni( TWAIN_SetThreshold( hb_parnd( 1 ) ) );
}
HB_FUNC( TW_GETCURRENTTHRESHOLD )
{
hb_retnd( TWAIN_GetCurrentThreshold() );
}
HB_FUNC( TW_SETXFERMECH )
{
hb_retni( TWAIN_SetXferMech( hb_parni( 1 ) ) );
}
HB_FUNC( TW_XFERMECH )
{
hb_retni( TWAIN_XferMech() );
}
HB_FUNC( TW_SUPPORTSFILEXFER )
{
hb_retni( TWAIN_SupportsFileXfer() );
}
HB_FUNC( TW_SETPAPERSIZE ) // nTypePaper
{
hb_retni( TWAIN_SetPaperSize( hb_parni( 1 ) ) );
}
//-------- Document Feeder ---------------------------------
HB_FUNC( TW_HASFEEDER )
{
hb_retl( TWAIN_HasFeeder() );
}
HB_FUNC( TW_ISFEEDERSELECTED )
{
hb_retl( TWAIN_IsFeederSelected() );
}
HB_FUNC( TW_SELECTFEEDER )
{
hb_retl( TWAIN_SelectFeeder( hb_parl( 1 ) ) );
}
HB_FUNC( TW_ISAUTOFEEDON )
{
hb_retl( TWAIN_IsAutoFeedOn() );
}
HB_FUNC( TW_SETAUTOFEDD )
{
hb_retl( TWAIN_SetAutoFeed( hb_parl( 1 ) ) );
}
HB_FUNC( TW_ISFEEDERLOADED )
{
hb_retl( TWAIN_IsFeederLoaded() );
}
//-------- Duplex Scanning ------------------------------------------
HB_FUNC( TW_GETDUPLEXSUPPORT )
{
hb_retni( TWAIN_GetDuplexSupport() );
}
HB_FUNC( TW_ENABLEDUPLEX )
{
hb_retni( TWAIN_EnableDuplex( hb_parni( 1 ) ) );
}
HB_FUNC( TW_ISDUPLEXENABLED )
{
hb_retl( TWAIN_IsDuplexEnabled() );
}
//--------- Other 'exotic' capabilities --------
HB_FUNC( TW_HASCONTROLLABLEUI )
{
hb_retni( TWAIN_HasControllableUI() );
}
HB_FUNC( TW_SETINDICATORS )
{
hb_retni( TWAIN_SetIndicators( hb_parl( 1 ) ) );
}
HB_FUNC( TW_COMPRESSION )
{
hb_retni( TWAIN_Compression() );
}
HB_FUNC( TW_SETCOMPRESSION )
{
hb_retni( TWAIN_SetCompression( hb_parni( 1 ) ) );
}
HB_FUNC( TW_TILED )
{
hb_retl( TWAIN_Tiled() );
}
HB_FUNC( TW_SETTILED )
{
hb_retni( TWAIN_SetTiled( hb_parl( 1 ) ) );
}
HB_FUNC( TW_PLANARCHUNKY )
{
hb_retni( TWAIN_PlanarChunky() );
}
HB_FUNC( TW_SETPLANARCHUNKY )
{
hb_retni( TWAIN_SetPlanarChunky( hb_parni( 1 ) ) );
}
HB_FUNC( TW_PIXELFLAVOR )
{
hb_retni( TWAIN_PixelFlavor() );
}
HB_FUNC( TW_SETPIXELFLAVOR )
{
hb_retni( TWAIN_SetPixelFlavor( hb_parni( 1 ) ) );
}
HB_FUNC( TW_SETLIGHTPATH )
{
hb_retni( TWAIN_SetLightPath( hb_parl( 1 ) ) );
}
HB_FUNC( TW_SETAUTOBRIGHT )
{
hb_retni( TWAIN_SetAutoBright( hb_parl( 1 ) ) );
}
HB_FUNC( TW_SETGAMMA )
{
hb_retni( TWAIN_SetGamma( hb_parnd( 1 ) ) );
}
HB_FUNC( TW_SETSHADOW )
{
hb_retni( TWAIN_SetShadow( hb_parnd( 1 ) ) );
}
HB_FUNC( TW_SETHIGHLIGHT )
{
hb_retni( TWAIN_SetHighlight( hb_parnd( 1 ) ) );
}
//--------- Barcode --------
HB_FUNC( TW_BARCODE_AVAIL )
{
hb_retl( BARCODE_IsAvailable() );
}
HB_FUNC( TW_BARCODE_SELENGINE )
{
hb_retni( BARCODE_SelectedEngine() );
}
HB_FUNC( TW_BARCODE_TEXT )
{
hb_retc( BARCODE_Text( hb_parni( 1 ) ));
}
HB_FUNC( TW_BARCODE_TYPE )
{
hb_retni( BARCODE_Type( hb_parni( 1 ) ));
}
HB_FUNC( TW_BARCODE_GETTEXT )
{
BARCODE_GetText( hb_parni( 1 ), (LPSTR) hb_parc(2) );
hb_ret();
}
HB_FUNC( TW_BARCODE_RECOGNIZE )
{
hb_retni( BARCODE_Recognize( (HANDLE) hb_parnl(1),hb_parni( 2 ),hb_parni( 3 ) ) );
}
//--------- OCR --------
HB_FUNC( TW_OCR_SELECTENGINE ) // nEngine
{
hb_retni( OCR_SelectEngine( hb_parni( 1 ) ) );
}
HB_FUNC( TW_OCR_SELECTEDENGINE )
{
hb_retni( OCR_SelectedEngine() );
}
HB_FUNC( TW_OCR_ENGINENAME )
{
hb_retc( OCR_EngineName( hb_parni( 1 ) ) );
}
HB_FUNC( TW_OCR_TEXT )
{
hb_retc( OCR_Text() );
}
HB_FUNC( TW_OCR_RECOGNIZEDIB ) // hDib
{
hb_retni( OCR_RecognizeDib( (HANDLE) hb_parnl(1) ) );
}
/*
HB_FUNC( TW_OCR_RECOGNIZEDIBZONE ) // hDib, Left, Top, Width, Height
{
hb_retni( OCR_RecognizeDibZone( (HANDLE) hb_parnl(1), hb_parni( 2 ), hb_parni( 3 ), hb_parni( 4 ), hb_parni( 5 ) ) );
}
*/
HB_FUNC( TW_DIBREGIONCOPY ) // hDib, Left, Top, Width, Height
{
hb_retnl( (LONG) DIB_RegionCopy( (HANDLE) hb_parnl(1), hb_parni( 2 ), hb_parni( 3 ), hb_parni( 4 ), hb_parni( 5 ), hb_parni( 6 ) ) );
}
//--------- Image Layout (Region of Interest) --------
HB_FUNC( TW_SETIMAGELAYOUT ) // left, top, right, bottom
{
hb_retni( TWAIN_SetImageLayout( hb_parnd( 1 ),hb_parnd( 2 ),hb_parnd( 3 ),hb_parnd( 4 ) ) );
}
HB_FUNC( TW_RESETIMAGELAYOUT )
{
TWAIN_ResetImageLayout();
hb_ret();
}
HB_FUNC( TW_GETIMAGELAYOUT )
{
double L,T,R,B;
int nRet;
nRet = TWAIN_GetImageLayout( &L,&T,&R,&B );
hb_stornd( L, 1 );
hb_stornd( T, 2 );
hb_stornd( R, 3 );
hb_stornd( B, 4 );
hb_retni( nRet );
}
HB_FUNC( TW_GETDEFAULTIMAGELAYOUT )
{
double L,T,R,B;
int nRet;
nRet = TWAIN_GetDefaultImageLayout( &L, &T, &R, &B);
hb_stornd( L, 1 );
hb_stornd( T, 2 );
hb_stornd( R, 3 );
hb_stornd( B, 4 );
hb_retni( nRet );
}
//HANDLE EZTAPI DIB_GetFromClipboard(void);
HB_FUNC( TW_DIB_GETFROMCLIPBOARD )
{
hb_retnl( (LONG) DIB_GetFromClipboard() );
}
// para no depender de Five, y harbour poder el solito trabajar ;)
HB_FUNC ( GETACTIVEWINDOW )
{
hb_retnl( ( LONG ) GetActiveWindow() );
}
HB_FUNC( TW_SETPIXELTYPE )
{
hb_retni( TWAIN_SetPixelType( hb_parni( 1 ) ) );
}
#pragma ENDDUMP