【问题标题】:Python 2.7 Pyautogui.locateOnScreen not workingPython 2.7 Pyautogui.locateOnScreen 不工作
【发布时间】:2018-12-19 11:03:59
【问题描述】:

由于某些未知原因,Pyautogui 的 locateOnScreen() 函数(以及所有其他 Pyautogui 的定位函数)无法正常工作并返回 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

我的研究

我知道当它返回None 时,这意味着pyautogui 无法定位屏幕上的图像。我也知道它必须在屏幕上可见。上面的代码是在不移动单个窗口时执行的。

我也知道在 stackoverflow 中有非常相似/相同的问题,例如 this one。但是该问题的解决方案不适用于我的情况,因为我实际上是直接使用 pyautogui 的屏幕截图和裁剪功能,甚至没有使用 3rd 方软件进行裁剪,但 pyautogui 无法找到它。


其他信息

Python:2.7.15 (64-bit)

操作系统:Windows 10 Home 64-bit

【问题讨论】:

    标签: python python-2.7 python-imaging-library pyautogui


    【解决方案1】:

    locateOnScreenlocateCenterOnScreen 和(可能)所有其他 Pyautogui 的 locate 函数都有一个可选参数 confidence

    顾名思义,设置 Pyautogui 可以容忍轻微偏差的程度。降低置信度值解决了这个问题,但增加了误报的机会。

    旁注:confidence 未在 Pyautogui's documentation 中提及。如果他们能把它加进去,那就太好了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-10
      • 2012-04-01
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      • 2017-09-14
      • 2018-06-01
      • 2020-04-14
      相关资源
      最近更新 更多