
利用PCL中分割算法、
pcl::SACSegmentation<pcl::PointXYZ> seg;
,不利用法线参数,只根据模型参数得到的分割面片,与想象的面片差距很大,
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
// 创建分割对象
pcl::SACSegmentation<pcl::PointXYZ> seg;
// 可选
seg.setOptimizeCoefficients (true);
// 必选
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setMaxIterations ();
seg.setDistanceThreshold (0.05);
后我采用RANSAC拟合的方法,进行面片的分割
std::vector<int> inliers; //存储局内点集合的点的索引的向量 //进行RANSAC平面拟合
pcl::SampleConsensusModelPlane<PointT>::Ptr model_p(new pcl::SampleConsensusModelPlane<PointT>(cloud)); //针对平面模型的对象
pcl::RandomSampleConsensus<PointT> ransacP(model_p);
ransacP.setDistanceThreshold(.); //与平面距离小于0.1的点作为局内点考虑
ransacP.computeModel(); //执行随机参数估计
ransacP.getInliers(inliers); //存储估计所得的局内点
pcl::copyPointCloud<PointT>(*cloud, inliers, *cloud_in); //复制估算模型的所有局内点到cloud_in中
pcl::io::savePCDFile("./data/seg_RAN/RANSAC_building_1.pcd", *cloud_in);
得到:
之后我想迭代的进行面片拟合后分割出来,在索引的地方遇到了问题
于是想出来一个比较笨的办法:
for (int i = ; i < cloud->points.size(); i++)
{
std::vector<int>::iterator iter = find(inliers.begin(), inliers.end(), i);
if (iter == inliers.end())
{
cloud_out->points.push_back(cloud->points.at(i));
}
}
等同于自己写了一个分割的方法。
中间遇到的问题有:
点云的索引、有序点云与无序点云的写入、智能指针未实例化问题、
现在仍未搞明白PCL中的索引的使用方法。例如:PointIndices、 ExtractIndices 等
如有了解的小伙伴希望告知、互帮互助、共同进步!
2019-04-12 19:04:34