Sign in to follow this  
Followers 0
leonick5

Pls Help with calling DLL function(Powerful OCR)

3 posts in this topic

Hey everybody.

I know probably this is very basic,...but it gives me headache for several days.(Google and Autoit-search are exhausted) :

This is a very powerful OCR which is able to read windows directly, where other solutions fail.

SDK library(demo) http://www.screenocr.com/screen-ocr-library-sdk.htm

The simple Problem is, that I've read 2 days about DLLs, but dont get how to do it.

OCRSDK.DLL does the magic.

Documentaion says:

Text capturing and recognition. 
TextractSource class reference defines where to get a source image for recognition. It can be a file or an area of the screen, see details below. 
TextractDest class reference defines where to store the results of recognition. It can be memory area or a file with a specified name, see details below. 
TextractDestFormat specifies output format with the use of format flags dfText, dfRtf, etc , which are described in "Screen OCR SDK control flags and output formats" section.

class TextractSource {
 public:
  TextractSource();
  TextractSource& BmpFile(const char *bmpFileName);
  TextractSource& Wnd(HWND);
  TextractSource& Rect(int ax, int ay, int bx, int by);
  TextractSource& DesktopWnd();
  TextractSource& TopWnd(const char *windowClass, const char *windowText);
  TextractSource& DeepWnd(const char *windowClass, const char *windowText);
  TextractSource& SubWnd(const char *windowClass, const char *windowText);
  TextractSource& SubDeepWnd(const char *windowClass, const char *windowText);
  TextractSource& FindLargestWindow();

  const char *BmpFileName; // used if != NULL
  HWND W; // used if != NULL
  int AX, AY, BX, BY; // used if BmpFileName == NULL and Wnd == NULL
};

TextractSource& BmpFile(const char *bmpFileName);

Specifies the file name of a bitmap, designed for recognition.

TextractSource& Wnd(HWND);

Specifies the handle of a window, designed for recognition.

TextractSource& Rect(int ax, int ay, int bx, int by);

Specifies the screen area, designed for recognition. 
ax,ay and bx,by are upper left (inclusive) and lower right (exclusive) corners of area.

TextractSource& DesktopWnd();

Specifies the desktop window as a window designed for recognition.

TextractSource& TopWnd(const char *windowClass, const char *windowText);

Specifies the top-level window, with windowClass as a window class name and windowText as a window caption (title) name.

TextractSource& DeepWnd(const char *windowClass, const char *windowText);

Specifies the child window with a desktop window as a parent window, with windowClass as the window class name and windowText as the window caption (title) name.

TextractSource& SubWnd(const char *windowClass, const char *windowText);

Specifies the child window in any match of a tree, with W as a parent window, with windowClass as the window class name and windowText as the window caption (title) name.

TextractSource& SubDeepWnd(const char *windowClass, const char *windowText);

Specifies the child window in any match of a tree, with W as a parent window with windowClass as the window class name and windowText as the window caption (title) name.

TextractSource& FindLargestWindow();

Specifies the largest child window of an active window as a window for recognition.

TextractSource is used to specify what to capture and what to recognise. 
Typical uses are:
Textract(TextractSource().BmpFile("MyImage.Bmp") ... to recognise the text from a  bitmap, captured from the screen some other way.
Textract(TextractSource().Rect(0,0, 100,200) ... to capture text from  a rectangle, located at (0,0) - (100,200).
TextractCapture(TextractSource()
  .TopWnd(NULL, "Inbox - Outlook Express")
  .SubDeepWnd("SysTreeView32", "") ... to capture text from the visible area of a window (HWND) with the class name SysTreeView32, find anywhere in the child windows (HWNDs) of top level window with a title "Inbox - Outlook Express". Methods DesktopWnd, TopWnd and DeepWnd... are designed to work together to specify the required window with known accuracy.
Textract(TextractSource().FindLargestWindow() ... to catch the largest visible subwindow on the screen. It's useful to capture terminal emulator window. 

class TextractDest {
 public:
  TextractDest(const char *destFileName);
  TextractDest();

  const char *FileName; // NULL if area specifeid, else dest file name
  void *Area; // NULL if file name specified, else memory area
  int AreaSize;
};
TextractExport TextractSuccess TextractDestFree(TextractDest&);

TextractDest  - is used to specify where to save captured results. 
Typical uses:
Textract(... , TextractDest("Results.Txt") ...  to save results in a specified file.

TextractDest dest;
Textract(... , dest, ...);
... use dest.Area of size dest.AreaSize ...
TextractDestFree(dest);
to use results in memory. TextractDestFree is used to free memory, allocated for results of recognition, if memory output mode is used. 

enum TextractDestFormat {
enum TextractItemType { ...
class TextractItem { ...

Specifies output formats and layouts of binary (dfBinary) or verbose (dfVerbose) modes. They are all described in "Screen OCR SDK control flags and output formats" section.

Operational environment. Font database, INI
TextractInit() searches for the OCRSDK.INI file to load parameters, see OCRSDKcl.EXE description. 
If OCRSDK.INI cannot be found, tsIniNotFound is returned.

TextractInit() loads the font database file, specified in INI
[Options]
Database Path =<path>\OCRSDK.PAT.
If this file is not found, TextractInit returns tsPatNotFound.

As in the doc said,..I found out, that the following initialy prepares the DLL for usage.

$dll = DllOpen("D:\OCRSDK\OCRSDK.DLL")
$test = DllCall("OCRSDK.DLL","int","TextractInit")

A Message "Trial-Peroid" pops up that tells me it was sucessful

In the forums I found this solution of using this specific OCRSDK.INI

Posted 01 December 2009 - 02:06 AM

$tTextractSource = DllStructCreate("ptr BmpFileName;hwnd W;int AX;int AY;int BX;int BY;")
$pTextractSource = DllStructGetPtr($tTextractSource)
$aRes = DllCall("dllname.dll", "int:cdecl", "Textract", "ptr", $pTextractSource, "ptr", $pTextractDest)

Several things are assumed here: TextractSuccess is an enumeration (int), that class is a simple one, no polymorphism is involved and that the calling convention is __cdecl. Change the necessary fields.

He says just to Change the necessary fields...but I've tried everything for hours....

also tried to use DllStructSetData and all the related stuff....but still no clue how to use it.

So I reeeealy would aprreciate, in a working example of how-to use this function. :D

Thank you for anyone trying to help. :D:huggles:

regards

Leonick

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

not one replay in 2 days? :D

So far i got this:

NO returned @error...but nothing happens.

I am sure my syntax is wrong somewhere.

#include <Array.au3>
$dll = DllOpen("C:\Program Files\OCRSDK\OCRSDK.DLL")


$1 = DllCall($dll,"int","Textractinit")
$aRes = DllCall($dll, "int:cdecl", "Textract","ptr","textractsource()","int","0","int","0","int","500","int","500","ptr","TextractDest()","str","z:\123456.txt")
if @error then
ConsoleWrite("--:"&@error)
EndIf

_ArrayDisplay($aRes)
Edited by leonick5

Share this post


Link to post
Share on other sites

Had to bump this.

Also wondering how to get calls to and from textract.dll to work 100%.

The documentation that comes with it is sparse and does not even have error code tables.

Please if anyone can help with this please do. I'm begging for some clarity!

Sorry I have no code to add.

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