Python3 AttributeError: module ‘cv2‘ has no attribute ‘SIFT‘ ‘module‘ object has no attribute ‘xfea

  • Post author:
  • Post category:python


在用python3使用sift = cv2.SIFT()进行SIFT时候,可能会产生错误:AttributeError: module ‘cv2’ has no attribute ‘SIFT’

解决:将sift = cv2.SIFT()替换为:sift = cv2.xfeatures2d.SIFT_create()

分析:opencv将SIFT等算法整合到xfeatures2d集合里面了。写法:sift = cv2.xfeatures2d.SIFT_create()

然后还有报错,AttributeError: module ‘cv2.cv2’ has no attribute ‘xfeatures2d’

opencv3.X以后opencv只包含部分内容,需要神经网络或者其他的函数需要导入opencv_contrib


解决方法:

pip install opencv-contrib-python
  • 如果已经安装OpenCv2,则需要先卸载

    pip uninstall opencv-python

    再安装

参考资料:

https://pypi.python.org/pypi/opencv-contrib-python



版权声明:本文为CVAIDL原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。