Region arguments seem to be mixed up?

Asked by GZ

Hi RaiMan,

I've noticed that while using the Region() function it wouldn't find the things in the area I defined, so I used selectRegion() to check if my coordinates for the Region() are correct and I've found something odd:

This is how I defined my region, which should be a rectangle (ish) shape in the bottom-center part of the screen:
s0Width = Screen(0).getBounds().width
s0Height = Screen(0).getBounds().height
Region((int(s0Width*0.5-300)),0,(int(s0Width*0.5+300)),(int(s0Height*0.5))).exists(Pattern("1430816648032.png").similar(0.88)):

When I printed the xywh coordinates from this, this is what I got: 660, 0, 1260, 540.
AS I mentioned, the problem was that the command only found my pattern in the top-center of the monitor instead of the bottom-center.

So I've done the selectRegion() command, selecting roughly the same area, which gave me the following coordinate:
680,567 602x512 or I could say: 680,567,602,512 ?

So question is, was I wrong thinking that the Region() should be x and y coordinate of the left-bottom starting point of the rectangle pointing to w and h, which are the coordinates of the right-top point of the rectangle?

Even if I have to change my w and h to only count from the x and y, having to have y in the center-height instead of 0 seems very odd.

But it might be that I'm completely wrong here.. :)

Any help is much appreciated!
George

Question information

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

A region is defined by

reg = Region(x, y, w, h)

where (x,y) is the top left corner and w is the width and h is the height
(hence printing a Region you get (x,y wxh) )

so the calculation could be:

s0 = Screen() # which is screen 0

partW = int(s0.w/2)
partH = int(s0.h/2)

reg = Region(partW-300, partH, 600, partH)

BTW: with version 1.1.0 there are some convenience shortcuts to create subregions.
http://sikulix-2014.readthedocs.org/en/latest/region.html#get-evenly-sized-parts-of-a-region-as-rows-columns-and-cells-based-on-a-raster

Revision history for this message
Manfred Hampl (m-hampl) said :
#2

see http://sikulix-2014.readthedocs.org/en/latest/region.html

A Region is a rectangular area on a Screen and is defined by
1.its upper left corner (x, y) being the pixel with this offset relative to the upper left corner of the screen (usually (0, 0) ) and
2.its dimension (w, h) as its width and height in pixels.

So if you have a screen with 1920*1080 and want to select a region in the bottom center of 600*500 pixel size,

the x,y,w,h values should most probably be 660, 580, 600, 500

total width: 1920, center is 1920/2=960, and now half the rectangle size to the left gives 960-300=660
total height: 1080, the size of the rectangle up gives 1080-500=580
region width: 600
region height: 500

Revision history for this message
GZ (g-zr) said :
#3

Awesome!! Thanks guys for the prompt reply, you are the best! :)