227°

PCL1.8.1 采样一致性算法 RANSAC

采样一致性算法主要是拟合点云中的平面、直线、圆等参数模型。

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

平面拟合

将远离平面0.01米的点剔除掉

#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米的点剔除掉

#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);

 

本文由【J】发布于开源中国,原文链接:https://my.oschina.net/u/4228078/blog/3134422

全部评论: 0

    我有话说: