def SIFTMATCHCOUNT(img1,img2):
img1=img1.copy()
img2=img2.copy()
# find the keypoints and descriptors with SIFT
kp1, des1 = Sift.detectAndCompute(img1,None)
kp2, des2 = Sift.detectAndCompute(img2,None)
# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)
if len(np.array(matches).shape)!=2 or np.array(matches).shape[1]!=2:
return 0
# Apply ratio test
good = []
for m,n in matches:
if 0.50*n.distance<m.distance < 0.80*n.distance:
good.append([m])
return len(good)
评论列表
文章目录