PyAutoGUI and Image Detection on different Monitor Resolutions

Hello,

I am writing an automation script to detect an image on the screen and do some automatic mouse movements and such. This program works smoothly on my own computer (because all my saved screengrab images are from my own monitor). However, when I test the program out on other computers, they will only work if I go through and manually redo the screengrabs for each image (my main monitor is 2560x1440, and laptop I test on is 1920x1080). Setting the confidence level of locateImage is not that consistent for me as well as resizing the screenshots do not work since it reduces clarity.

I was wondering if anyone has a solution to my woes?

Posted Jul 19, 2020, 2:37 AM UTC

11
Fenrir333•

Maybe you could try Pillows resize() func.

main_size = (2560, 1440)           #Size of your Main monitor
current_size = pyautogui.size()    # Get the current size (1920, 1980)

# Get the proportion of your main_size to the current_size
prop = (current_size[0] / main_size[0], current_size[1] / main_size[1])
      
# For Example your img is 100 x 100
img = Image.open('test.png')
# Resize the image to (width=100px * 0.75, height=100px*0.75)
# (Width = 75px, Height = 75px)
resized_img = img.resize(img.size[0] * prop[0], img.size[1] * prop[1])
# Saves the resized Image
resized_img.save('resized_test.png')

so you should get the resized img in prop to the original size of the mainscreen

and sorry english is not my native language.

1