RANSAC原理
输入:①数据 ②抽样次数N ③距离阈值t ④数量阈值T
输出:最终估计的模型
程序流程:
1. data :数据
2. 取样本 :确定模型参数p所需要的最小数据数n,随机取n个数据作为一个样本J
3. 建模型:根据样本J建立模型Mp(J)。
4. 判断距离:根据模型Mp(J)判断所有数据点到模型的距离。
5. 记录:记录 距离小于t的个数total 和 距离小于t的点的索引。
6. 判断: 若total>数量阈值T :则用距离小于t的点重新估计模型 重复3-5一次。
若total
7. 记录最大total和此时的模型作为最佳模型。
8. 循环N次。
9.输出
函数ransac_fitplane
function [a,b,c,d]=ransac_fitplane(data,N,t,T)
figure;plot3(data(1,:),data(2,:),data(3,:),'o');hold on; % 显示数据
iter = N; %抽样次数N
number = size(data,2); % 总数
maxNum=0; %符合拟合模型的数据的个数
for i=1:iter %循环次数
sampleidx = randperm(number); sampleidx =sampleidx(1,1:3);
sample = data(:,sampleidx); %取样本
[a1,a2,a3,a4]=get_nice_plane(samp