When practicing the sift
operator, I found this problem:
AttributeError: 'module' object has no attribute 'xfeatures2d'
OpenCV version problem, because the sift operator is patented, the original OpenCV cannot include this function, and it can only be included in the extension package `opencv-contrib-python`.
In two versions
1)If the version of opencv-python is <=3.4
:
pip install opencv-contrib-python==3.4.2.17
sift = cv2.xfeatures2d.SIFT_create()
kp = sift.detect(gray_img, None)
img = cv2.drawKeypoints(gray_img, kp, img)
plt.imshow(img)
2) If the version of opencv-python is >=4.5
:
pip install opencv-contrib-python==4.5.3.56
When using
sift = cv2.SIFT_create()
kp = sift.detect(gray_img, None)
img = cv2.drawKeypoints(gray_img, kp, img)
plt.imshow(img)