module 'cv2.cv2' has no attribute 'xfeatures2d_SIFT'错误

用于opencv+python图片全景拼接出现的问题

问题1:module 'cv2.cv2' has no attribute 'xfeatures2d_SIFT'问题

解决方法:把sift = cv.xfeatures2d_SIFT().create() 换成sift = cv.xfeatures2d.SIFT_create()

问题2:module 'cv2.cv2' has no attribute 'xfeatures2d'问题

解决方法:需要导入opencv-contrib-python模块,导入语句:pip install opencv-contrib-python。(注意:记得导入完成后刷新一下python,否则在运行的时候还会出现以上错误)

具体导入方法请看连接:https://blog.csdn.net/weixin_43837871/article/details/88897272

问题3:导入opencv-contrib-python模块后,还出现sift = cv.xfeatures2d.SIFT_create()
cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function ‘cv::xfeatures2d::SIFT::create’错误;

解决方法:通过网上了解,这是因为该算法已经申请专利,开源OpenCV没有版权,新的OpenCV去掉了这个算法。所以sift = cv.xfeatures2d.SIFT_create()函数无法使用,也是opencv-contrib-python无法使用。解决方法为降低opencv版本,因为当初安装时是默认最新版本安装的,版本比较高。通过自己测试opencv-python-3.4.2.16和opencv-contrib-python-3.4.2.16可是使用运行。所以要把之前新的版本卸载,安装旧的3.4.2.16版本。

 

你可能感兴趣的:(module 'cv2.cv2' has no attribute 'xfeatures2d_SIFT'错误)