在运行一个利用opencv库中的SIFT算法的图像拼接程序时,出现了如下错误
C:\Users\syzim\anaconda3\envs\ethan\python.exe C:/Users/syzim/Desktop/代码/ch3/stitcher/ImageStiching.py
Traceback (most recent call last):
File "C:/Users/syzim/Desktop/代码/ch3/stitcher/ImageStiching.py", line 10, in
(result, vis) = stitcher.stitch([imageA, imageB], showMatches=True)
File "C:\Users\syzim\Desktop\代码\ch3\stitcher\Stitcher.py", line 11, in stitch
(kpsA, featuresA) = self.detectAndDescribe(imageA)
File "C:\Users\syzim\Desktop\代码\ch3\stitcher\Stitcher.py", line 44, in detectAndDescribe
descriptor = cv2.xfeatures2d.SIFT_create()
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1210: 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即可解决
我是用的anaconda创建的虚拟环境
卸载原来的opencv
pip uninstall opencv-python
pip uninstall opencv-contrib-python
重装opencv
pip install opencv-python==3.4.2.16
pip install opencv-contrib-python==3.4.2.16
然后运行程序,成功!顺便贴一张结果图
个人网站