How to restrict a search to a specific region

Asked by Jeff Sant

I am selecting a region on screen and want Sikuli to only find and click the images available in this region, but this is not working

eg.

Region(112,777,71,137)
if exists(some_image,180):
 click(getLastMatch())

i have also tried with the click(image) but that also doesn't work.

As the sceen has so many exactly similar images, Sikuli is behaving randomly.

Any suggestions?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Pls. do me a favor and have a look at the docs to understand some basic features.

many options:
--- setROI()
--- reg.exists(), reg.click(), reg.getLastMatch()
--- with reg:

all in the docs.

Your case using with:

with Region(112,777,71,137):
    if exists(some_image,180):
        click(getLastMatch())

Revision history for this message
Jeff Sant (sant-jeff) said :
#2

I saw the documents but was unable to understand thats why requested you to help me out.

The solution you gave is not working for me, its still clicking out of the region, any other solution?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

# solution: qualify every search action with the respective region
reg =Region(112,777,71,137):
if reg.exists(some_image,180):
    click(reg.getLastMatch())

Revision history for this message
Best RaiMan (raimund-hocke) said :
#4

sorry, again:

# solution: qualify every search action with the respective region
reg = Region(112,777,71,137)
if reg.exists(some_image,180):
    click(reg.getLastMatch())

Revision history for this message
Jeff Sant (sant-jeff) said :
#5

Thanks RaiMan, that solved my question.