[request] want as feature: get the nearest point/region/image to a given point/region/image
Bug #1355017 reported by
RaiMan
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SikuliX |
In Progress
|
Medium
|
RaiMan |
Bug Description
I ran into a major problem while making a script. At present sikuli randomly selects the pictures , i wanted sikuli to select the recognized picture closest to the mouse since there are more than 5 matches , at least on the screen.but since i am new to this i am hopelessly lost ! , how do i get sikuli to select the the picture closest to the mouse location when there are multiple matches. thanks :)
is it possible to achieve this by setting a region at the mouse location every time ?
Changed in sikuli: | |
status: | New → In Progress |
importance: | Undecided → Medium |
assignee: | nobody → RaiMan (raimund-hocke) |
milestone: | none → 1.2.0 |
Changed in sikuli: | |
milestone: | 2.0.0 → 2.1.0 |
To post a comment you must log in.
This is a more general solution:
import math
# used by sorted, to calculate the distance to refLocation match.getCenter ().x - refLocation.x) match.getCenter ().y - refLocation.y)
# the sort function uses this value for sorting the list elements
def by_nearest(match):
x = math.fabs(
y = math.fabs(
distance = int(math.sqrt(x * x + y * y))
return distance
img = "some-image.png" # the image to look for
refLocation = Env.getMouseLoc ation() # the reference point
# use findAll(), to find all matches on screen findAll( img), key=by_nearest)
# and create the sorted list
sortedMatches = sorted(
# list contains the elements sorted by distance in ascending order 0].highlight( 2)
# hence the first element is the one we are looking for
sortedMatches[