OPENCV跟踪器未识别(AttributeError:Module' CV2;没有属性' trackerkcf_create;)
import cv2
if __name__ == "__main__":
major_v, minor_v, subminor_v = (cv2.__version__).split('.')
# >>> 4.6.0
tracker = cv2.TrackerKCF_create()
# >>> AttributeError: module 'cv2' has no attribute 'TrackerKCF_create'
如上所述,运行时,这些是我得到的结果(我已经与CV2中的其他跟踪器一起尝试过,除trackermil_create
外,所有应该包括的跟踪器都给我带来了这个错误。我用过 pip安装opencv-python
, pip install opencv-contrib-python
和 pip安装opencv-contrib-python-headless
在我的终端上尝试安装OpenCV。我没有遇到CV2属性的任何其他问题(例如imread
,imshow
,resize
),但是跟踪器给我带来了困难时间,我想知道我从一开始就做错了什么。谢谢。
import cv2
if __name__ == "__main__":
major_v, minor_v, subminor_v = (cv2.__version__).split('.')
# >>> 4.6.0
tracker = cv2.TrackerKCF_create()
# >>> AttributeError: module 'cv2' has no attribute 'TrackerKCF_create'
As the code above shows, when running this these are the results I get (I have tried this with other trackers in cv2 and other than TrackerMIL_create
all trackers that are supposed to be included are giving me this error. I usedpip install opencv-python
,pip install opencv-contrib-python
, andpip install opencv-contrib-python-headless
on my terminal to try and install opencv. I haven't run into any other issues with cv2 attributes (such as imread
, imshow
, resize
) but the trackers are giving me a hard time and I was wondering if there is anything I am doing wrong from the start. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除所有内容,然后重新安装
opencv-contrib-python
。这些软件包可能会相互冲突。pip卸载opencv-contrib-python opencv-python opencv-contrib-python-headless& PIP安装opencv-contrib-python
Remove everything and then reinstall
opencv-contrib-python
. The packages can conflict with one another.pip uninstall opencv-contrib-python opencv-python opencv-contrib-python-headless && pip install opencv-contrib-python
与@ddelarue的答案一样,您要确保您已安装了
opencv-contrib-python
(或opencv-contrib-python-headless
),而不是非contrib版本。此外,在某个时候,API已更改。现在是
cv2.trackerkcf.create()
(在4.9.0.80中,也可能是更早的版本)As with @ddelarue answer, you neeed to make sure that you have
opencv-contrib-python
(oropencv-contrib-python-headless
) installed and not the non-contrib versions.In addition, at some point the API was changed. It is now
cv2.TrackerKCF.create()
(in 4.9.0.80, and potentially earlier versions too)