Date: 02-16-2022
Return to Index
created by gbSnippets
#Compile Exe
#Dim All
' from: https://github.com/tesseract-ocr/tesseract/wiki/APIExample
#Include "tesseract.inc"
Macro LEPT_CALL = CDecl Import "liblept-5.dll"
Declare Function pixRead LEPT_CALL Alias "pixRead" ( _
ByRef filename As AsciiZ _ ' const char *filename
) As Dword ' PIX *
Declare Sub pixDestroy LEPT_CALL Alias "pixDestroy" ( _
ByVal ppix As Dword _ ' PIX **ppix
) ' void
Function PBMain
Local pPix As Dword
Local pHandle As Dword
Local pText As AsciiZ Ptr
Local rc As Long
pPix = pixRead("C:\Program Files (x86)\Tesseract-OCR\doc\phototest.tif")
If IsFalse pPix Then
Print "Error reading image."
GoTo x0
End If
pHandle = TessBaseAPICreate()
If IsFalse pHandle Then
Print "Couldn't create BaseAPI"
GoTo x1
End If
rc = TessBaseAPIInit3(pHandle, ByVal 0, "eng")
If rc Then
Print "Could not initialize tesseract."
GoTo x2
End If
TessBaseAPISetImage2(pHandle, pPix)
rc = TessBaseAPIRecognize(pHandle, 0)
If IsTrue rc Then
Print "Error in Tesseract recognition"
GoTo x3
End If
pText = TessBaseAPIGetUTF8Text(pHandle)
If IsFalse pText Then
Print "Error getting text"
GoTo x3
End If
Print Utf8ToChr$(@pText)
TessDeleteText(pText)
x3:
TessBaseAPIEnd(pHandle)
x2:
TessBaseAPIDelete(pHandle)
x1:
pixDestroy(VarPtr(pPix))
x0:
WaitKey$
End Function
http://www.garybeene.com/sw/gbsnippets.htm