文档说要使用置信度参数,但会引发错误 [英] Documentation says to use a confidence parameter, but it throws an error
问题描述
编辑以包含代码片段.
我正在使用 pyautogui 开发一个应用程序.我想在桌面上匹配一个区域并单击它.调用 locateOnscreen 函数,我传递包含要匹配的图像的文件名以及置信度参数,该参数会引发错误.
I am developing an app with pyautogui. I want to match a region on the desktop and click it. Calling the locateOnscreen function, I pass the filename containing the image to match, along with a confidence parameter, which throws an error.
import pyautogui as pag
button_login = pag.locateOnScreen("button_login.png", confidence=0.7)
File ".\test.py", line 23, in <module>
button_login = pag.locateOnScreen("button_login.png", confidence=0.7)
...
TypeError: _locateAll_python() got an unexpected keyword argument 'confidence'
安装的版本是 0.9.47.文档指的是 1.0.0 版.我在任何地方都找不到这个版本,包括 pypi 和 github.
Installed version is 0.9.47. The docs refer to version 1.0.0. I can't find this version anywhere including pypi and github.
推荐答案
发生这种情况是因为函数 locateOnScreen
可以达到两个不同的函数 (源代码):
This happens because the function locateOnScreen
can reach two different functions (source code):
_locateAll_opencv
如果安装了 cv2/OpenCV
_locateAll_opencv
if cv2 / OpenCV is installed
_locateAll_python
如果找不到 cv2/OpenCV 或者您使用 python3 的 cv2 版本低于 3
_locateAll_python
if cv2 / OpenCV cannot be found or if you are using python3 with a version of cv2 inferior to 3
并且 _locateAll_python
不处理 confidence
参数.
And _locateAll_python
doesn't handle the confidence
parameter.
因此,如果您需要此功能,可以尝试安装/更新 OpenCV:https://pypi.组织/项目/opencv-python/
So you can try to install/update OpenCV if you need this feature : https://pypi.org/project/opencv-python/
pip install opencv-python
这篇关于文档说要使用置信度参数,但会引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!