当前位置: 移动技术网 > IT编程>开发语言>C/C++ > PCL利用RANSAC自行拟合分割平面

PCL利用RANSAC自行拟合分割平面

2019年04月13日  | 移动技术网IT编程  | 我要评论

前列腺炎的治疗费用,胜利油田向浩被杀,木地板招商

利用pcl中分割算法、

 pcl::sacsegmentation<pcl::pointxyz> seg;

,不利用法线参数,只根据模型参数得到的分割面片,与想象的面片差距很大,

 1  pcl::modelcoefficients::ptr coefficients (new pcl::modelcoefficients ());
 2   pcl::pointindices::ptr inliers (new pcl::pointindices ());
 3   // 创建分割对象
 4   pcl::sacsegmentation<pcl::pointxyz> seg;
 5   // 可选
 6   seg.setoptimizecoefficients (true);
 7   // 必选
 8   seg.setmodeltype (pcl::sacmodel_plane);
 9   seg.setmethodtype (pcl::sac_ransac);
10   seg.setmaxiterations (1000);
11   seg.setdistancethreshold (0.05);

后我采用ransac拟合的方法,进行面片的分割

 1     std::vector<int> inliers;    //存储局内点集合的点的索引的向量
 2     
 3     //进行ransac平面拟合
 4     pcl::sampleconsensusmodelplane<pointt>::ptr    model_p(new pcl::sampleconsensusmodelplane<pointt>(cloud));        //针对平面模型的对象
 5     pcl::randomsampleconsensus<pointt> ransacp(model_p);
 6     ransacp.setdistancethreshold(.1);        //与平面距离小于0.1的点作为局内点考虑
 7     ransacp.computemodel();                    //执行随机参数估计
 8     ransacp.getinliers(inliers);                //存储估计所得的局内点
 9     pcl::copypointcloud<pointt>(*cloud, inliers, *cloud_in);    //复制估算模型的所有局内点到cloud_in中
10     pcl::io::savepcdfile("./data/seg_ran/ransac_building_1.pcd", *cloud_in);

得到:

之后我想迭代的进行面片拟合后分割出来,在索引的地方遇到了问题

于是想出来一个比较笨的办法:

 

1 for (int i = 0; i < cloud->points.size(); i++)
2     {
3         std::vector<int>::iterator iter = find(inliers.begin(), inliers.end(), i);
4         if (iter == inliers.end())
5         {
6             cloud_out->points.push_back(cloud->points.at(i));
7         }
8     }

 

等同于自己写了一个分割的方法。

中间遇到的问题有:

点云的索引、有序点云与无序点云的写入、智能指针未实例化问题、

现在仍未搞明白pcl中的索引的使用方法。例如:pointindices、 extractindices 等

如有了解的小伙伴希望告知、互帮互助、共同进步!

2019-04-12  19:04:34

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网