我尝试在屏幕上找到图像。
我尝试重新安装 pyautogui 和 Pillow 但它总是显示这个:
Traceback (most recent call last):
File "c:\Users\win0908\Desktop\PY\stickman.py", line 9, in <module>
if pyautogui.locateOnScreen('stickman.png', region=(150,175,350,600), grayscale=True, confidence=0.8) != None:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\win0908\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\__init__.py", line 172, in wrapper
return wrappedFunction(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\win0908\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\__init__.py", line 210, in locateOnScreen
return pyscreeze.locateOnScreen(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\win0908\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 405, in locateOnScreen
retVal = locate(image, screenshotIm, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\win0908\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 383, in locate
points = tuple(locateAll(needleImage, haystackImage, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\win0908\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 241, in _locateAll_opencv
raise ValueError('needle dimension(s) exceed the haystack image or region dimensions')
ValueError: needle dimension(s) exceed the haystack image or region dimensions
这是我的代码:
import pyautogui
if pyautogui.locateOnScreen('stickman.png', confidence=0.8) != None:
print("I can see it")
请帮忙!
该错误试图告诉您
stickman.png
图像大于它正在搜索的区域。请参阅错误的以下部分:
File "c:\Users\win0908\Desktop\PY\stickman.py", line 9, in <module>
if pyautogui.locateOnScreen('stickman.png', region=(150,175,350,600), grayscale=True, confidence=0.8) != None:
它正在区域
(150,175,350,600)
(这些是代表区域的x、y、宽度、高度值)中搜索,该区域的尺寸比stickman.png
图像更小