Sign in to follow this  
Followers 0
hsoltau

OCR again...

12 posts in this topic

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

:)

Share this post


Link to post
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

Share this post


Link to post
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

:)

Share this post


Link to post
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

Share this post


Link to post
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

:)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I use an external exec to convert the JPG files to text with a free soft called GOCR. Just google "gocr voice" and you'll find the thing.

cheers

Share this post


Link to post
Share on other sites

The most accurate OCR engine for text is called Tesseract.

code.google.com/p/tesseract-ocr/

If your text is small, you will have to resize the images using GDIPlus.

This engine does a stellar job on everything above 8pt.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Hello i'm new and i'll talk to anyone so "hello" to you all...I like this forum very much and I wish there are much more postings here because I would like to exchange as much information as I can.Hope everyone is doing great.

Here my question is how to convert a image bitmap into jpeg ?

data conversion services

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

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