我目前正在使用SIFT功能来查找图像之间的相似度。但是我想为它添加更多功能,以便可以改进相似性度量。现在,对于类似的图片,它显示len(good)
左右500
的值,对于棋盘游戏和狗的图像,值约为275
。我可以研究哪些其他功能,可能是全局功能?我如何用SIFT添加它?
def feature_matching():
img1 = cv2.imread('img1.jpeg', 0) # queryImage
img2 = cv2.imread('img2.jpeg', 0)
# 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)
# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)
# Apply ratio test
good = []
for m,n in matches:
if m.distance < 0.75*n.distance:
good.append(m)
print(len(good))
#gray1 = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
#gray2 = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
# cv2.drawMatchesKnn expects list of lists as matches.
img3 = drawMatches(img1,kp1,img2,kp2,good)
答案 0 :(得分:0)
您还可以尝试交叉检查匹配,如C ++中解释here。在python中,您只需要更改以下行:
bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True)