WitchDoctor
WitchDoctor

Reputation: 21

Pyautogui finding multiple screenshot matches regardless of color gradient

I am using pyautogui to click a matching image, but it is also picking up similar images that have a different brightness/contrast/gradient. For example, in this example image:

enter image description here

pyautogui will pick up the P with a white background, and the Ps with the two gray backgrounds (but not the red background P), when I am providing it a screenshot of the P with a white background.

How do I get it to locate ONLY the P that matches my image?

I have tried grayscale set to False but it seems to be false by default.

I am expecting only one image to be returned when I use locateallonscreen, and not three images.

Upvotes: 2

Views: 1314

Answers (1)

Ethan J.
Ethan J.

Reputation: 46

I have done similar things to this in the past. What you want to do is open Paint, Photoshop, or other similar application and remove all color background around the 'P' Try to be as precise as possible! You should be left with nothing but a black 'P'. Give this to pyautogui to look. You will find, as I have, this will work like a wonder, as long as the P remains black. It is fairly easy to do, and will detect on virtually all non-black colors, depending on your tolerance. You can set tolerances and such in your file. Here is a resource for pyautogui I have always found helpful:

https://pyautogui.readthedocs.io/en/latest/screenshot.html

This site is great for anything pyautogui!

Best of luck in your programming!

Ethan J.

Upvotes: 1

Related Questions