Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Real OCR in AU3 - in a few lines.


  • Please log in to reply
137 replies to this topic

#1 ptrex

ptrex

    Universalist

  • MVPs
  • 2,408 posts

Posted 02 August 2007 - 01:21 PM

Real OCR in AU3

In the support forum I saw serveral posts about OCR.
And this has been discussed over and over again in a rather complex way.

This gives you OCR in no time and no effort.

MODI automation provides powerful document management and OCR features; however, it does not automate the document scanning process itself or support image annotation.

AutoIt         
; <a href='http://msdn2.microsoft.com/en-us/library/aa202819(office.11' class='bbc_url' title='External link' rel='nofollow external'>http://msdn2.microsoft.com/en-us/library/aa202819(office.11</a>).aspx #include <GUIConstants.au3> #include <Array.au3> Dim $miDoc, $Doc Dim $str Dim $oWord Dim $sArray[500] Const $miLANG_CZECH = 5 Const $miLANG_DANISH = 6 Const $miLANG_DUTCH = 19 Const $miLANG_ENGLISH = 9 Const $miLANG_FINNISH = 11 Const $miLANG_FRENCH = 12 Const $miLANG_GERMAN = 7 Const $miLANG_GREEK = 8 Const $miLANG_HUNGARIAN = 14 Const $miLANG_ITALIAN = 16 Const $miLANG_JAPANESE = 17 Const $miLANG_KOREAN = 18 Const $miLANG_NORWEGIAN = 20 Const $miLANG_POLISH = 21 Const $miLANG_PORTUGUESE = 22 Const $miLANG_RUSSIAN = 25 Const $miLANG_SPANISH = 10 Const $miLANG_SWEDISH = 29 Const $miLANG_TURKISH = 31 Const $miLANG_SYSDEFAULT = 2048 Const $miLANG_CHINESE_SIMPLIFIED = 2052 Const $miLANG_CHINESE_TRADITIONAL = 1028 ; Initialize error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $miDoc = ObjCreate("MODI.Document") $miDocView = ObjCreate("MiDocViewer.MiDocView") $Viewer = GUICreate ( "Embedded MODI Viewer", 640, 580,(@DesktopWidth-640)/2, (@DesktopHeight-580)/2 , _                     $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) ;Creates an ActiveX Control in the GUI. $GUIActiveX = GUICtrlCreateObj ($miDocView, -1, -1, 640, 580) GUICtrlSetResizing ($Viewer, $GUI_DOCKAUTO) $miDoc.Create("C:_AppsAutoIT3COMMODIdeclaration.tif") $miDoc.Ocr($miLANG_ENGLISH, True, False) ; Show GUI GUISetState () $MiDocView.Document = $miDoc $MiDocView.SetScale (0.75, 0.75) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend $i = 0 For $oWord in $miDoc.Images(0).Layout.Words     $str = $str & $oWord.text & @CrLf         ConsoleWrite($oWord.text & @CRLF)     $sArray [$i] = $oWord.text     $i += 1 Next _ArrayDisplay($sArray,"OCR Result") ;MsgBox(0,"",$miDocView.FileName) ;------------------------------ This is a COM Error handler -------------------------------- Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Error Test","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


Forgot to tell that Office 2003 is needed.

PS : Added all available languages.

Enjoy !!

ptrex

Edited by ptrex, 14 September 2012 - 09:38 AM.








#2 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,557 posts

Posted 02 August 2007 - 02:17 PM

Great!

It's working.

#3 ptrex

ptrex

    Universalist

  • MVPs
  • 2,408 posts

Posted 02 August 2007 - 02:20 PM

@Zedna

Thanks.

I always tend to test the scripts before posting :)

Which is not always the same thing as delivering a working script :">

See you around,

regards,

ptrex

#4 gseller

gseller

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,057 posts

Posted 02 August 2007 - 03:11 PM

Awesome!! Works with Office 2007 also. My hopes one day are to have an OCR Setup in autoit tht we can use the rubberband method and copy text from anythingon screen... Great Job ptrex! Cannot wait to see where this goes.

#5 Toady

Toady

    Easy there turbo...

  • Active Members
  • PipPipPipPipPipPip
  • 698 posts

Posted 02 August 2007 - 03:15 PM

Very nice find! I will find a great use for this in the near future :)
www.itoady.com (Go here to download the MacroGamer installer)

#6 ptrex

ptrex

    Universalist

  • MVPs
  • 2,408 posts

Posted 02 August 2007 - 03:20 PM

Thanks all !!

I am wondering if someone could check if it is working in a lower version than Office 2003 ?

Regards

ptrex

#7 Automan Empire

Automan Empire

    Wayfarer

  • Active Members
  • Pip
  • 51 posts

Posted 02 August 2007 - 04:07 PM

Does not work with Office 97.
"I've seen your work in the past, and it's novice at best..." SmOke_N

#8 sandman

sandman

    I ❤ WordPress

  • Active Members
  • PipPipPipPipPipPip
  • 1,303 posts

Posted 02 August 2007 - 05:54 PM

Works with Office 2000. Wow, that's really cool!

"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();


#9 SleepyXtreme

SleepyXtreme

    Prodigy

  • Active Members
  • PipPipPip
  • 194 posts

Posted 02 August 2007 - 06:26 PM

What exactly is OCR?
Programs:AAST (Andrew's Anti Snooping Tool) - Elite protection from prying eyes with tons of functionality_TooBigForForums - Downloads your program and opens it (For when you have exceeded your upload limit but still want to know how many downloads you have).

#10 sandman

sandman

    I ❤ WordPress

  • Active Members
  • PipPipPipPipPipPip
  • 1,303 posts

Posted 02 August 2007 - 07:08 PM

http://en.wikipedia.org/wiki/Optical_character_recognition

"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();


#11 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,250 posts

Posted 02 August 2007 - 11:01 PM

Thanks!

But not workin for me :P - i getting many COM errors - my Office 2003 is on russian, maby i need to change something? like $miLANG_ENGLISH = ? (what the value for russian?).

And the link in the top of example is not good :)

Edited by MsCreatoR, 02 August 2007 - 11:05 PM.

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

Posted Image AutoIt Russian CommunityPosted Image Projects: 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 ProgramPosted Image UDFs: 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 UDFPosted Image Examples: 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#12 piccaso

piccaso

    Rock me, Amadeus!

  • MVPs
  • 893 posts

Posted 02 August 2007 - 11:24 PM

I have Office 2003 installed but dont have that 'MODI.Document' object.
any idea why?
Posted Image CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

#13 Siao

Siao

    RTFM, foo!

  • Active Members
  • PipPipPipPipPipPip
  • 937 posts

Posted 02 August 2007 - 11:49 PM

Works with Office 2000. Wow, that's really cool!

Are you sure? In wikipedia it says it was introduced in Office XP, and my 2000 Pro certainly doesn't have this. I've never bothered with any service packs though.

Edited by Siao, 02 August 2007 - 11:50 PM.

"be smart, drink your wine"

#14 sandman

sandman

    I ❤ WordPress

  • Active Members
  • PipPipPipPipPipPip
  • 1,303 posts

Posted 03 August 2007 - 12:01 AM

Are you sure? In wikipedia it says it was introduced in Office XP, and my 2000 Pro certainly doesn't have this. I've never bothered with any service packs though.

I have Office 2000 with SP2 and it works fine.

"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();


#15 qazwsx

qazwsx

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 813 posts

Posted 03 August 2007 - 12:58 AM

i have 2002 with sp3 and it is not working. I get this error.
C:\Documents and Settings\*******\Desktop\New AutoIt v3 Script.au3 (28) : ==> Object referenced outside a "With" statement.:
For $oWord in $miDoc.Images(0).Layout.Words
For $oWord in $miDoc.Images(0)^ ERROR

I think i might be doing something wrong but im not sure.

Edited by qazwsx, 16 November 2010 - 08:46 PM.


#16 Toady

Toady

    Easy there turbo...

  • Active Members
  • PipPipPipPipPipPip
  • 698 posts

Posted 03 August 2007 - 03:10 AM

i have 2002 with sp3 and it is not working. I get this error.
C:\Documents and Settings\Steven Pecht\Desktop\New AutoIt v3 Script.au3 (28) : ==> Object referenced outside a "With" statement.:
For $oWord in $miDoc.Images(0).Layout.Words
For $oWord in $miDoc.Images(0)^ ERROR

I think i might be doing something wrong but im not sure.


Exact same thing for me too. :)
www.itoady.com (Go here to download the MacroGamer installer)

#17 ptrex

ptrex

    Universalist

  • MVPs
  • 2,408 posts

Posted 03 August 2007 - 06:53 AM

@All

Good to see that it is working in a variaty of MS Office versions !!

Some have still dificulty as I see.
The ones that have can do a little check : Open the registry and check if the MODI component is properly registered.

Go to -> HK_Classes_Root and check if you find an entry for "MODI.Document"

Also check of this exists on your machine : C:\Program Files\Common Files\Microsoft Shared\MODI

If not the COM component is not registered on your system.
Try repairing MS Office or install all components of Office and test again.

@MsCreatoR

Regarding the languages. I will add RUSSIAN too.

See first post.

Regards,

ptrex

Edited by ptrex, 03 August 2007 - 07:25 AM.


#18 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,250 posts

Posted 03 August 2007 - 12:17 PM

ptrex
Hi, thanks for the languages additions...

Go to -> HK_Classes_Root and check if you find an entry for "MODI.Document"


I have there some values.

Also check of this exists on your machine : C:\Program Files\Common Files\Microsoft Shared\MODI

It's exists (with many stuff in there).

But it still not working (even with my language) :) .

Try repairing MS Office or install all components of Office and test again.

I will try that later, thanks.
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: 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 ProgramPosted Image UDFs: 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 UDFPosted Image Examples: 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#19 ptrex

ptrex

    Universalist

  • MVPs
  • 2,408 posts

Posted 03 August 2007 - 01:25 PM

@MsCreatoR

Just to make sure, In order to have this example work you need to have a TIF file ready in the path specified in the Script :

"C:\Temp\Numbers.tif "

If not it will give errors.

This might be confusing looking at the CREATE statement in the script ?
It does not CREATE anything but OPENS it.

Regards,

ptrex

#20 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,250 posts

Posted 03 August 2007 - 02:10 PM

It does not CREATE anything but OPENS it.

Oh, now i see, thanks... but what do i write to this file? :)
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: 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 ProgramPosted Image UDFs: 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 UDFPosted Image Examples: 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users