Jump to content

Help with a GOOD OCR


Recommended Posts

is possible to have output in a file text ?

just feed the output to a file instead of to arraydisplay

#include <Array.au3>
#include <ScreenCapture.au3>

Sleep(1000)
$Loc = WinGetPos("")
_ScreenCapture_Capture(".\Render.bmp",$Loc[0],$Loc[1],$Loc[0]+200,$Loc[1]+30)
Sleep(500) ;give file time to be created
$output = _OCR(".\Render.bmp")


$file = FileOpen("output.txt",1)
For $i = 0 to UBound($output)
    If $output[$i] = "" Then ExitLoop
    FileWriteLine($file,$output[$i])
Next
FileClose($file)

;_ArrayDisplay($output)

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

Hi , ofLight .

I'm so stupid , I know nothing about au3 , and I just tried your OCR code , but it turns out

"$miDoc.Ocr(9, True, False)^ERROR

Error: The requested action with this object has failed."

I don't know what' wrong ,all i did is save your code as a au3 file , and put a file named image.bmp

to C:\ , run the au3 file (i have ms office2003 installed)

Link to comment
Share on other sites

Hi , ofLight .

I'm so stupid , I know nothing about au3 , and I just tried your OCR code , but it turns out

"$miDoc.Ocr(9, True, False)^ERROR

Error: The requested action with this object has failed."

I don't know what' wrong ,all i did is save your code as a au3 file , and put a file named image.bmp

to C:\ , run the au3 file (i have ms office2003 installed)

Your image will be very small.

Paste ur image in paint and use some white space which is provided along with it...Save it

and run ur code..

It will work :)

Link to comment
Share on other sites

Your image will be very small.

Paste ur image in paint and use some white space which is provided along with it...Save it

and run ur code..

It will work :)

try this it will work

#include <Array.au3>

#include <ScreenCapture.au3>

WinActivate("EFI Colorproof XF Client")

; Capture region

;$file1= _ScreenCapture_Capture("C:\GDIPlus_Image2.bmp", 141, 572, 850, 950)

;$file2= _ScreenCapture_Capture("C:\menu1.bmp", 1053,123, 1111, 141)

$menu_XF = _ScreenCapture_Capture("C:\menuXF3.bmp",873,123,1282,169)

$output = _OCR("C:\menuXF3.bmp")

;================================= OCR =======================================

; Function Name:

; Description: Searches a bmp file for all recognizable characters and returns them in an array

; Requires: Microsoft Word must be installed on system & <Array.au3>

; Parameters: $file bmp file to search

;

; Syntax: _OCR($file)

; Returns: $Array[1] = 0 on failure, $Array on success

;

;===============================================================================

Func _OCR($file)

Dim $miDoc, $Doc, $str, $oWord, $sArray[500]

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

$miDoc = ObjCreate("MODI.Document")

$miDocView = ObjCreate("MiDocViewer.MiDocView")

$miDoc.Create($file)

$miDoc.Ocr(9, True, False)

$MiDocView.Document = $miDoc

$MiDocView.SetScale (0.75, 0.75)

$i = 0

For $oWord in $miDoc.Images(0).Layout.Words

$str = $str & $oWord.text & @CrLf

$fileopen = FileOpen("C:\test.txt", 1)

If $fileopen = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

ConsoleWrite($oWord.text & @CRLF)

;MsgBox(0,"Console writing",$oWord.text)

FileWrite($fileopen, $oWord.text & @CRLF)

; Check if file opened for reading OK

$sArray [$i] = $oWord.text

;$sArray = $oWord.text

$i += 1

$i += 1

Next

Return $sArray

EndFunc;========================== OCR ========================================

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...