问题描述
我已经浏览了下面的代码,想知道在使用 RANSAC 后如何计算离群点和内点?你能指出一个好的代码是如何完成的吗?
第二个问题,哪个特征匹配算法更好:BFMatcher.knnmatch() with Test ratio 或 bf = cv.BFMatcher(cv.norM_HAMMING,crossCheck=True) 最短距离?这个比较有什么参考吗?
**# BFMatcher with default params
bf = cv.BFMatcher()
matches = bf.knnMatch(des1,des2,k=2)
# Apply ratio test
good_matches = []
for m,n in matches:
if m.distance < 0.75*n.distance:
good_matches.append([m])
# Draw matches
img3=cv.drawMatchesKnn(img1,kp1,img2,kp2,good_matches,None,flags=cv.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
cv.imwrite('matches.jpg',img3)
# Select good matched keypoints
ref_matched_kpts = np.float32([kp1[m[0].queryIdx].pt for m in good_matches])
sensed_matched_kpts = np.float32([kp2[m[0].trainIdx].pt for m in good_matches])
# Compute homography
H,status = cv.findHomography(sensed_matched_kpts,ref_matched_kpts,cv.RANSAC,5.0)**
解决方法
计算异常值和内部值的数量
# number of detected outliers: len(status) - np.sum(status)
# number of detected inliers: np.sum(status)
# Inlier Ratio,number of inlier/number of matches: float(np.sum(status)) / float(len(status))
特征匹配算法
我想说的是,如果您使用的是基于稀疏特征的算法(SIFT 或 SURF),则首选 BFMatcher.knnMatch() with Test ratio
。而 bf = cv.BFMatcher(cv.NORM_HAMMING,crossCheck=True)
用于基于二进制的算法(ORB、FAST 等)。我的建议是在您的项目中尝试两种算法,以研究哪一种更好。
Good Reference