pythonimagepython-3.ximage-processingpyautogui

How can I locate something on my screen quickly in Python?


I've tried using the pyautogui module and i's function that locates an image on the screen

pyautogui.locateOnScreen()

but it's processing time is about 5-10 seconds. Is there any other way for me to locate an image on the screen more quickly? Basically, I want a faster version of locateOnScreen().


Solution

  • The official documentation says that it should take 1-2 seconds on a 1920x1080 screen. Your time seems to be a bit slow. I would try optimizing the code by doing the following:

    This is all described in the documentation linked above.

    If this is still not fast enough, you can check the sources of pyautogui, see that 'locate on screen' uses a specific algorithm (Knuth-Morris-Pratt search algorithm) implemented in Python. Implementing this part in C may result in a quite pronounced speedup.