Jump to content

OCR again...


hsoltau
 Share

Recommended Posts

hi ,

iam reading all the posts about screen capturing and ocr, but still i am a little bit lost...

i have this sofar (credits to the developers)

#include <ScreenCapture.au3>
WinActivate("CwApi")


; Capture region
$file= _ScreenCapture_Capture(@ScriptDir & "\GDIPlus_Image2.bmp", 50, 68, 150, 85)

this gives me a bitmap with an ID of Patient Master Index, i like to have it in a variable i.e. $id

i have to screen capture because its a java application ...

so, what have i to do wiht this tiny image to get the text of it ???

thanks in advance and have a nice day...

Henning

:)

Link to comment
Share on other sites

thanks for posting whim, but yes ive seen this...

interesting stuff but way to much code to understand for me and i am not able to use it for my task...

i now have tried with this MODI stuff which is used by a script from ptrex (i think) and trids script

;
;
;   minicap_au3.exe .. automation of minicap.exe (screen capture commandline utility)
;   -> http://www.softpedia.com/get/Multimedia/Gr...e/MiniCap.shtml
;
Global $oMyError = ObjEvent("AutoIt.Error","_OCRErrFunc")

;Dependencies
   ;FileInstall( "D:\_#WWW\MiniCap - 1.08.02\MiniCap\MiniCap.exe", @SYSTEMDIR & "\" )

;Wait for the window so that we capture it 
    $sTargetImage = "D:\Autoitscripts\Krams\cwapiIDscan\GDIPlus_Image2.jpg"
    $sTargetTitle = "Untitled - Notepad"
   ;WinWaitActive( $sTargetTitle )
    
#cs
--------------------------------------------------------------------------------
;Capture the target by PID
    $nPID = WinGetProcess( $sTargetTitle )
    $sSwitches = ' -save "' & $sTargetImage & '"'
    $sSwitches &= ' -capturepid ' & $nPID 
    $sSwitches &= ' -exit'
    RunWait( @COMSPEC & ' /c minicap.exe ' & $sSwitches, "", @SW_HIDE)
--------------------------------------------------------------------------------
#ce


;Now lets do something with the saved image .. 
;.. like OCR it and see what it says
    $sTargetText = _OCRGetText( $sTargetImage )

;Display the results
    Msgbox( 0, @SCRIPTNAME, "Results of OCR:" & @LF & $sTargetText )

Func _OCRGetText( $Image )
Local $oDoc = ObjCreate("MODI.Document")
    $oDoc.Create($Image)
    If @ERROR Then Return SetError(1)
    $oDoc.Ocr(9, True, False)       ;ENGLISH = 9
    If @ERROR Then Return SetError(2)
    Return $oDoc.Images(0).Layout.Text
    $oDoc = 0
EndFunc


Func _OCRErrFunc()
  $HexNumber = hex($oMyError.number, 8)
  Msgbox(0, @SCRIPTNAME,"We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @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)
  SetError(1) ; to check for after this function returns
Endfunc

it starts but gives me a Com Error:

post-11529-1202472306_thumb.jpg

this is the jpg i like to OCR:

greetings

Henning

Link to comment
Share on other sites

now,

i made a tif out of the jpeg and opened it with Microsoft Office Document Imaging program and tried to ocr it, but theres a message that it cannot find any text in the document ?

is the image to small, isnt it possible because there a only numbers in it ?

i am stuck...

Henning

:)

Link to comment
Share on other sites

The image probably is too small. I get the same error with this image, but woth other images all recognized correctly.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

yep, you are right...

i just found the comment from smoke n on the REAL OCR topic and made my jpg screenshot a little bigger...

and tada: it works :)

now i have to get rid of the characters i dont need or learn how to search through the array, cause all i need is the id...

or is it possible to make the canvas of the small image bigger ???

thanks for helping, this is great because now i am able to grab alot of stuff of this java window i am scanning...

bye

Henning

:)

Link to comment
Share on other sites

hi again,

this modi ocr has problems with recognizing 0 and 8, its mixing these 2 numbers sometimes...

what possibilities do i have to get better ocr results, should i zoom the image (how with autoit) or change background color (how with autoit) ?

any suggestions are welcome...

Henning

Link to comment
Share on other sites

  • 1 month later...
  • 7 months later...
  • 2 months later...

Here is an example:

$path = 'C:\Documents and Settings\User2\tesseract-2.01'
Run(@ComSpec  &" /c " & 'tesseract phototest.tif phototest', $path, @SW_HIDE)
$Text = FileRead($path&'\phototest.txt')
MsgBox(0, "", $Text)

Posted Image

I agree with you Oldschool.

In fact I was so impressed with Tesseract that I began developing a UDF for it. Click on this link to have a look -> Tesseract UDF.

Edited by seangriffin

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
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...