How do I quickly find something on my screen in Python?

I have tried using the pyautogui module and the i function that finds the image on the screen

pyautogui.locateOnScreen()

      

but the processing time is 5-10 seconds. Is there another way for me to find the image on the screen faster? Basically, I need a faster version of locateOnScreen ().

+3


source to share


2 answers


The official documentation says it takes 1-2 seconds on a 1920x1080 screen, so your time seems a little slow. I would try to optimize:

  • Use grayscale if color information is important ( grayscale=True

    should give a 30% boost)
  • Use a smaller image for your search (e.g. only a part if this already uniquely identifies the position you need to get)
  • Don't load the image you need to find from the file every time, but keep it in memory.
  • Pass the scope argument if you already know something about possible locations (for example from previous runs).


All of this is described in the documentation above.

Whether this is not fast enough yet, you can check the sources of the pyautogui sources , see the screen search uses a specific algorithm (Knuth-Morris-Pratt) implemented in Python. Thus, implementing this part in C can lead to significant speedup.

+2


source


If you are looking for image recognition, you can use Sikuli . Check out the Hello World tutorial .



0


source







All Articles