采样一致性算法主要是拟合点云中的平面、直线、圆等参数模型。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);