get coordinates of image?

Asked by Stuart Robinson

I would like to define a Region dynamically. I want to click on secondary image that is within a certain distance of a given image that has a variable location.

How can I determine the coordinates of an image?

It looks like maybe I can hover over the main image and then get the mouse coordinates, but surely there is a more direct method?

Question information

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

I'm not really sure, that I understand right:

In the moment, there are only 2 possibilities, to get the coordinates of an image on the screen (in this case your "main image"):

1. find(): if the image is found, the resulting match has the same attributes and features as a region, especially the (x,y)-position and the width/height.

2. with the help of the user by using selectRegion("Pls. select the window ...."), that returns the coordinates of the region that hopefully is the one you are looking for.

May be, looking through my example http://sikuli.org/documentation.shtml#/trac/wiki/EnlargeWindow-0.10 gives you some more hints.

Revision history for this message
Stuart Robinson (stuart-clifford) said :
#2

thanks raiman! the very last sikuli snippet in your posted example is exactly what I was looking for.

fyi i noticed there are a couple 0.10 examples listed under "Tutorials (0.9)."

Revision history for this message
Stuart Robinson (stuart-clifford) said :
#3

btw, getCenter() is how to get the coordinates of an image

http://sikuli.org/trac/wiki/reference-0.10#getCenter

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

@Stuart

This comment may be misleading for the one or other user:

getCenter() returns the center of a region. So since a match object is a region, you may use getCenter(), to know where the current centre point of your image is on the screen (means relative to (0,0) on the screen, not to the borders of the image).

So to be clear:
- image is a pattern (captured in most cases) contained in an imagefile. For such an "object" you have no standard Sikuli means to get information about its dimension.
- the image you are talking about, is a match object, that does not contain any image information, only where the image was found on the screen.

So in the consequence, if you want to know the center of an image, you first have to find() it on the screen, to have a match object, that understands getCenter().

During the developement of version 0.10, I made some feature suggests in this direction:
- get information about an imagefile
- the possibility, to track back, on what pattern object a match object is based. To realize this now, you have to build a dictionary youself, that pairs patterns an matches.

Still some possibilities ;-)