我正在使用Python 2.7上的open cv 3.0.0。我试图通过Surf方法检测徽标。但面临一个错误即分段错误。你能帮我们解决这个问题吗?并非总是发生此错误。有时似乎。我在下面分享代码。
img1 = cv2.imread('logo1.jpg',0) # queryImage
img2 = cv2.imread('logo2.jpg',0) # trainImage
sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)
kp2,des2 = sift.detectAndCompute(img2,None)
# FLANN parameters
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 4)
search_params = dict(checks=50) # or pass empty dictionary
flann = cv2.FlannBasedMatcher(index_params,search_params)
matches = flann.knnMatch(np.asarray(des1,np.float32),np.asarray(des2,np.float32),k=2)
for i,(m,n) in enumerate(matches):
if m.distance < 0.7*n.distance:
c +=1
return(c)
我认为分段错误出现在这一行:
matches = flann.knnMatch(np.asarray(des1,np.float32),np.asarray(des2,np.float32),k=2)