SLAM的那些坑——RANSAC

用特征法匹配两帧图像估计相机位姿的时候, 匹配的特征点对中有很多都是误匹配, 这些误匹配如果被用于计算位姿, 无疑会得到一个错误的答案, 于是引入了RANSAC which stands for Random Sample Consesus to overcome the barrier.

RANSAC随机采样一致性是一种利用实验数据拟合模型的方法,能够用来平滑带有大量干扰的数据,所以当然可以用来筛除错误的匹配点对,留下正确的匹配点对. 其他经典的优化技术如最小二乘和优化函数模型没有内在的机制去检测和去除较大的误差数据,而是用所有数据去拟合去对偏差期望求均值,所以需要大量的好的数据去平滑大的偏差. 而RANSAC与传统的方法不同,是利用小的可行的初始数据集然后利用一致性尽可能的扩大这个集合.

一段 RANSAC 算法的伪代码 看一遍就懂了

Given:
    data – a set of observed data points
    model – a model that can be fitted to data points
    n – minimum number of data points required to fit the model
    k – maximum number of iterations allowed in the algorithm
    t – threshold value to determine when a data point fits a model
    d – number of close data points required to assert that a model fits well to data

Return:
    bestfit – model parameters which best fit the data (or nul if no good model is found)

iterations = 0
bestfit = nul
besterr = something really large
while iterations < k {
    maybeinliers = n randomly selected values from data
    maybemodel = model parameters fitted to maybeinliers
    alsoinliers = empty set
    for every point in data not in maybeinliers {
        if point fits maybemodel with an error smaller than t
             add point to alsoinliers
    }
    if the number of elements in alsoinliers is > d {
        % this implies that we may have found a good model
        % now test how good it is
        bettermodel = model parameters fitted to all points in maybeinliers and alsoinliers
        thiserr = a measure of how well model fits these points
        if thiserr < besterr {
            bestfit = bettermodel
            besterr = thiserr
        }
    }
    increment iterations
}
return bestfit


你可能感兴趣的:(SLAM)