def SIFTMATCHPOINTS(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)
# Apply ratio test
matchesMask =np.array( [0 for i in range(len(matches))])
good=[]
for i,(m,n) in enumerate(matches):
if 0.50*n.distance<m.distance < 0.85*n.distance:
good.append(m)
matchesMask[i]=1
src_pts = [ tuple([int(pos) for pos in kp1[m.queryIdx].pt]) for m in good ]
dst_pts = [ tuple([int(pos) for pos in kp2[m.trainIdx].pt]) for m in good ]
return dict(zip(src_pts,dst_pts))
# kp1=np.array(kp1)[matchesMask==1]
# kp2=np.array(kp2)[matchesMask==1]
# kp1pt=list(map(lambda x: tuple([int(posi) for posi in x.pt]),kp1))
# kp2pt=list(map(lambda x: tuple([int(posi) for posi in x.pt]),kp2))
# return dict(zip(kp1pt,kp2pt))
评论列表
文章目录