How may I get a region of image on screen?

Asked by mrderanakt

I need to get a region of certain image and work in this region.How can I do it?

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
mrderanakt (mrderanakt) said :
#1

And I don't understand how use "similar()" and "exact()"

Revision history for this message
masuo (masuo-ohara) said :
#2

[example for first question]
r = Region (100, 100, 500, 500)
r.find ( "image.png")

[for #1]
Use SikuliX IDE and click image in editer pane, pattern setting window open.
Then select matching preview tab and move slider to change minimum similarity.
Switch off [Show ThumbNails], pattern setting will be shown.

like this:
click(Pattern("image.png").similar(0.96))
click(Pattern("image.png").exact())

Revision history for this message
mrderanakt (mrderanakt) said :
#3

Thaks,but how to determine the position of the image on screen?

Revision history for this message
mrderanakt (mrderanakt) said :
#4

Thanks*
:D

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

Uuups, sorry:

The region the image has on the screen, when found (it is called the match):
match = r.find ( "image.png")

Revision history for this message
masuo (masuo-ohara) said :
#6

@mrdenarakt
An easy way to specify the region of the screen is provided by SikuliX IDE.

Click Region button on SikuliX IDE.
Screen get dark.
Select Region from top left to bottom right.
That is all.

Revision history for this message
masuo (masuo-ohara) said :
#7

And we can be visualized the region on the screen by using highlight().
r = Region (100, 100, 500, 500)
r.highlight(1)
r.find ( "image.png")

Revision history for this message
mrderanakt (mrderanakt) said :
#8

RaiMan,Thank,But I need the program to work in the last region found,which can vary depending on the position of the desired object on the screen.This will force my program to find the things I need in a smaller region faster than full screen)))

Revision history for this message
mrderanakt (mrderanakt) said :
#9

Oh man,I did it,just I don't understand how it works,but it works
r=Region(some region)
match = r.find (Pattern("image").similar(0.35))
r=match
r.click("image")

Revision history for this message
mrderanakt (mrderanakt) said :
#10

Thanks RaiMan, that solved my question.