many matched components, how to decide which to click?

Asked by Yadong Yu

For example, there are 5 matched compontes which are the same actually in the full screen and their similarities are all bigger than 0.99.
I konw that sikuli will click the compont which has the biggest similarity by matchTemplate method.
But i need to click the compont closest to the center of the screen. It may has similarity like 0.9901, less than another compont which has 0.9909 in similarity.

Is there any method in sikuli can do that?
Should this requirement need to change the source code? If so, please give me some advice, and i will try to do that myself.
Thank in advance!

Question information

English Edit question
SikuliX Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :

Since there has not been any answer from other persons, I suggest using

Use findall to identify all matches
loop through the list of matches:
 calculate the distance to the center for the current match, if it is better than the previous value, save the match

It should be possible to use sorting as shown in
probably something like
Settings.MinSimilarity = 0.97 # or whatever value you need
icons = findAll("png_icon.png")
sorted_icons = sorted(icons, reverse=True, key=lambda m: (SCREEN.getH/2 - m.getY)*(SCREEN.getH/2 - m.getY) + (SCREEN.getW/2 - m.getX)*(SCREEN.getW/2 - m.getX))
and finally sorted_icons[0] should be the match that is closest to the screen center.

(no warranty given that this works as desired)

Can you help with this problem?

Provide an answer of your own, or ask Yadong Yu for more information if necessary.

To post a message you must log in.