ORB应用正常。既然没有办法找出我的单纯形的准确性,我就试着找出我的匹配的准确性,哪种方法是正确的?在我的代码中,除去异常值后的匹配显然是原始匹配。我想在我执行比率测试后,得到好的匹配,并找到他们的准确性。在
代码:
detector = cv2.ORB_create(FEATURESCOUNT)
kp1, desc1 = detector.detectAndCompute(img1, None)
kp2, desc2 = detector.detectAndCompute(img2, None)
flann_params= dict(algorithm = FLANN_INDEX_LSH, table_number = 6, key_size = 12, bmulti_probe_level = 1)
matcher = cv2.FlannBasedMatcher(flann_params, {})
raw_matches = matcher.knnMatch(desc1, trainDescriptors = desc2, k = 2)
ratio = 0.9
mkp1, mkp2 = [], []
for m in raw_matches:
if len(m) == 2 and m[0].distance < m[1].distance * ratio:
m = m[0]
mkp1.append( kp1[m.queryIdx] )
mkp2.append( kp2[m.trainIdx] )
print max(distmax)
distall = sum(i for i in distmax)
print distall/len(distmax)
p1 = np.float32([kp.pt for kp in mkp1])
p2 = np.float32([kp.pt for kp in mkp2])
comps =[]
res = []
kp_pairs = zip(mkp1, mkp2)
if len(p1) >= 4:
H, status = cv2.findHomography(p1, p2, cv2.RANSAC, 5.0)
comps = getComponents(H)
print (comps)
print('%d / %d inliers/matched' % (np.sum(status), len(status)))
else:
H, status = None, None
print('%d matches found, not enough for homography estimation' % len(p1))
衡量单应性质量的一个常用方法(假设两幅图像中都存在误差)是重投影误差。当各点对应误差为高斯分布时,最小重投影误差等价于最大似然估计。它被计算为follows,其中(x_i,x_i')是对应关系,H是单应性,d是图像中的几何距离,即在非均匀图像点上。在
findHomography内部已经尝试优化重投影错误。如果找不到单应项(基于传递的max reprojection error),那么函数应该返回None。在
如果结果是完全错误的,我会将ORB改为AKAZE特征,并减少RANSAC方案中inlier分类的最大重投影误差。 如果单应性是一个很好的粗略估计,需要进一步优化,则可以使用单应性通过将每个点与单应映射来找到所有兴趣点上的更多匹配,并在局部邻域中找到最近的兴趣点。然后你可以再计算一次findHomography。在
相关问题 更多 >
编程相关推荐