Can I make OCR to use threshold? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
liij
Posts: 51
Joined: 23 Apr 2016, 13:25

Can I make OCR to use threshold?

20 Sep 2017, 02:24

On the site http://capture2text.sourceforge.net/#download there is command like this

Code: Select all

  --tess-config-file <file>          (Advanced) Path to Tesseract configuration file.
My script works, but usually OCR does not recognize number correctly. I know I can fix this by changing threshold, because numbers on the screen are almost white compare to the background.
I am searching for ''tesseract'' command to change threshold

Code: Select all

q::
TempFile := A_Temp . "\temp_capture.txt"
FileDelete, %TempFile%
RunWait, C:\Users\xxxx\Desktop\Capture2Text_CLI.exe -s "1805 22 1897 33" -d --whitelist 1234056789/ -o %TempFile%,,Hide
sleep 1
FileRead, CaptureText, %TempFile%
FileDelete, %TempFile%
var := StrSplit(CaptureText,"/")
MsgBox % var[1] "`n" var[2]
MsgBox %CaptureText%
return
This outputs 152/188 according to script

debug_capture.png
Image

debug_enhanced.png
Image

I was trying imagemagick with many commands and thresholds, but it does not work correctly on windows7 in my opinion

Code: Select all

"C:\Program Files\ImageMagick-7.0.7-Q16\magick.exe"     convert -density 150 -threshold 60% rose.jpg out.jpg
There is image barely visible below
Image
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Can I make OCR to use threshold?

20 Sep 2017, 11:34

Try this ImageMagick command on your captured image:

Code: Select all

magick.exe convert debug_capture.png -geometry 500% -threshold 90% white_on_black.png
That creates a white-on-black image. The OCR packages that I tried did better with a black-on-white image, which you can create with this ImageMagick command:

Code: Select all

magick.exe convert white_on_black.png -colorspace HSI -channel B -level 100,0% +channel -colorspace sRGB black_on_white.png
That created this image:

Image

Capture2Text 3.9 OCRs that perfectly (does not with the white-on-black.png file):

Image

Regards, Joe
liij
Posts: 51
Joined: 23 Apr 2016, 13:25

Re: Can I make OCR to use threshold?

20 Sep 2017, 13:33

@JoeWinograd Great job with commands, but ImageMagick does not work on my pc correctly. This is how I am running this ( i know I can run wait .bat with ahk).
I made geometrythreshold1.bat from notepad with code magick.exe convert debug_capture.png -geometry 500% -threshold 90% white_on_black.png. This is what I got:
Image
After that I made colorspacechannel.bat with code magick.exe convert white_on_black.png -colorspace HSI -channel B -level 100,0% +channel -colorspace sRGB black_on_white.png
Image
Definitely I am doing something wrong. My system is windows 7.
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Can I make OCR to use threshold?  Topic is solved

20 Sep 2017, 14:32

I executed the commands in a Prompt window. Since you put it in a batch file, you need to escape the percent signs, which you do with a double percent. So in a batch file:

Code: Select all

magick.exe convert debug_capture.png -geometry 500%% -threshold 90%% white_on_black.png

magick.exe convert white_on_black.png -colorspace HSI -channel B -level 100,0%% +channel -colorspace sRGB black_on_white.png
Btw, I'm on W7 Pro 64-bit running ImageMagick 7.0.7-3-portable-Q16-x86. Regards, Joe

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Descolada, Oblomov228 and 166 guests