使用 pyautogui 进行图像识别:如何一次搜索多个区域?

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

我正在使用 python 搜索图像,我可以在一个区域执行此操作,但我如何针对多个区域调整此代码?

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

欢迎堆砌! PIL 有一个区域标志,字面上称为区域。如果您指定区域在左上角 x 和 y 以及右下角 x 和 y 的位置,您可以使用 for region_name, region in regions.items(): 循环遍历区域,然后在找到图像时执行 something在任何地区。

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 )