AttributeError: module 'cv2' has no attribute 'SIFT'解決總結

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

遇到該問題時,網友可能是建議補個包,即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
注意以上兩條命令==左右沒有空格python

又報錯誤:算法

  'module' object has no attribute 'xfeatures2d'ui

緣由:opencv將SIFT等算法整合到xfeatures2d集合裏面了。this

siftDetector=cv2.SIFT()

變動後爲spa

siftDetector= cv2.xfeatures2d.SIFT_create()

又報:code

TypeError: Required argument 'outImage' (pos 3) not foundblog

im=cv2.drawKeypoints(img_RGB,kp,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
變動後爲im=cv2.drawKeypoints(img_RGB,kp,img,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

 SURF:ip

import cv2
 
img = cv2.imread('cat.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
 
surf = cv2.xfeatures2d.SURF_create()
kp = surf.detect(gray, None)
 
img = cv2.drawKeypoints(gray, kp, img)
 
cv2.imshow("img", img)
 
k = cv2.waitKey(0)
if k & 0xff == 27:
    cv2.destroyAllWindows()

it

相關文章
相關標籤/搜索