How to define a non-fixed region for OCR? (Sikuli IDE)

Asked by Milteven on 2016-12-28

Hello, I'm using Sikuli IDE to extract text from a region, its working BUT the text that I want to extract appears on different regions of the screen (Different tabs equals to a different position).

There is a way to make sikuli uses a "non-fixed region" or recognize the position of the tab to extract the text ?

Thank you for your attention, have a good day!

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Roman Podolyan
Solved:
2016-12-31
Last query:
2016-12-31
Last reply:
2016-12-31
Tim Bernd (tim32) said : #1

Hi, can you add a screenshot to clarify this further?

Milteven (milteven12) said : #2

Yes, the image can be viewed here: http://imgur.com/3qwM0Pl

The region is defined by the red rectangle, as you can see, if I open another tab, the "90%" will be in another position but the region is fixed, so the OCR will return the wrong text.

@Milteven.
I see two areas which can be used as "guides".
The first is small phrase "Ativo e lucro". It looks like its relative position to the percentage you need is stable.
The second is bigger text starting "O lucro que".

So what you want to do:

1) Find something by image which is on stable position against region you are interested in, read it to match object.
2) From coordinates of that match object construct a new region.
3) Do some testing to mare sure that the area you are interested is really that region.
4) Use it.

Here is a sample of code doing that using "Ativo e lucro":
______
#here goes "Ativo e lucro" image with similarity increased to 85
match = find("1483189609482.png")
# using obtained match we do construct new region, adding desired width and height and offsets.
newregion = Region(match.getX()+ 45, match.getY()+ 65 , 40, 20)
# this is a test code, it makes constructed region "blink" 4 times
for i in range(4):
    newregion.highlight(1)
______

Milteven (milteven12) said : #4

Thank you @Roman Podolyan, this was exactly what I'm looking for; the code worked perfectly!!

Milteven (milteven12) said : #5

Thanks Roman Podolyan, that solved my question.