简体   繁体   English

AttributeError:模块'cv2.cv2'没有属性'SURF_create',2.模块'cv2.cv2'没有属性'xfeatures2d'

[英]AttributeError: module 'cv2.cv2' has no attribute 'SURF_create' , 2. module 'cv2.cv2' has no attribute 'xfeatures2d'

I'm new to OpenCV and trying to use SIFT and SURF for a project.我是 OpenCV 的新手,正在尝试将 SIFT 和 SURF 用于项目。
On my laptop I have OpenCV version= 4.5.1.48 and also added OpenCV-contrib-python of version 4.5.1.48在我的笔记本电脑上,我有 OpenCV 版本= 4.5.1.48 并且还添加了版本 4.5.1.48 的 OpenCV-contrib-python
currently the problem I'm facing is the error I'm getting after following the documentation SIFT works perfectly after following documentation but SURF isn't working and giving me error for following codes目前我面临的问题是我在遵循文档后遇到的错误 SIFT 在遵循文档后完美运行,但 SURF 无法正常工作并给我以下代码错误

code 1代码 1
surf = cv.xfeatures2d.SURF_create()冲浪 = cv.xfeatures2d.SURF_create()
AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d' AttributeError:模块“cv2.cv2”没有属性“xfeatures2d”

code 2代码 2
surf = cv2.SURF_create()冲浪 = cv2.SURF_create()
AttributeError: module 'cv2.cv2' has no attribute 'SURF_create' AttributeError:模块“cv2.cv2”没有属性“SURF_create”

After reading many answers on Stack overflow I changed version of OpenCV and did many things but nothing is working for me在阅读了有关 Stack Overflow 的许多答案后,我更改了 OpenCV 的版本并做了很多事情,但没有什么对我有用
I'm new to this please someone guide me through this我是新手,请有人指导我完成这个
I read about the patent expiring too but nothing is working in my case pls tell me if im wrong somewhere Thanks in advance我也读到了专利即将到期的消息,但在我的情况下没有任何效果,请告诉我我是否在某处有误提前谢谢

OpenCV version= 4.5.1.48 OpenCV 版本 = 4.5.1.48

this is probably from pypi, and does not contain any "nonfree" code这可能来自 pypi,并且不包含任何“非自由”代码

(SURF is still patented, if you absolutely need that, you have to build from src (with contrib modules), using the OPENCV_ENABLE_NONFREE=ON cmake flag) (SURF 仍然是专利,如果你绝对需要,你必须从 src 构建(使用 contrib 模块),使用 OPENCV_ENABLE_NONFREE=ON cmake 标志)

however, since the SIFT patent expired last year, use that instead但是,由于 SIFT 专利于去年到期,请改用它

sift = cv2.SIFT_create() # it's in main, no more xfeatures2d

btw, dont install both opencv-python, and opencv-contrib-python, only the latter (else the former will "shadow" it, and you cannot use contrib modules. this is the reason for AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d' )顺便说一句,不要同时安装 opencv-python 和 opencv-contrib-python,只安装后者(否则前者会“隐藏”它,并且您不能使用 contrib 模块。这就是AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d'

For patent reasons, opencv 4.5.1.48 does not include the whole algorithm由于专利原因,opencv 4.5.1.48 不包含整个算法

You can use Python3.6 (or Python3.7 maybe OK) and install opencv-pyhton==3.4.2.16 and opencv-contrib-python==3.4.2.16 , then you can use the function that:您可以使用 Python3.6(或 Python3.7 可能还可以)并安装opencv-pyhton==3.4.2.16opencv-contrib-python==3.4.2.16 ,然后您可以使用以下功能:

surf = cv2.xfeatures2d.SURF_create() or sift = cv2.xfeatures2d.SIFT_create() surf = cv2.xfeatures2d.SURF_create()sift = cv2.xfeatures2d.SIFT_create()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM