圆柱模型分割

该教程介绍了如何利用样本共识方法在Point Cloud Library (PCL)中对圆柱模型进行分割。首先,数据集经过预处理,过滤掉距离超过1.5米的点,并计算每个点的表面法线。接着,通过平面模型分割出桌子,然后对圆柱形模型(如杯子)进行分割并保存。实现步骤包括创建滤波器、估计法线、设定分割参数并提取模型。程序编译运行后,可以输出圆柱点云。
摘要由CSDN通过智能技术生成

本教程举例说明了如何为圆柱模型运行样本共识分割。为了使示例更实用,对输入数据集进行以下操作(按顺序):

  • 超过 1.5 米的数据点被过滤

  • 估计每个点的表面法线

  • 平面模型(描述我们演示数据集中的表)被分割并保存到磁盘

  • 一个圆柱形模型(描述我们演示数据集中的杯子)被分割并保存到磁盘

下载数据集 https://raw.github.com/PointCloudLibrary/data/master/tutorials/table_scene_mug_stereo_textured.pcd

创建cylinder_segmentation.cpp文件

源码:

  1#include <pcl/ModelCoefficients.h>
  2#include <pcl/io/pcd_io.h>
  3#include <pcl/point_types.h>
  4#include <pcl/filters/extract_indices.h>
  5#include <pcl/filters/passthrough.h>
  6#include <pcl/features/normal_3d.h>
  7#include <pcl/sample_consensus/method_types.h>
  8#include <pcl/sample_consensus/model_types.h>
  9#include <pcl/segmentation/sac_segmentation.h>
 10
 11typedef pcl::PointXYZ PointT;
 12
 13int
 14main ()
 15{
 16  // All the objects needed
 17  pcl::PCDReader reader;
 18  pcl::PassThrough<PointT> pass;
 19  pcl::NormalEstimation<PointT, pcl::Normal> ne;
 20  pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg; 
 21  pcl::PCDWriter writer;
 22  pcl::ExtractIndices<PointT> extract;
 23  pcl::ExtractIndices<pcl::Normal> extract_normals;
 24  pcl::search::KdTree<PointT>::Ptr tree (new pcl::search::KdTree<PointT> ());
 25
 26  // Datasets
 27  pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT>);
 28  pcl::PointCloud<PointT>::Ptr cloud_filtered (new pcl::PointCloud<PointT>);
 29  pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
 30  pcl::PointCloud<PointT>::Ptr cloud_filtered2 (new pcl::PointCloud<PointT>);
 31  pcl::PointCloud<pcl::Normal>::Ptr cloud_normals2 (new pcl::PointCloud<pcl::Normal>);
 32  pcl::ModelCoefficients::Ptr coefficients_plane (new pcl::ModelCoefficients), coefficients_cylinder (new pcl::ModelCoefficients);
 33  pcl::PointIndices::Ptr inliers_plane (new pcl::PointIndices), inliers_cylinder (new pcl::PointIndices);
 34
 35  // Read in the cloud data
 36  reader.read ("table_scene_mug_stereo_textured.pcd", *cloud);
 37  std::cerr << "PointCloud has: " << cloud->size () << " data points." << std::endl;
 38
 39  // Build a passthrough filter to remove spurious NaNs and scene background
 40  pass.setInputCloud (cloud);
 41  pass.setFilterFieldName ("z");
 42  pass.setFilterLimits (0, 1.5);
 43  pass.filter (*cloud_filtered)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

目标成为slam大神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值