Reputation: 61
When I try to recognize an image with pyautogui
it just says: None
import pyautogui
s = pyautogui.locateOnScreen('Dark.png')
print s
When I ran this code the picture was on my screen but it still failed.
Upvotes: 3
Views: 16705
Reputation: 59
It's pixel perfect.
It can't find the image if it is not 100% match.
For example, I cropped an area with an Opera extension. Then I ran my script with Firefox, and pyautogui did not recognize it.
Upvotes: 5
Reputation: 913
Pyautogui.locateOnScreen has a parameter that specifies the 'confidence' you have in the image you enter.
This way, pyautogui will deal with slight pixel deviations.
For example:
import pyautogui
s = pyautogui.locateOnScreen('Dark.png', confidence=0.9)
print(s)
For more information, see https://buildmedia.readthedocs.org/media/pdf/pyautogui/latest/pyautogui.pdf.
Upvotes: 6
Reputation: 8411
On my system, I get this if the picture is on a second monitor. If I move it to the main screen, the image is located successfully.
It looks like multiple-monitor functionality is not yet implemented: From http://pyautogui.readthedocs.org/en/latest/roadmap.html
Future features planned (specific versions not planned yet):
- Find a list of all windows and their captions.
- Click coordinates relative to a window, instead of the entire screen.
- Make it easier to work on systems with multiple monitors.
- ...
Upvotes: 3