It seems to me that there are a bunch of forum posts on OCR (and ODR), where a lot of people say "I used OCR with AHK", and others say "How do you use OCR with AHK?" But nobody has actually made a lib for it to make it easy to use. I went ahead and did it, cause I've been kinda wanting to do it for a while... so here you go!
OCR.zip v0.96 [AHK_basic] [AHK_L ANSI] [AHK_L Unicode] [32-bit or 64-bit]
Starting with 0.96, this lib should work fine with 64-bit. Let me know if there are any issues.
To start out, extract the zip and verify that the function works by running OCR-preview.ahk, and you should be able to see that the OCR program evaluates the area under the pink rectangle that is displayed. Try looking at larger text first, to make sure that it works. Then, feel free to use OCR-example.ahk to see what your code should look like. As with any AHK lib, you'll need the rest of the files to stay in a common lib directory, but you should only need to #include OCR.ahk to use the RunOCR() function.
Simply put, the OCR function will make a JPG screenshot of the region specified (using GDIp), convert it to a PNM (using djpeg.exe), then run gocr.exe to get a good guess of what that region contained. Note that smaller screen fonts are less reliable, and GOCR frequently confuses letters that look similar to one another (like lowercase T/F, L/I, etc...). There is also a parameter called "options" that allows you enter "debug" mode or "numeric"-only mode (just pass it a string with that text in it). Note that I'm planning a future version that should be capable of getting rid of some of the misinterpretations that GOCR makes, and thinking it will also be able to determine if a given string is displayed in a given region of the screen. Only time will tell.
Please feel free to give feedback, info on bugs, etc...
keywords: camerb OCR lib, Optical Character Recognition, Optical Digit Recognition, text in images,
OCR.ahk - Library for recognizing text in images
Started by
camerb
, Jul 15 2011 11:13 PM
88 replies to this topic
#1
-
Posted 15 July 2011 - 11:13 PM
Aren't you glad that I didn't put an annoying gif here?
Nice if it would work, but it didn't read a single letter unfortunately. I just unzipped it all and ran both the example and preview. OCR seems to be #included "as it is". I run Win7 x64 and AHK_L Unicode x32.
#2
-
Posted 16 July 2011 - 08:20 AM
Same here. Tried it, but it doesn't work. WinXP AHK_L Unicode x32
#3
-
Posted 16 July 2011 - 10:44 AM
I believe it will only work for AHK_basic at the moment. I'll see if I can get it working on AHK_L this week. Thanks for letting me know!
#4
-
Posted 16 July 2011 - 04:11 PM
Aren't you glad that I didn't put an annoying gif here?
worked ok for me on AHK Basic using the test script with the pink box. some letters were wrong though, but not your fault
you might also want to check out this older thread, its not exactly a library, but its a complete solution using gocr or tesseract. look towards the end of the thread where people had fixed some of the issues. i believe the technique used was to convert the image to black&white before doing the ocr to get more consistent results:
<!-- m -->http://www.autohotke...pic.php?t=11186<!-- m -->
you might also want to check out this older thread, its not exactly a library, but its a complete solution using gocr or tesseract. look towards the end of the thread where people had fixed some of the issues. i believe the technique used was to convert the image to black&white before doing the ocr to get more consistent results:
<!-- m -->http://www.autohotke...pic.php?t=11186<!-- m -->
#5
-
Posted 16 July 2011 - 07:15 PM
Uploaded version 0.91 - reduced the number of library dependencies and added support for AHK_L.
#6
-
Posted 19 July 2011 - 01:26 AM
Aren't you glad that I didn't put an annoying gif here?
Still doesn't work for me at all. (Win7 x64)
The box "reads" the 200x50 area, but returns garbage. Not a single character is correct, and the font it returns them to me in looks like chinese.
The box "reads" the 200x50 area, but returns garbage. Not a single character is correct, and the font it returns them to me in looks like chinese.
#7
-
Posted 20 July 2011 - 12:22 PM
Grendahl: I sent you a PM, but I'll post my request for more info here as well... Can you send me a screenshot of the preview script as it is running? Also, have you tried running it over larger text to see if it recognizes that? What AHK version are you running? Is it AHK_L, AHK_basic? Is it 32 bit or 64 bit? Unicode or ANSI?
Thanks for your help.
Thanks for your help.
#8
-
Posted 21 July 2011 - 01:08 PM
Aren't you glad that I didn't put an annoying gif here?
Could you possibly make it clearer as to where should the files for the OCR function be put (I mean the files from the zipped OCR folder that has been made available for download). I presently put them in the same directory where the Autohotkey exe is located, but all I see when I fire the autohotkey exe is a pink rectangle with no text captured. Thanks.
#9
-
Posted 21 August 2011 - 06:48 PM
bmoore45: Awesome! Glad you're liking it.
Also, I'm currently working with StarBlue to track down the issues he is having with the lib.
Also, I'm currently working with StarBlue to track down the issues he is having with the lib.
#11
-
Posted 29 August 2011 - 04:12 AM
Aren't you glad that I didn't put an annoying gif here?
Hello Camerb,
I have one problem.....i want to read a text from web application but wingettext command is not working properly.
IfWinNotActive, AWD/Contact – Windows Internet Explorer, Favorites Command Ba,
WinActivate, AWD/Contact
WinWait, AWD/Contact
WinGetText, text ; The window found above will be used.
MsgBox, The text is:`n%text%
in this script varable text returns some other values which doesn't exist on that window like...navigationbar...etc. so could you please help me to sort out this issue........
I have one problem.....i want to read a text from web application but wingettext command is not working properly.
IfWinNotActive, AWD/Contact – Windows Internet Explorer, Favorites Command Ba,
WinActivate, AWD/Contact
WinWait, AWD/Contact
WinGetText, text ; The window found above will be used.
MsgBox, The text is:`n%text%
in this script varable text returns some other values which doesn't exist on that window like...navigationbar...etc. so could you please help me to sort out this issue........
#12
-
Posted 29 August 2011 - 09:49 AM
yash.dhiman: Please post a new thread in the "Ask for Help" section with your question. This thread is not related to the question you have asked...
Ask for Help section: <!-- m -->http://www.autohotke...ewforum.php?f=1<!-- m -->
Ask for Help section: <!-- m -->http://www.autohotke...ewforum.php?f=1<!-- m -->
#13
-
Posted 29 August 2011 - 05:28 PM
Aren't you glad that I didn't put an annoying gif here?
hey camerb, is there a way to limit the OCR recognition to numbers only and not letters?? thanks!
#14
-
Posted 02 September 2011 - 07:29 AM
Not at the moment, but I am thinking about investigating that someday. It isn't high on my priority list, though.
#15
-
Posted 02 September 2011 - 01:45 PM
Aren't you glad that I didn't put an annoying gif here?