Python 2.7 Pyautogui.locateOnScreen 不工作
Python 2.7 Pyautogui.locateOnScreen not working
由于某些未知原因,Pyautogui 的 locateOnScreen()
函数(以及所有其他 Pyautogui 的定位函数)无法正常工作并且 returns None
.
我的代码:
>>> pyautogui.screenshot('test.png',region=(100,20, 30, 20))
<PIL.Image.Image image mode=RGB size=30x20 at 0x39E35C0>
>>> print pyautogui.locateOnScreen('test.png')
None
我的研究
我知道当它 returns None
时,这意味着 pyautogui
无法定位 屏幕上的图像。我也知道它必须在屏幕上可见。上面的代码是在 没有移动单个 window.
时执行的
我也知道在 Whosebug 上有很多 similar/identical 个问题,比如 。但是这个问题的解决方案不适用于我的情况,因为我实际上是直接使用 pyautogui 的屏幕截图和裁剪功能,甚至没有使用第 3 方软件进行裁剪,但 pyautogui 无法定位它。
附加信息
Python: 2.7.15 (64-bit)
OS: Windows 10 Home 64-bit
locateOnScreen
、locateCenterOnScreen
和(可能)所有其他 Pyautogui 的 locate 函数都有一个可选参数 confidence
.
顾名思义,设置 Pyautogui 可以容忍多少细微偏差。降低置信度值 解决了这个问题 但增加了 误报 .
的机会
旁注:confidence
未在 Pyautogui's documentation 中提及。如果他们能把它加进去,那就太好了。
由于某些未知原因,Pyautogui 的 locateOnScreen()
函数(以及所有其他 Pyautogui 的定位函数)无法正常工作并且 returns None
.
我的代码:
>>> pyautogui.screenshot('test.png',region=(100,20, 30, 20))
<PIL.Image.Image image mode=RGB size=30x20 at 0x39E35C0>
>>> print pyautogui.locateOnScreen('test.png')
None
我的研究
我知道当它 returns None
时,这意味着 pyautogui
无法定位 屏幕上的图像。我也知道它必须在屏幕上可见。上面的代码是在 没有移动单个 window.
我也知道在 Whosebug 上有很多 similar/identical 个问题,比如
附加信息
Python: 2.7.15 (64-bit)
OS: Windows 10 Home 64-bit
locateOnScreen
、locateCenterOnScreen
和(可能)所有其他 Pyautogui 的 locate 函数都有一个可选参数 confidence
.
顾名思义,设置 Pyautogui 可以容忍多少细微偏差。降低置信度值 解决了这个问题 但增加了 误报 .
的机会旁注:confidence
未在 Pyautogui's documentation 中提及。如果他们能把它加进去,那就太好了。