引用opencv异常
1.异常AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d'
原因:**3.X以后OpenCv只包含部分内容,需要神经网络或者其他的函数需要导入opencv_contrib
解决方法:
pip3 install opencv-contrib-python
注意:如果已经安装OpenCv2(opencv-python),则需要先卸载pip3 uninstall opencv-python再安装
2.异常 cv2.error: OpenCV(4.0.0) 类型
cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:3784: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
解决方法:
原因:这种情况可能是图片格式的问题(我还没有遇到过,后续补充......)
3.异常 cv2.error: OpenCV(4.0.0) 类型
cv2.error: OpenCV(3.4.3) 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-python和opencv-contrib-python版本不一致,新版本的兼容性问题
解决方法:
(1)安装匹配的opencv-python与opencv-contrib-python版本
pip install opencv-python == 3.4.2.16 pip install opencv-contrib-python == 3.4.2.16
或者是opencv-python(3.4.0.14)和opencv-contrib-python(3.4.2.17)
(2)如果解决方法(1)还没有解决问题的话,就在CMD终端命令行卸载之前安装的opencv-python与opencv-contrib-python版本,直接在pycharm安装opencv-contrib-python3.3版本,我这里是安装opencv-contrib-python3.3.1.11版本
(3)下载whl安装,下载链接https://www.lfd.uci.edu/~gohlke/pythonlibs/
pip3 install opencv_python-3.4.0-cp36-cp36m-win_amd64.whl