参考 https://blog.youkuaiyun.com/yuxuan_08/article/details/87966840
在用python3使用sift = cv2.SIFT()进行SIFT时候,可能会产生错误:AttributeError: module ‘cv2’ has no attribute ‘SIFT’
import numpy as np
import cv2
from matplotlib import pyplot as plt
MIN_MATCH_COUNT = 10
img1 = cv2.imread('red_cube.jpg', 0) # queryImage
img2 = cv2.imread('image_106.jpg', 0) # trainImage
# Initiate SIFT detector
sift = cv2.SIFT()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None

在使用Python3的cv2库进行SIFT操作时,可能会遇到AttributeError,提示没有'SIFT'属性。解决方案是将`sift = cv2.SIFT()`替换为`sift = cv2.xfeatures2d.SIFT_create()`。如果出现`'cv2.cv2'`没有`xfeatures2d`属性的错误,可能是因为OpenCV版本问题。对于OpenCV 4.x,需要确保已安装opencv-contrib-python。如果仍然存在问题,可能由于SIFT专利问题,降级OpenCV到3.4.2版本,如`pip install opencv-python==3.4.2.17`和`pip install opencv-contrib-python==3.4.2.17`,此方法已被验证可行。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



