我正在 Python (PyAutoGUI) 中寻找一种简单的方法来定位屏幕上某种类型的所有图像,但这里有一个问题,每个图像都有不同的渐变/色调,我不想截取屏幕截图每个图像以在屏幕上定位它们。
这是包含我试图获取坐标的图像的屏幕区域:

如您所见,每个方块都有独特的颜色(对比度)。
所以我想获得每个方块的坐标,使 PyAutoGUI 只扫描一张图像。有什么办法可以让它忽略图像对比度的差异?比如制作黑白模式什么的。
代码如何工作:
import pyautogui
coordinates = pyautogui.locateAllOnScreen("image.png") # Returns list of coordinates of all images matching image.png
Run Code Online (Sandbox Code Playgroud)
小智 5
我知道这已经 2 岁了,但是对于任何像我一样发现这一点的未来人类,请尝试使用信心论证。
import pyautogui
button7location = pyautogui.locateOnScreen('calc7key.png', confidence=0.9)
button7location
Box(left=1416, top=562, width=50, height=41)
Run Code Online (Sandbox Code Playgroud)
来源:https : //pyautogui.readthedocs.io/en/latest/screenshot.html#the-locate-functions
| 归档时间: |
|
| 查看次数: |
6452 次 |
| 最近记录: |