OCR not recognizing simple text

Asked by Niklas Jørgensen

Hey all!

Im having some trouble recognizing some simple text using the inbuilt tesseract OCR in Sikulix. It had a bit of trouble recognizing everything but when I set the language to danish (which is the language i need to use) it helped alot but it keeps mixing SJ/SJ for 5351 or 5531 or something. I've been playing with the OCR.globalOptions for multiple hours without any change in the outcome, heeeelp! The text in the image is -

Text: https://ibb.co/ZhmZGxJ

Is there any way it can be calibrated in a way where it can actually read the SJ/SJ? - are the letters too small or thin maybe?

This is the code that I have in this test project.

Settings.OcrTextSearch = True
Settings.OcrTextRead = True
Settings.OcrLanguage = "dan"

my_options = OCR.Options().oem(OCR.OEM.TESSERACT_ONLY).configs("digits").language("dan")

print(OCR.globalOptions())

print(my_options)

my_region = Region(877,548,167,11)

print(OCR.readWord(my_region,my_options))

print(my_region.text())

Output:

53511 01-01-2009-31-12-2099
[5]153] €01—01—2009—31—12—2099)

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Niklas Jørgensen (shortytheman) said :
#1

Sikulix version: 2.0.5
Java: version 17

Revision history for this message
Niklas Jørgensen (shortytheman) said :
#2

Spamming my own topic, sorry guys :D

Using:

m = findtext(SomeString)
m.highlight(3)

wont work if the text is too small or too thin it seems. Only with some specific inputs -

I tried just adding some text in a notepad:

Hej med diiig
Hallo hvordan går det
My Veteran/161'
yoyo
evqw
777
01-01
wqe
[SJ/SJ] (01-01-2009-31-12-2099)

some lines usefull for my work and some just playing around, but the result from:

print(the_region.text()) also gave my the output:

Hej med diiig
Hallo hvordan går det
Ny: YVeteran/161”
yoyo
evgw
777
01—01
wge
[S1/SJ] (61—01—2009—31—12—2099)

(Ignore the long dashes, I have dealt with them with a simple .replace("—", "-"))

So there's clearly alot of outliers.. Can i somehow change the font or make the program zoom on the text or something to make it more consistent? - My last post for now, i promise! :)

Revision history for this message
Launchpad Janitor (janitor) said :
#3

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Niklas Jørgensen (shortytheman) said :
#4

Changed to "expired" so posting just to "bump"

Revision history for this message
abuzer stream (abuzerstream) said :
#5

If you are trying to read a text that you can select, after selecting it with doubleClick(), you can assign the datayo you copied with ctrl+c ->(type( Key.CTRL+'c')) to your variable with Env.getClipboard.

Env.getClipboard()
Get the content of the clipboard if it is text, otherwise an empty string.

NOTE: Be careful, when using Env.getClipboard() together with paste(), since paste internally uses the clipboard to transfer text to other applications, the clipboard will contain what you just pasted. Therefore, if you need the content of the clipboard, you should call Env.getClipboard() before using paste().

Tipp: When the clipboard content was copied from a web page that mixes images and text, you should be aware, that there may be whitespace characters around and inside your text, that you might not have expected. In this

text = Env.getClipboard()

Revision history for this message
Niklas Jørgensen (shortytheman) said :
#6

I did consider the clipBoard operation, but the problem is that the program that im working in (the .txt file was just for testing) i am not able to highlight any text :(

Revision history for this message
Manfred Hampl (m-hampl) said :
#7

Just for diagnostic purposes:
Is the "[SJ/SJ] (01-01-2009-31-12-2099)" text the output of a program running locally, or is that part of a web page?

If it is a web page, what is the format for displaying "[SJ/SJ] (01-01-2009-31-12-2099)" - is it an image or text?
Or, if you do a right click on the "[SJ/SJ] (01-01-2009-31-12-2099)" text, what do you get offered in the pop-up window (e.g save image as ...)?

Is there any possibility to increase the display size of that part of the screen or changing the configuration of the program used (e.g. like increasing display size of the web page to 150%)?

Revision history for this message
Niklas Jørgensen (shortytheman) said :
#8

Hey Manfred, thanks for the answer!

It is a part of a dropdown menu in a program - rightclicking will just choose that option. Since the program is being used by a big coorporation, i am not able to change the configuration of the program itself, because that would change it for everyone in the company. Zooming in doesnt seem to be an option the program offers, maybe the old "loop" windows function can help out here somehow? :D

I tried working with resize(x) for some time, but this was most optimal at "3" and as far as i know, this is the default value anyway.

Maybe i just have to somehow try to avoid using OCR for this task

Revision history for this message
Manfred Hampl (m-hampl) said :
#9

I did not mean reconfiguring the whole application for all users, but just the display part on your computer. In any case, from your answer it seems that this is not possible.

Do you really need to (correctly) read the contents of that line?
Eventually it is possible to select "the last entry in the menu" without the need to decipher the text?

Revision history for this message
Niklas Jørgensen (shortytheman) said :
#10

I guess i coule make a forloop that uses Key.PAGE_DOWN and waits for the img "end_of_dropdown" is found, that's what i did to break the loop.

but now i tried avoiding OCR and are working with an API that sends the data to the script and work with fixed regions with that!

lmk if there is some smart was with that "last entry in the menu" idea :) - and thanks for your time again.

Revision history for this message
Launchpad Janitor (janitor) said :
#11

This question was expired because it remained in the 'Open' state without activity for the last 15 days.