因为要使用SIFT需要用到opencv-contrib-python包中的cv2.xfeatures2d,但在安装了opencv-contrib-python之后,程序报错如下:
(-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-contrib-python的版本问题,当前版本为4.1.0。
解决方法:
pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip install opencv-contrib-python==3.4.2.17