Jump to content

Real OCR in AU3 - in a few lines.


ptrex
 Share

Recommended Posts

Hey I'm having some trouble.

The first error I got for undeclared variables and found them in here after running the check

$Viewer = GUICreate ( "Embedded MODI Viewer", 640, 580,(@DesktopWidth-640)/2, (@DesktopHeight-580)/2 , _ 
                    $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

I added Dim statements so at least it would run and it did. It read the file too which was excellent but here's the problem. It froze when it opened the modi window and i had to force quit that window so that the results would pop up.

Did something go wrong with the autoit installation with those variables missing or something like that? Maybe a better question is what the WS_ variables are

All help is appreciated. I'm running Vista i that makes a difference, Office 2003.

Link to comment
Share on other sites

@climberman

Maybe if you add

This might get you going

regards

ptrex

Yes that absolutely did the trick. AutoIt is a bit different than what im used to pragramming mathematical stuff but your posts are very helpful. If I'd read up on the function maybe I would've caught that mistake.

Anyways, I threw in my own twist as a test to capture a window and it worked with your script. I downloade a vista sidebar gadget to see my mouse coordinates since I can't think of a good way to see that on the fly without writing something myself and taking way too long to get it to work.

I plan to replace my addition with a specific region screen capture. After seeing the offshoot with minicap.exe, this way seems much better, plus the minicap thing didn't work for me. so thx ptrex and here's some code for anyone else interested.

;Wait for the window so that we capture it 
    $sTargetImage = "C:\Users\Brian\Desktop\OCR_tgt.jpg"
    $sTargetTitle = "Untitled - Notepad"
    WinWaitActive( $sTargetTitle )
    _ScreenCapture_CaptureWnd($sTargetImage, WinGetHandle($sTargetTitle))

The built in screen capture function needs to be included. O and the mouse can be turned off but i didn't bother since this was a test

Link to comment
Share on other sites

Can anybody confirm this working on Vista Ultimate x86 with Office 2007 ?

----------------------------------90% of teens today would die if Myspace,Bebo + FaceBook had a system failure and was completely destroyed. If you are one of the 10% that would be laughing, copy and paste this to your signature.----------------------------------Code to win, 'till you die, 'till the compiler dies from your linesCode to win, take it all, just keep coding till you fallDay by day, codin' all the way, I'm not cavin' inLet another App begin, code to win

Link to comment
Share on other sites

Just spent half a day on getting this to work.

So for ppl having the same problems as me:

#1: doesn't work on x64 v. of autoit -> use either unicode or ANSI v. of autoit

#2: When I installed my Office 2007 I unchecked some features of it. When I used full instalation, this started to work.

Link to comment
Share on other sites

  • 1 month later...

Func OCR_Region($x,$y,$width,$height)oÝ÷ ØZèÚòx-+ºw-èºÙÉ·­êZ­©µêïj¸nW¬².ÖÞ²¶§X¤zØb²)ìµæjëh×6Func OCR_Region($left,$top,$right,$bottom)

The "$width" and "$height" does not seem to be correct when testing this function out with Office 2003 SP3 installed.

Sorry if this was already covered somewhere. Thanks for the functionality! :P

Link to comment
Share on other sites

So far I've been having great success with this, but now have encountered a strange problem.

I have the OCR in several different functions.

The first time, it executes with a certain file just fine and exits the function.

The next time, it uses a different image just fine but in a seperate function and the exits the function.

The third time, it goes back into the same function and whether it reads a different file or not, the OCR fails, even if it was the same image as before but only renamed.

I tried throwing in a close statement to the document but it didn't give a fix.

Any ideas?

Link to comment
Share on other sites

So far I've been having great success with this, but now have encountered a strange problem.

I have the OCR in several different functions.

The first time, it executes with a certain file just fine and exits the function.

The next time, it uses a different image just fine but in a seperate function and the exits the function.

The third time, it goes back into the same function and whether it reads a different file or not, the OCR fails, even if it was the same image as before but only renamed.

I tried throwing in a close statement to the document but it didn't give a fix.

Any ideas?

Sorry for this earlier post, I just cleaned up some of the code that seemed like extra junk and it took care of the problem.

Link to comment
Share on other sites

  • 2 weeks later...

Hello

it's just me or when i give a small areas to OCR i get COM Error ?

for example OCR_Region (19,619,49,707) and i get the COM Error is this normal ?

Here is my function

Func OCR_Region($x,$y,$x1,$y1)
    Const $miLANG_ENGLISH = 9

    $file_name = "C:\VRT_Temp.png"
    _GDIPlus_Startup ()
    _ScreenCapture_Capture ($file_name, $x,$y, $x1,$y1, False)

    Dim $miDoc = ObjCreate("MODI.Document")
    $miDoc.Create($file_name)
    $miDoc.Ocr($miLANG_ENGLISH, True, True)

    Dim $str = $miDoc.Images(0).Layout.Text
    
    FileDelete($file_name)
    
    _GDIPlus_ShutDown ()
    
    Return $str
    
EndFunc
Edited by Sand
Link to comment
Share on other sites

  • 2 weeks later...
Link to comment
Share on other sites

@APPLEEATER

I mainly use this OCR within VM's, and dont want the overhead of Office on every instance. So i just install MODI. You can just download the Microsoft Office Document Imageing from MSDN, im not sure if this is the exact link for wuttever OS you use. MSDN LINK

EDIT: wrong link, lemme see if i can find the one where i downloaded mine.

EDIT2: I think Ptrex is correct, you cant download it through MSDN seperate anymore??? or atleast I cant seem to find the install package, only the reference. I have looked through my backups and found the .dll's I was installing, the main one I think you want is MDIVWCTL.DLL.

Edited by ofLight

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

  • 2 weeks later...

oh hi. great work on this, ptrex, it will be very useful to me.

@ofLight: do you mean this works without office installed? just with modi2003.exe installed? i'll try removing office to verify this.

btw if anyone has trouble getting modi2003.exe i can upload it somewhere, unless i'm not allowed to (haven't actually READ the eula, lol)

Link to comment
Share on other sites

  • 1 month later...

oh hi. great work on this, ptrex, it will be very useful to me.

@ofLight: do you mean this works without office installed? just with modi2003.exe installed? i'll try removing office to verify this.

btw if anyone has trouble getting modi2003.exe i can upload it somewhere, unless i'm not allowed to (haven't actually READ the eula, lol)

It is available to download from Microsoft at modi2003.exe download.

BotWriter

Link to comment
Share on other sites

  • 2 months later...

I hope Ptrex et al. are still willing to answer questions regarding this script... I see that a lot of people are having success with it which makes me feel great! I however, am getting COM errors and believe I have checked everything that others have said.

I have created a .tiff and placed it in C:\Temp\MyPic.tiff

I have objects in the C:\Program Files\Common Files\Microsoft Shared\MODI\12.0\ -- specifically 30 files, including dll's for a total of 6.7 MB, no M*.dll though

I am getting a rough total of 9 COM errors, and an error when closing the MODI window. I have taken a screenshot of the sorts of COM errors I am getting and hope someone can point in my in the right direction. I have office 2007, and have also tried downloading the '03 MODI executable. It dumps 2 files, one HTML file and one CHM file so I am unsure if that is the way to go - regardless I do have the 2007 MODI objects as stated above.

Could anyone lend assistence? I would love to be able to use Ptrex source and maybe even the minicap dumps provided by trids. You guys are great, any help would be greatly appreciated. Cheers.

PS: I could be missing something totally stupid-simple, so please dont hold it against me :)

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...