Sign in to follow this  
Followers 0
marko001

OCRDLL.DLL API - Need help on implementing for AutoIt

13 posts in this topic

#1 ·  Posted (edited)

Hi all,

after days and days of searching, I found what could be the API for OCRDLL.DLL. But to be honest I can't manage them so I hope community can help for everybody to get them working.

Hi have also a C++ - VB thread that could help finding the right commands to send trough AutoIt

Here the thread with the DLL for Download:

C++

this is in a module...
Declare Sub XMLoadLibrary Lib "OCRDll.dll" (ByVal LoadLibrary As String)
Declare Sub XMLoadImage Lib "OCRDll.dll" (ByVal LoadImage As String)
Declare Sub XMRecognition Lib "OCRDll.dll" (ByVal Recognition As String)


Private Sub Form_Load()
Dim LoadImage As String
Dim LoadLibrary As String
Dim getRec As Long

LoadLibrary = "c:\xmRadio\lib\library.xcl"
LoadImage = "c:\xmRadio\temp.gif"

Call getRec(LoadLibrary, LoadImage, Recognition)

MsgBox getRec

End Sub

 

XMLoadLibrary:
int XMLoadLibrary(char *name); - load the image library from the name file

XMLoadImage:
int XMLoadImage(char *addr); - load an image located on addr (it may be a full path local file name or an Internet reference
like http://link). A file from Internet is saved in a temporary file. 

XMRecognition:
int XMRecognition(char *str); - recognize a loaded image and put the result in str

C++ example of order of operation...
if XMLoadLibrary("1.xcl") != 0 then error;

if XMLoadImage("1.gif") != 0 then error;
if XMRecognition(s) != 0 then error;
output s;
...

XMImport.h

extern "C" int __declspec(dllimport) __stdcall XMLoadImage(char *addr);
extern "C" int __declspec(dllimport) __stdcall XMRecognition(char *str);
extern "C" int __declspec(dllimport) __stdcall XMLoadLibrary(char *name);

and VB

Declare Ansi Function XMLoadLibrary Lib "OCRDll.dll" (ByVal LoadLibrary As String) As Integer
Declare Ansi Function XMLoadImage Lib "OCRDll.dll" (ByVal LoadImage As String) As Integer
Declare Ansi Function XMRecognition Lib "OCRDll.dll" (ByVal Recognition As String) As Integer

Here follows the API:

OCR

OCR

 int OCR(const IMG * img, int noisy) 

Recognizes the text located in an image.

Return Value
A non zero error code if the function fails.

Parameters

img
    A pointer to the image to process.

noisy
    Non zero value if the image is noisy (i.e. contains a lot of speckles)

OCROnArea

int OCROnArea(const IMG * img, int noisy) 

Recognizes the text located in an image that contains a unique text area. This function doesn't do any layout analysis on the area. The image containing the area is usually extracted from a page with ExtractImgArea.

Return Value
A non zero error code if the function fails.

Parameters

img
    A pointer to the image to process.

noisy
    A non zero value if the image is noisy (i.e. contains a lot of speckles)

OCROnArea2

int OCROnArea2(const IMG * img, int noisy, int startprogress, int endprogress) 

This function is similar to OCROnArea but allows you to give starting and ending values for the progress percentage. It is useful when you want to have to display a progress bar when processing several areas.

Return Value
A non zero error code if the function fails.

Parameters

img
    A pointer to the image to process.

noisy
    A non zero value if the image is noisy (i.e. contains a lot of speckles)

startprogress
    Starting value for the progress percentage.

endprogress
    Ending value for the progress percentage.

OCRSetOutputHandler

OCROutputHandler OCRSetOutputHandler(OCROutputHandler handler) 

When the output mode is OM_TEXT or OM_RICHTEXT, a user defined function of type OCROutputHandler will be called by the OCR engine for each "OCR event".

Return Value
Previously selected output handler.

Parameters

handler
    New OCR Output handler function.


Comments

If the output mode is OT_TEXT, OCR events among OT_PROP, OT_ITAL, 
OT_UNDS, OT_SIZE, OT_HILT and OT_BITM are not sent to the output hander.

An OCROutputHandler has the following form:

void AnOCRHandler(int event, int param);

with event, the code of the "OCR event" and param a value associated with the event.

The OCR events are:

OT_TEXT
    A character has been recognized. param contains the ASCII code of the recognized character.

OT_PROP
    The font type has changed (proportional or non proportional font). param is nonzero if the font is proportional.

OT_ITAL
    Switches italic mode on or off. param is nonzero if the following characters are italic.

OT_UNDS
    Switches underscored mode on or off. param is nonzero if the following characters are underscored.

OT_SIZE
    Changes the character size. param contains the font size for the following characters.

OT_HILT
    Changes the character color. If param contains 1, the following word is not in the dictionary. if param contains 2, the following word has not been well recognized.

OT_ENDL
    An end of line has been reached.

OT_ENDZ
    An end of text area has been reached.

OT_BITM
    An image has been recognized. (IMG *) param is a pointer to the image.

OCRSetProgressHandler

OCRProgressHandler OCRSetProgressHandler(OCRProgressHandler handler) 

When the OCR engine processes a document, a user defined function of type OCRProgressHandler, is called several times.

Return Value
Previously selected progress handler.

Parameters

handler
    New OCR Progress handler function.


An OCRProgressHandler has the following form:

int AProgressHandler(int percent);

with percent, the percentage of the job completed at the time of the call. This value is between 0 and 100.

Defining such a function allows an application to display a progress bar. With this function, it's also possible to interrupt the OCR process. If the progress handler returns a non zero value, the OCR process is stopped.

SetLanguage

void SetLanguage(int language, const char* dictDir) 

Selects the language used in the text you want to process.

Return Value
None.

Parameters

language
    A value among:

    ENGLISH
        English language.

    FRENCH
        French language.

    NONE
        No language selected.

dictDir
    The directory where the dictionary files are stored.

SetOutputMode

void SetOutputMode(int mode) 

Selects the output mode for the OCR engine

Return Value
None.

Parameters

mode
    A value among:

    OT_TEXT
        The engine will output only the text.

    OT_RICHTEXT
        The engine will output the text and additional information like characters format, characters size, and font type.

    OT_WINDOW
        The engine will output only the text directly in a window as it was typed on the keyboard.

SetOutputWindow

void SetOutputWindow(HWND hWnd) 

When the output mode OT_WINDOW has been selected with the SetOutputMode function, this function allows you to indicate in which window the text will be sent.

Return Value
None

Parameters

hWnd
    A window handler.

M.

Edited by marko001

Share this post


Link to post
Share on other sites



Got also this API for Loading Images:

LoadImg

IMG * LoadImg(const char * filename) 

Loads an image from a TIFF file.

Return Value
A pointer to the loaded image or NULL if the function fails.

Parameters

filename
    TIFF file name

anyway I get a strange error: when I open it with $dll = DllOpen("ocrdll.dll") I get a -1 handle (user32.dll gives me 1)

M.

Share this post


Link to post
Share on other sites

Solved the problem with the error (needed to run AutoIt at 32 bit)

Anyway I use this:

$image = @ScriptDir & "\screenshot.99.tif"
$dll = DllOpen("ocrdll.dll")
$imghndl = DllCall($dll,"int","LoadImg","str",$image)
;$text = DllCall($dll,"str","OCR","ptr",$imghndl)

but it returns me 0 instead of the pointer. Is the sintax correct?

M.

Share this post


Link to post
Share on other sites

Just corrected your example, not based on previous documentation.

Also you may add error handler, search Helpfile/forum for examples with error handler.

$image = @ScriptDir & "\screenshot.99.tif"
$dll = DllOpen("ocrdll.dll")
$imghndl = DllCall($dll,"int","LoadImg","str",$image)
$text = DllCall($dll,"str","OCR","ptr",$imghndl[0])
MsgBox(0,'Result',$text[0])

Share this post


Link to post
Share on other sites

I know about errorhandler, just would like to speedup it and often msgbox is the best friend ^^

Btw I got "(8) : ==> Subscript used with non-Array variable.:" as I expected due the fact that the 1st

$imghndl = DllCall($dll,"int","LoadImg","str",$image)

returns me 0 as msgbox

But the sintax should be correct since API is:

LoadImg

 IMG * LoadImg(const char * filename) 

Loads an image from a TIFF file.

Return Value
A pointer to the loaded image or NULL if the function fails.

Parameters

filename
    TIFF file name


Comments

When you don't need the loaded image anymore, you have 
to free it by calling the FreeImg function. 
If you load a multiple image TIFF file, 
only the first image stored in the file is loaded. You have to use 
LoadMultipleImg for handling multiple image files

Example

IMG *img;

img=LoadImg("foo.tif");
if (img==NULL) {
  // error processing
}

Share this post


Link to post
Share on other sites

Tried also on a x32 system (vitrual machine running xp) and got same error.

Any suggestion?

Share this post


Link to post
Share on other sites

I'm not skiled enough to create a COM error handler :huh2:

Share this post


Link to post
Share on other sites

Zedna have you been drinking again?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Btw I tried

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

Func MyErrFunc()

  Msgbox(0,"AutoItCOM Test","We intercepted a COM error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
Endfunc

But found no errors (or probably I didn't declare it in the correct way)

Share this post


Link to post
Share on other sites

Use COM error handler! It will give you exact error description for your DllCall()

Sorry, my bad.

Use _WinAPI_GetLastErrorMessage() to get exact error description after your DllCall().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0