How may I get a region of image on screen?

Asked by mrderanakt on 2018-08-12

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:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2018-08-15
Last query:
2018-08-15
Last reply:
2018-08-13
mrderanakt (mrderanakt) said : #1

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

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())

mrderanakt (mrderanakt) said : #3

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

mrderanakt (mrderanakt) said : #4

Thanks*
:D

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")

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.

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")

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)))

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")

mrderanakt (mrderanakt) said : #10

Thanks RaiMan, that solved my question.