PCL中的点云分割模型的部分常用参数含义

1、SACMODEL_PLANE

该参数指的是点云平面拟合,拟合后得到的平面方程为:AX+BY+CZ+D=0。执行点云分割算法pcl::SACSegmentation后,输出的归一化向量是[A B C D]。
例如:

pcl::ModelCoefficients::Ptr coefficients;
pcl::SACSegmentation<pcl::PointXYZ> seg;		//创建分割对象
seg.setOptimizeCoefficients(true);				//设置对估计模型参数进行优化处理
seg.setModelType(pcl::SACMODEL_PLANE);			//设置分割模型类别
seg.setMethodType(pcl::SAC_RANSAC);				//设置用哪个随机参数估计方法
seg.setMaxIterations(1000);						//设置最大迭代次数
seg.setDistanceThreshold(1.0);                  //判断是否为模型内点的距离阀值  
seg.setInputCloud(cloudsource);
seg.segment(*inliers, *coefficients);

2、SACMODEL_LINE(三维直线)

点云三维直线拟合,获得的是三维直线上的一点以及其单位方向向量:
[point_on_line.x point_on_line.y point_on_line.z line_direction.x line_direction.y line_direction.z]
直线上一点:[point_on_line.x point_on_line.y point_on_line.z]
单位方向向量:[line_direction.x line_direction.y line_direction.z]

3、SACMODEL_CIRCLE2D(二维圆)

获得的是二维圆的中心以及半径: [center.x center.y radius]
center.x : the X coordinate of the circle’s center
center.y : the Y coordinate of the circle’s center
radius : the circle’s radius

#include <pcl/sample_consensus/sac_model_circle.h>
pcl::SampleConsensusModelCircle2D<pcl::PointXYZ>::Ptr
 model_circle2D(new pcl::SampleConsensusModelCircle2D<pcl::PointXYZ>(cloud));
pcl::RandomSampleConsensus<pcl::PointXYZ> ransac(model_circle2D);
ransac.setDistanceThreshold(.01);
ransac.computeModel();
ransac.getInliers(inliers);
Eigen::VectorXf modelParas;
ransac.getModelCoefficients(modelParas);
//圆心坐标及半径
std::cout << modelParas<< "\n\n";

4、SACMODEL_CIRCLE3D(三维圆)

#include <pcl/sample_consensus/sac_model_circle3d.h>
pcl::SampleConsensusModelCircle3D<pcl::PointXYZ>::Ptr
 model_circle3D(new pcl::SampleConsensusModelCircle3D<pcl::PointXYZ>(cloud));
pcl::RandomSampleConsensus<pcl::PointXYZ> ransac(model_circle3D);
ransac.setDistanceThreshold(.01);
ransac.computeModel();
ransac.getInliers(inliers);  
Eigen::VectorXf modelParas;
ransac.getModelCoefficients(modelParas);
//所计算出的圆心坐标及半径如下,前三个数值为圆心坐标(x, y, z),第四个数值为计算出的圆形点云的半径,最后三个为圆形点云所在平面的法向量:
std::cout << modelParas<< "\n\n";  

5、SACMODEL_SPHERE(球)

获得球心以及半径: [center.x center.y center.z radius]
center.x : the X coordinate of the sphere’s center
center.y : the Y coordinate of the sphere’s center
center.z : the Z coordinate of the sphere’s center
radius : the sphere’s radius

6、SACMODEL_CYLINDER(圆柱)

以下图片来源网上截图
在这里插入图片描述
圆柱方程的核心思想是:圆柱上的一点到圆柱轴线(单位方向向量)的距离为r。以下是圆柱拟合的代码示例:

// 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.005);
    //设置估计出的圆柱模型的半径的范围
    seg.setRadiusLimits(0.01, 0.1);
    seg.setInputCloud(cloud_filtered);
    seg.setInputNormals(cloud_normals);
    //最终获取内点以及模型系数
    seg.segment(*inliers_cylinder, *coefficients_cylinder);
 
     //Extract the cylinder inliers from the input cloud
    extract.setInputCloud(cloud_filtered);
    extract.setIndices(inliers_cylinder);
    extract.setNegative(false);
    extract.filter(*cloud_cylinder);
    std::cout << "PointCloud representing the planar component: " << cloud_cylinder-> size() << "data points." << std::endl;
    writer.write("cylinder_piece.pcd", *cloud_cylinder, false);

获得的参数为圆柱轴线上一点,以及圆柱的轴线单位方向向量,以及圆柱的半径: [point_on_axis.x point_on_axis.y point_on_axis.z]
[axis_direction.x axis_direction.y axis_direction.z]
[radius]

  • 16
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PCL点云分割是通过定义满足某些条件的点云的一组点来实现的。每个点云都具有多个字段,例如XYZ坐标,RGB颜色等。以下是一个基本的点云分割示例,其点云的XYZ坐标被用作分割依据: ```cpp #include <pcl/point_types.h> #include <pcl/filters/extract_indices.h> #include <pcl/segmentation/sac_segmentation.h> pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); // 假设将点云数据加载到变量cloud 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(1000); seg.setDistanceThreshold(0.01); // 设置SACSegmentation的参数 seg.setInputCloud(cloud); seg.segment(*inliers, *coefficients); // 执行分割 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>); pcl::ExtractIndices<pcl::PointXYZ> extract; extract.setInputCloud(cloud); extract.setIndices(inliers); extract.setNegative(false); extract.filter(*cloud_filtered); // 将分割结果提取为一个新的点云 // 输出分割结果 std::cerr << "Model coefficients: " << coefficients->values[0] << " " << coefficients->values[1] << " " << coefficients->values[2] << " " << coefficients->values[3] << std::endl; std::cerr << "Inliers: " << inliers->indices.size() << std::endl; ``` 在这个例子点云分割采用了基于RANSAC的平面模型,其距离阈值设置为0.01。分割结果被提取为一个新的点云(`cloud_filtered`),其只包含内点。你可以根据你的需要修改距离阈值和其他参数

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值