AttributeError: ‘module‘ object has no attribute ‘xfeatures2d‘

AttributeError: ‘module‘ object has no attribute ‘xfeatures2d‘,第1张

AttributeError: ‘module‘ object has no attribute ‘xfeatures2d‘ 问题

在练习sift算子的时候,发现出现这个问题:

AttributeError: 'module' object has no attribute 'xfeatures2d'
原因

OpenCV版本问题,由于sift算子是有专利的,固原始OpenCV是无法包含该函数的,只能在扩展包中opencv-contrib-python。

解决办法

分两个版本

  • 如果opencv-python的版本是<=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)
  • 如果opencv-python的版本是>=4.5:
    • pip install opencv-contrib-python==4.5.3.56
    • 使用的时候
sift = cv2.SIFT_create()
kp = sift.detect(gray_img, None)
img = cv2.drawKeypoints(gray_img, kp, img)
plt.imshow(img)
参考
  • https://stackoverflow.com/questions/37039224/attributeerror-module-object-has-no-attribute-xfeatures2d-python-opencv-2

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5625364.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存