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

时间:2017-07-28 22:35:26

标签: python 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输入要加载的Web地址后发生此循环。

2 个答案:

答案 0 :(得分:3)

找到我的问题的答案。选择一个区域可以加快搜索功能。这样,程序就不会在整个屏幕上搜索,只搜索特定区域。

例如:

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

其中region = left,top,width,height

答案 1 :(得分:0)

简单方法

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