Easy way to take a screenshot and region at the same time (2)

Asked by Mi Me

Hi,
this one was asked before (and answered) (https://answers.launchpad.net/sikuli/+question/670985)
but the answer didn't solve my problem:

In Sikulix IDE I can do:
1. take a screenshot without region information or
2. take a region but without a screenshot.

If I do one after another, they most likely aren't pixel perfect.

I would like to take a "screenshot+region" in 1 step, so I could use it later as:

if region1.exists(image1,0):
    click(region1.getLastMatch())
elif region2.exists(image2,0):
    click(region2.getLastMatch())

The reason I want to do this is to speed up the find operations.
In my application the images I want to click are always at the same exact locations, so I thought if the image matches the region perfectly, the find operation should be fastest.

Each image has its own location.
There can be images with the same location.
There can be images which I don't want to click (ignore).

Is there an easy way to do this, or maybe a different approach?

(Edit:)
My current (long) approach is:
1. take a region
2. helper script for saving a screenshot of that region to a file
3. Insert image into main script
4. copy region from helper script to main script

Question information

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

This is currently not a feature, but I like the idea and put on the list (low priority - so it will not help you).

A manual approach like yours can be done directly in the main script:

add a line
reg1 = <cursor>
and capture the region around the image (need not be exact, better a few pixel larger on each side)

the line will then be
reg1 = <region-thumbnail>

add a next line
img1 = <cursor>
and capture the image (be exact, so the image is inside the region captured before)

the line will then be
img1 = "img1.png" as thumbnail

now you can use both variables as you like.

if reg1.has(img1):
   # some code

One more thing:
For both aspects (performance and being sure image is in its place) the region can be 10 to 20 pixels larger on each side without any effect on both aspects.

Can you help with this problem?

Provide an answer of your own, or ask Mi Me for more information if necessary.

To post a message you must log in.