使用pyautogui进行图像重新识别:如何同时搜索多个区域



我正在使用python搜索图像,我可以用一个区域来搜索,但如何将此代码适应多个区域?

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

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

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 )

最新更新