http://pointclouds.org/documentation/tutorials/cylinder_segmentation.php#cylinder-segmentationphp
#include <pcl/ModelCoefficients.h> #include <pcl/point_types.h> #include <pcl/sample_consensus/method_types.h> #include <pcl/sample_consensus/model_types.h> #include <pcl/segmentation/sac_segmentation.h> #include <pcl/features/normal_3d.h> typedef pcl::PointXYZ PointT; pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg; pcl::PointCloud<PointT>::Ptr cloud_filtered2 (new pcl::PointCloud<PointT>); pcl::PointCloud<pcl::Normal>::Ptr cloud_normals2 (new pcl::PointCloud<pcl::Normal>); // Create the segmentation object for cylinder segmentation and set all the parameters seg.setOptimizeCoefficients (true); //設置對估計的模型係數進行優化 seg.setModelType (pcl::SACMODEL_CYLINDER); //設置分割模型爲圓柱形 seg.setMethodType (pcl::SAC_RANSAC); seg.setNormalDistanceWeight (0.1); //設置表面法線權重係數 seg.setMaxIterations (10000); seg.setDistanceThreshold (0.05); seg.setRadiusLimits (0, 0.1); //設置估計出的圓柱模型的半徑範圍 seg.setInputCloud (cloud_filtered2); seg.setInputNormals (cloud_normals2); // Obtain the cylinder inliers and coefficients pcl::ModelCoefficients::Ptr coefficients_cylinder (new pcl::ModelCoefficients); pcl::PointIndices::Ptr inliers_cylinder (new pcl::PointIndices); seg.segment (*inliers_cylinder, *coefficients_cylinder); std::cerr << "Cylinder coefficients: " << *coefficients_cylinder << std::endl;