我正在尝试在两张图片上使用 SIFT,并使用 OpenCV 中的 BFMatcher 匹配关键点。
然而,匹配数不等于查询描述符的数量。有人能解释一下为什么它们不相等吗?
根据 docs 的介绍,match()
函数"为查询集中的每个描述符找到最佳匹配项。"
import cv2
import numpy as np
im1 = cv2.imread("trex1.png", cv2.IMREAD_GRAYSCALE)
im2 = cv2.imread("trex2.png", cv2.IMREAD_GRAYSCALE)
sift = cv2.xfeatures2d.SIFT_create()
kp1, des1 = sift.detectAndCompute(im1, None)
kp2, des2 = sift.detectAndCompute(im2, None)
im_kp1 = np.zeros(im1.shape, dtype=np.uint8)
im_kp2 = np.zeros(im1.shape, dtype=np.uint8)
im_kp1 = cv2.drawKeypoints(im1,kp1,None)
im_kp2 = cv2.drawKeypoints(im2,kp2,None)
bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True)
matches = bf.match(des1,des2)
print len(des1)
# Result : 78
print len(des2)
# Result : 71
print len(matches)
# Result : 55