Search code examples
pythonpyautogui

Why am I detecting image outside of a defined region?


I've used pyautogui.displayMousePosition() to determine that the top left corner of where I want to search is 750, 25 and the bottom right is 1200, 125

Why is this code finding a positive match at 1649, 99

    for image in image_list:
        name = image
        location = pyautogui.locateCenterOnScreen(image, region=(750, 25, 1200, 125), confidence=0.9, grayscale=True)
        print(name + " Found at: " + str(location))

It looks right based on the documention.


Solution

  • In the documentation the region is defined as a box, so the first 2 parameters are the x,y coordinates of your upper left corner and the next two parameters are the width and the height.

    Try with (750,25,1200-750,125-25)