Sign in to follow this  
Followers 0
USBFreak

MODI OCR and using TIF from memory (avoid write to disk)

4 posts in this topic

Hi all,

I have this working example, it captures a rectangle of active window and saves it as TIF, then the second part does OCR using Microsoft's MODI :

;save file here
$Filename = 'C:\test.tif'
;coordinates to grab
$Coordinates = _ArrayCreate(350, 315, 450, 490)
;$Coordinates = _ArrayCreate(45, 595, 100, 610)
;Capture screen
_ScreenCapture_CaptureWnd($Filename, WinGetHandle(""), $Coordinates[0], $Coordinates[1], $Coordinates[2], $Coordinates[3], False)


;OCR part
Const $miLANG_ENGLISH = 9

$miDoc = ObjCreate("MODI.Document")
$miDoc.Create($Filename)
$miDoc.Ocr($miLANG_ENGLISH, True, False)

For $oWord in $miDoc.Images(0).Layout.Words
;If StringInStr($oWord.text, "$") Then
    ;output words in console
        ConsoleWrite($oWord.text & @CRLF)
;EndIf
    
Next

All is well here, but I'd like to avoid saving files to disk and then reading them back in for MODI - If I can use graphics directly that would be great. I'm not sure however how to pass the handle (and whether it can be done at all in this case).

Another thing is that OCRing a simple image (about 100 x 150 pixels) with a few words (actually a capture of part of AutoIt Help window) takes some 2,5 seconds. Far cry from some other screenscraping programs which do it in under 50 miliseconds, but they can't help me in this particular scraping/OCRing case.

Any help appreciated as always.

Share this post


Link to post
Share on other sites



No takers?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well, lets start with the help files:

_ScreenCapture_CaptureWnd

Remarks

If FileName is not blank this function will capture the screen and save it to file. If FileName is blank, this

function will capture the screen and return a HBITMAP handle to the bitmap image. In this case, after you are

finished with the bitmap you must call _WinAPI_DeleteObject to delete the bitmap handle. All coordinates are in

client coordinate mode.

So, try and do this:

$image = _ScreenCapture_CaptureWnd( "" , WinGetHandle(""), $Coordinates[0], $Coordinates[1], $Coordinates[2], $Coordinates[3], False)

Then, see if you can use $image in your OCR thing.

But then you have to destroy that handle using _WinAPI_DeleteObject as the remarks says.

I'm not sure if all of this would work.

That's why I'm saying "try". :D

Edited by Derak

[quote]#include <AutoIt.au3> [indent]$Nothing = Impossible[/quote] [/indent]

Share this post


Link to post
Share on other sites

Well, lets start with the help files:

So, try and do this:

$image = _ScreenCapture_CaptureWnd( "" , WinGetHandle(""), $Coordinates[0], $Coordinates[1], $Coordinates[2], $Coordinates[3], False)

Then, see if you can use $image in your OCR thing.

But then you have to destroy that handle using _WinAPI_DeleteObject as the remarks says.

I'm not sure if all of this would work.

That's why I'm saying "try". :D

Thanks, I thought of this but can't figure out how to use handle with

$miDoc = ObjCreate("MODI.Document")

$miDoc.Create($Filename)

$miDoc.Ocr($miLANG_ENGLISH, True, False)

How to do $miDoc.something and give it handle of the image?

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