使用 pyautogui 检查图像是否在屏幕上的最快方法

Fastest Way to Check if Image is Onscreen Using pyautogui

我有以下代码:

b_counter = False

while (b_counter == False):
    if (pyautogui.locateOnScreen('editcheck.png') is not None):
            pyautogui.click(pyautogui.center(pyautogui.locateOnScreen('home.png')))
            b_counter = True

循环在 运行 时滞后,有时在图像加载后长达 10 秒。我的机器本身非常快(i7 16gb ram 等)。有什么办法可以加快这个循环吗?

我正在加载网页,因此 "home" 按钮不会立即出现。此循环发生在 pyautogui 输入要加载的网址后。

找到了我的问题的答案。 Select 使搜索功能更快的区域。这样,程序就不会搜索整个屏幕,只会搜索特定区域。

例如:

    import pyauotgui
    pyautogui.locateOnScreen('test.png', region = (0,0,400,400))

其中区域 = 左、上、宽、高

简单的方法

if (pyautogui.locateOnScreen('test.PNG') is not None):
    pyautogui.hotkey('win', 'l')