Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Image eecongition with pyautogui: How do I search for multiple areas at once?

I’m using python to search for images and I can do that with one area but how can I adapt this code for multiple areas?

found_image = pyautogui.locateOnScreen(image)
if found_image !=None:
    pyautogui.click(found_image)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

welcome to stack! PIL has a flag for regions literally called region. If you specify where you regions are top left x and y and bottom right x and y you can them loop through the regions with for region_name, region in regions.items(): and then do something if your image is found in any of the regions.

regions = {
"Top left": (top, left, bottom, right),
"Bottom left": (top, left, bottom, right),
"Top right": (top, left, bottom, right),
"Bottom right": (top, left, bottom, right)
}

for region_name, region in regions.items():
    found_image = py.locateOnScreen(image, region=region)
    if found_image != None:
        print(f"Clicked found_image in {region_name} region.")
        py.click(found_image )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading