PCL1.8.1 採樣一致性算法 RANSAC

採樣一致性算法主要是擬合點雲中的平面、直線、圓等參數模型。php

http://pointclouds.org/documentation/tutorials/random_sample_consensus.php#random-sample-consensus算法

平面擬合

將遠離平面0.01米的點剔除掉app

#include <pcl/sample_consensus/ransac.h>
#include <pcl/sample_consensus/sac_model_plane.h>


pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr final(new pcl::PointCloud<pcl::PointXYZ>);

//建立一個平面模型
pcl::SampleConsensusModelPlane<pcl::PointXYZ>::Ptr
		model_p(new pcl::SampleConsensusModelPlane<pcl::PointXYZ>(cloud));

//用於保存擬合後的點的索引
std::vector<int> inliers;

//建立隨機採樣一致性算法
pcl::RandomSampleConsensus<pcl::PointXYZ> ransac(model_p);
ransac.setDistanceThreshold(.01);
ransac.computeModel();
ransac.getInliers(inliers);

// copies all inliers of the model computed to another PointCloud
pcl::copyPointCloud (*cloud, inliers, *final);

球形擬合

將遠離qiu面0.01米的點剔除掉dom

#include <pcl/sample_consensus/ransac.h>
#include <pcl/sample_consensus/sac_model_sphere.h>

//用於保存擬合後的點的索引
std::vector<int> inliers;


// initialize PointClouds
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr final (new pcl::PointCloud<pcl::PointXYZ>);

// created RandomSampleConsensus object and compute the appropriated model
pcl::SampleConsensusModelSphere<pcl::PointXYZ>::Ptr
    model_s(new pcl::SampleConsensusModelSphere<pcl::PointXYZ> (cloud));

pcl::RandomSampleConsensus<pcl::PointXYZ> ransac (model_s);
ransac.setDistanceThreshold (.01);
ransac.computeModel();
ransac.getInliers(inliers);

pcl::copyPointCloud (*cloud, inliers, *final);
相關文章
相關標籤/搜索