2

我正在寻找一种简单的 Python (PyAutoGUI) 方法来定位屏幕上某种类型的所有图像,但这里有一个问题,每个图像都有不同的渐变/色调,我不想截屏每个图像的位置,以在屏幕上定位它们。

这是包含我要获取其坐标的图像的屏幕区域:

如您所见,每个正方形都有独特的颜色(对比度)。

所以我想得到每个正方形的坐标,使 PyAutoGUI 只扫描一个图像。有什么办法可以让它忽略图像对比度的差异?比如把它做成黑白模式什么的。

代码如何工作:

import pyautogui
coordinates = pyautogui.locateAllOnScreen("image.png") # Returns list of coordinates of all images matching image.png
4

2 回答 2

7

我知道这已经 2 岁了,但对于任何像我一样发现它的未来人类,请尝试信心论点。

import pyautogui
button7location = pyautogui.locateOnScreen('calc7key.png', confidence=0.9)
button7location
Box(left=1416, top=562, width=50, height=41)

来源:https ://pyautogui.readthedocs.io/en/latest/screenshot.html#the-locate-functions

于 2019-10-17T20:48:55.760 回答
3

我会尝试以下方法:

pyautogui.locateOnScreen("image.png", grayscale=True)

这将忽略颜色值并简单地比较值的对比度。这有一个额外的好处,即比较快 30%,但可能导致误报。

于 2016-12-27T07:41:09.797 回答