简体   繁体   中英

Python image recognition with pyautogui

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.

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 .

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.

  1. Don't let your image get resized or compressed by screen capture software or extensions.
  2. Use the same window/screen (size, resolution) as where you saved your screenshot.

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.
  • ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM