PCL:3DSC特征(3D形状上下文特征)

介绍:3DSC

包含XYZ字段即可,代码如下:

#include <iostream>
#include <vector>

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/features/3dsc.h>
#include <pcl/features/impl/3dsc.hpp>
#include <pcl/features/normal_3d.h>

int
main (int, char** argv)
{
  std::string filename = argv[1];
  std::cout << "Reading " << filename << std::endl;
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);

  if (pcl::io::loadPCDFile <pcl::PointXYZ> (filename.c_str (), *cloud) == -1)
  // load the file
  {
    PCL_ERROR ("Couldn't read file");
    return (-1);
  }
  std::cout << "Loaded " << cloud->points.size () << " points." << std::endl;

  // Compute the normals
  pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimation;
  normal_estimation.setInputCloud (cloud);

  pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree (new pcl::search::KdTree<pcl::PointXYZ>);
  normal_estimation.setSearchMethod (kdtree);

  pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud< pcl::Normal>);
  normal_estimation.setRadiusSearch (0.03);
  normal_estimation.compute (*normals);

  // Setup the shape context computation
  pcl::ShapeContext3DEstimation<pcl::PointXYZ, pcl::Normal, pcl::ShapeContext1980> shape_context;

  // Provide the point cloud
  shape_context.setInputCloud (cloud);
  // Provide normals
  shape_context.setInputNormals (normals);
  // Use the same KdTree from the normal estimation
  shape_context.setSearchMethod (kdtree);
  pcl::PointCloud<pcl::ShapeContext1980>::Ptr shape_context_features (new pcl::PointCloud<pcl::ShapeContext1980>);

  // The minimal radius is generally set to approx. 1/10 of the search radius, while the pt. density radius is generally set to 1/5
  shape_context.setRadiusSearch (0.2);
  shape_context.setPointDensityRadius (0.04);
  shape_context.setMinimalRadius (0.02);

  // Actually compute the shape contexts
  shape_context.compute (*shape_context_features);
  std::cout << "3DSC output points.size (): " << shape_context_features->points.size () << std::endl;

  // Display and retrieve the shape context descriptor vector for the 0th point.
  std::cout << shape_context_features->points[0] << std::endl;
  //float* first_descriptor = shape_context_features->points[0].descriptor; // 1980 elements

  return 0;
}

来源:PCL官方示例

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`pcl::SACMODEL_CIRCLE3D`是[PCL库](https://pcl.readthedocs.io/projects/tutorials/en/latest/)中的一个模型,用于拟合3D点云中的圆。该模型可以在噪声和异常值存在的情况下,从三维空间中的点云中计算出一个最优拟合圆,以及圆上的内外点。 以下是使用`pcl::SACMODEL_CIRCLE3D`模型拟合点云的步骤: 1. 加载点云数据,将其转换为`pcl::PointCloud<pcl::PointXYZ>`格式; 2. 创建一个`pcl::SACSegmentation<pcl::PointXYZ>`对象; 3. 设置模型类型为`pcl::SACMODEL_CIRCLE3D`; 4. 设置其他参数,例如最小拟合点数、迭代次数和距离阈值等; 5. 使用`pcl::ModelCoefficients`和`pcl::PointIndices`存储拟合结果; 6. 调用`pcl::SACSegmentation`对象的`segment`方法进行拟合; 7. 从结果中提取拟合的圆心和半径; 以下是代码示例: ```cpp pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::io::loadPCDFile<pcl::PointXYZ>("cloud.pcd", *cloud); pcl::SACSegmentation<pcl::PointXYZ> seg; seg.setOptimizeCoefficients(true); seg.setModelType(pcl::SACMODEL_CIRCLE3D); seg.setMethodType(pcl::SAC_RANSAC); seg.setDistanceThreshold(0.01); seg.setInputCloud(cloud); seg.setRadiusLimits(0, 0.1); pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients); pcl::PointIndices::Ptr inliers(new pcl::PointIndices); seg.segment(*inliers, *coefficients); Eigen::Vector3f center(coefficients->values, coefficients->values, coefficients->values); float radius = coefficients->values; std::cout << "Fitted circle center: " << center << std::endl; std::cout << "Fitted circle radius: " << radius << std::endl; ``` 其中,`cloud.pcd`是一个点云文件,包含需要拟合的点云数据。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值