问题
I've been looking all over for a way to find a specific color in a image (screen capture), and return the the position of of the color (x,y). I've had some tries, but not managed to do a proper search. The result should be the first pixel found with that color.
I tought maybe PIL will be to any help. So I tried something like this, problem now is that it returns EVERY position, found with that color:
Fixed:
def FindColor(r,g,b):
image = ImageGrab.grab()
for x in range(1, 400):
for y in range(1,400):
px = image.getpixel((x, y))
if px[0] == r and px[1] == g and px[2] == b:
return(x,y)
And, I need to replace the loops range, with the pictures width/height.
回答1:
return
the result at the first match, instead of continuing the loop.
来源:https://stackoverflow.com/questions/8862387/search-image-for-color-return-x-y