PyAutoGUI - LocateAllOnScreen - 为什么信心不起作用?

PyAutoGUI - LocateAllOnScreen - Why is confidence not working?

我正在尝试为 diep 制作瞄准机器人。我正在尝试定位屏幕上的所有敌人,但有 1 个置信度 returns None 和 0.9999 置信度 returns 屏幕上的每个位置。

我正在使用 PyCharm,当我 运行 代码时,它 return 显示屏幕上的每个位置,即使没有任何红色。然后,当我将置信度设置为 1 时,它甚至没有 return 个红色位置。

我什至试过打开文件,看看它是否能找到颜色。没用,结果一样。

我的代码

# https://pyautogui.readthedocs.io/en/latest/screenshot.html
from pyautogui import locateAllOnScreen, moveTo

while True:
    """
    try:
        coords = list(locateAllOnScreen('enemycolordiep.png'))
    except 'ImageNotFoundException':
        coords = []
    """

    coords = locateAllOnScreen('enemycolordiep.png', confidence=X)
    if coords is None:
        coords = []

    else:
        coords = list(coords)

    print(coords)

    for coord in coords:
        centerCoord = (coord[0] + (coord[2] / 2), coord[1] + (coord[3] / 2))
        print(centerCoord)
        # moveTo(centerCoord[0], centerCoord[1], duration=0)

我希望在屏幕上显示红色位置,但这不起作用。我有 pyautoguipyobjc-corepyobjc-framework-quartzPillowopencv-python 以及这些包所依赖的其他一些东西。我正在使用 MacOS Mojave。感谢您的帮助!

尝试 updating/installing openCV。

查看类似问题的答案:Documentation says to use a confidence parameter, but it throws an error