天天看點

解決: AttributeError: module 'cv2' has no attribute 'SURF'

AttributeError: module 'cv2' has no attribute 'SURF'

遇到該問題時,網友多是建議補個包,即pip install opencv-contrib-python

我在補完之後又出現下面這樣的錯誤:

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版本退到3.4.2即可解決,解除安裝之前的包(pip uninstall opencv-python),然後

pip install opencv-python==3.4.2.16
pip install opencv-contrib-python==3.4.2.16      

注意以上兩條指令==左右沒有空格

又報錯誤:

'module' object has no attribute 'xfeatures2d'

變更後為

Detector= cv2.xfeatures2d.SURF_create()

繼續閱讀