**1. sift算法的错误**
~~~
sift = cv.xfeatures2d_SIFT().create()
~~~
出现错误:
[1] [AttributeError: 'module' object has no attribute 'xfeatures2d' \[Python/OpenCV 2.4\]]
**解决**:安装pip install opencv-python opencv-contrib-python
[ 2] 又遇到如下错误:
cv2.error:OpenCV(4.1.0)C:\projects\opencvpython\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版本退到3.4.2可解决,卸载之前的包,然后
pip install opencv-python == 3.4.2.16
pip install opencv-contrib-python == 3.4.2.16
参考:https://www.jianshu.com/p/0f8185a1616f
**2.问题cv2.resize()报错**
error: (-215:Assertion failed) !_img.empty() && ((imgtype) & ((1 << 3) - 1)) == 0 && (imgcn == 1 || imgcn == 3 || imgcn == 4) in function 'cv::xfeatures2d::SURF_Impl::detectAndCompute'
**解决:**请一定好好检查图片读取路径有没有写对!!!
可能错误:
1.图片路径写成了如下形式:C:\Users\Desktop\test\
正确的应该为:C:/Users/Desktop/test/
(在程序中斜杠‘\’有转义字符含义)
2.图片路径少写了一个斜杠(图片存放在test文件夹中)
错误:C:/Users/Desktop/test
正确:C:/Users/Desktop/test/
(千千万万不要忘了最后一个斜杠,不然读取的就变成了test这个文件夹而不是里面的图片了,因为一个不小心,我苦恼了两天,还以为是opencv的锅,尝试了无数种解决方案,放佛一个白痴!!!)
3.图片的格式不对!
4.图片的数量不一致!
5.路径中、文件夹名称都不要包含中文!.(编程中各种命名都尽量使用易懂的英文,实在不行用拼音hhh)