sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #27613
[Bug 1355017] Re: [request] want as feature: get the nearest point/region/image to a given point/region/image
This is a more general solution:
import math
# used by sorted, to calculate the distance to refLocation
# the sort function uses this value for sorting the list elements
def by_nearest(match):
x = math.fabs(match.getCenter().x - refLocation.x)
y = math.fabs(match.getCenter().y - refLocation.y)
distance = int(math.sqrt(x * x + y * y))
return distance
img = "some-image.png" # the image to look for
refLocation = Env.getMouseLocation() # the reference point
# use findAll(), to find all matches on screen
# and create the sorted list
sortedMatches = sorted(findAll(img), key=by_nearest)
# list contains the elements sorted by distance in ascending order
# hence the first element is the one we are looking for
sortedMatches[0].highlight(2)
--
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1355017
Title:
[request] want as feature: get the nearest point/region/image to a
given point/region/image
Status in Sikuli:
New
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 ?
To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1355017/+subscriptions
References