利用PCL中分割算法、算法
pcl::SACSegmentation<pcl::PointXYZ> seg;dom
,不利用法線參數,只根據模型參數獲得的分割面片,與想象的面片差距很大,ui
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擬合的方法,進行面片的分割spa
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);
獲得:指針
以後我想迭代的進行面片擬合後分割出來,在索引的地方遇到了問題code
因而想出來一個比較笨的辦法:對象
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 }
等同於本身寫了一個分割的方法。blog
中間遇到的問題有:索引
點雲的索引、有序點雲與無序點雲的寫入、智能指針未實例化問題、ci
如今仍未搞明白PCL中的索引的使用方法。例如:PointIndices、 ExtractIndices 等
若有了解的小夥伴但願告知、互幫互助、共同進步!
2019-04-12 19:04:34