Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

OCR.ahk - Library for recognizing text in images


  • Please log in to reply
88 replies to this topic
camerb
  • Moderators
  • 573 posts
  • Last active: Sep 14 2015 03:32 PM
  • Joined: 19 Mar 2009
dexter323: What are the exact contents of the variable called "Power"? You've probably got other characters in there, like a space or something. Use a StringReplace command or something similar to get rid of the non-numeric characters.
Aren't you glad that I didn't put an annoying gif here?

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
I have a problem recognizing numbers with OCR.ahk

FAIL1.jpg
DD:_:_:D7

FAIL2.jpg
nothing

is there a way to help recognition?

is structurise textract better than gocr?
"Simplifying complexity is not simple"

camerb
  • Moderators
  • 573 posts
  • Last active: Sep 14 2015 03:32 PM
  • Joined: 19 Mar 2009
stevep: are you running it in numeric mode?
Aren't you glad that I didn't put an annoying gif here?

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
numeric is useless, it just changes the undetermined numbers to spaces, and I could convert D to 0 after OCR function
here's a bitmap, please try if you can

is there a way to use Tesseract OCR suggested by PhilHo in AHK?
<!-- m -->http://googlecode.bl... ... t-ocr.html<!-- m -->
<!-- m -->http://sourceforge.n...s/tesseract-ocr<!-- m -->
made by HP, taken over by Google which made it open source.
"Simplifying complexity is not simple"

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
after saving the file as Monochrome in Paint and converting it to pcx, gocr.exe recognized all the numbers
A dos utility that will convert a bmp image to 2-bit Monochrome and save it as pcx/ is necessary for gocr.exe
also I have found there are many other ocr tools:
<!-- m -->http://en.wikipedia.... ... n_software<!-- m -->
but many are not command-line driven and not for Windows :(

This one recognized all the numbers from a jpeg without any conversions:
<!-- m -->http://www.verydoc.c...-ocr/index.html<!-- m -->
but it's 200$ !
"Simplifying complexity is not simple"

camerb
  • Moderators
  • 573 posts
  • Last active: Sep 14 2015 03:32 PM
  • Joined: 19 Mar 2009
SteveP: Good to hear that your conversion worked just fine for the expensive OCR software.

OCR does not guarantee a correct reading of what those numbers are, it merely makes a guess at what they could be. With text that small, I wouldn't get my hopes up for it recognizing many of the characters in there, because it is so pixelated. If the text is larger, it will be better, but again, nothing is guaranteed. Also, in the "FAIL1" image you gave me, a significant portion of the numbers is chopped off. That makes it nearly impossible for the computer to determine the actual text of the numbers.

Also, feel free to experiment with using TesseractOCR on your own (and start your own thread, too). I've messed around with Tesseract a little, but I am not planning on implementing any interaction with that software. Feel free to make your own lib for it.
Aren't you glad that I didn't put an annoying gif here?

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006

That makes it nearly impossible for the computer to determine the actual text of the numbers.

goocr is fine, it determines all the numbers after the image is saved as Monochrome and converted to pcx/pnb
currently I am searching for a dos-utility command-line tool to accomplish this task.
Have you any on your mind?
"Simplifying complexity is not simple"

camerb
  • Moderators
  • 573 posts
  • Last active: Sep 14 2015 03:32 PM
  • Joined: 19 Mar 2009
You'll notice that the lib already converts the files to pnm. However, it does not have a monochrome conversion mode. It does have a greyscale conversion mode, but that is not the same thing, since it allows for many shades of grey. I have not looked into monochrome conversions via the command-line, if you find something promising, let me know. It might be nice to add that in.
Aren't you glad that I didn't put an annoying gif here?

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
GDI+ doesn't have ColorDepth functions, ImageMagick does the job
<!-- m -->http://www.imagemagi... ... hp#windows<!-- m -->

currently reading the help files
<!-- m -->http://www.imagemagi... ... essing.php<!-- m -->
here it is:
-monochrome
transform the image to black and white.
"Simplifying complexity is not simple"

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
Still have a problem with conversion to Monochrome, ImageMagick have a lot of color reduction and dithering options, I have tried most, but with no luck. I had to create a topic in ImageMagick forum to solve the problem:
http://www.imagemagi...php?f=1&t=21264

It looks like Gocr project is abandoned, last version is dated 2010-09
"Simplifying complexity is not simple"

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
camerb, you should read the gocr help file, the image is already converted to grayscale by gocr itself:
<!-- m -->http://aist1.pisem.net/gocr.html<!-- m -->

no need for the grayscale option in
convertCmd=djpeg.exe -pnm -grayscale %filenameJpg% %filenamePnm%

I don't get it, it recognizes text on following images, even handwritten text, is it a problem with the Windows version?
Examples are downloaded from the Linux version
<!-- m -->http://www-e.uni-mag... ... .49.tar.gz<!-- m -->
"Simplifying complexity is not simple"

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
examples
"Simplifying complexity is not simple"

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
so, here are the changes that saved my day:
Changes in OCR.ahk 

93 filenamePnm := "in.pnm"
>  filenamePnm := "in.pgm"

95 djpegPath=djpeg.exe
>  djpegPath=c:\Program Files\ImageMagick-6.7.7-Q16\convert.exe

117 convertCmd=djpeg.exe -pgm -grayscale %filenameJpg% %filenamePnm%
>   convertCmd=%djpegPath% %filenameJpg% -colorspace gray -auto-level -threshold 64`% -background black -extent 95x18 %filenamePnm%
it's not universal, but the threshold value can be added as additional option to GetOCR()
and definitely the convert.exe should be used, as jpeg even at 100% quality IS compressed, and with ImageMagick convert GetOCR() could prepare an uncompressed pgm for gocr.exe
and use pgm (Portable Graymap) instead of pnm
this file is also uncompressed
"Simplifying complexity is not simple"

MartinCarlsson
  • Members
  • 4 posts
  • Last active: Apr 21 2012 04:46 PM
  • Joined: 21 Apr 2012
Where am I suppose to see the result?

When I run OCR-preview.ahk I just see a pink rectangle, nothing more.

camerb
  • Moderators
  • 573 posts
  • Last active: Sep 14 2015 03:32 PM
  • Joined: 19 Mar 2009
MartinCarlsson: What version of AHK are you running? Also, what OS are you using? Also, did you unzip the zip file before running the AHK? Also, can you tell where the AHK stopped by opening up the "Lines most recently executed" debug panel in AHK?

You should see a pink rectangle, plus a ToolTip that shows what the text said.
Aren't you glad that I didn't put an annoying gif here?