AttributeError: module ‘cv2’ has no attribute ‘SIFT’ [How to Solve]

AttributeError: module ‘cv2’ has no attribute ‘SIFT’

When encountering this problem, most netizens suggest to add a package, that is, PIP install opencv contrib python.
I made the following error again after completing the repair:
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’
it can be solved by backing the opencv version to 3.4.2, unloading the previous package ( PIP install opencv Python ), and then
PIP install opencv python = = 3.4.2.16
PIP install opencv contrib python = = 3.4.2.16
note that the above two commands = = no spaces are left and right

Error again:

‘module’ object has no attribute ‘xfeatures2d’

Reason: opencv integrates sift and other algorithms into xfeatures 2D set

siftDetector=cv2.SIFT()

Changed to

siftDetector= cv2.xfeatures2d.SIFT_create()

then report another error:

TypeError: Required argument ‘outImage’ (pos 3) not found

im=cv2.drawKeypoints(img_RGB,kp,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
change to im=cv2.drawKeypoints(img_RGB,kp,img,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

SURF:

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()

Similar Posts: