Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
840 views
in Technique[技术] by (71.8m points)

python - Why PyAutoGui LocateOnScreen() only Returns None

Here's the code that I'm trying to run:

import pyautogui
r=pyautogui.locateOnScreen('C:UsersDavidDesktopindex.png',grayscale=False)
print r
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It has to be a pixel-perfect match in order to be found. To allow for any sort of deviance you can invoke a confidence parameter.

For example:

loc = pyautogui.locateOnScreen(image, grayscale=True, confidence=.5)

However, in order to use the confidence parameter you have to have opencv_python installed. This is easy to install with pip:

./python -m pip install opencv_python

After that is in place, you should be able to account for minor differences.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...