我们这次将学着使用ExtractIndices滤波器来从一个分割算法中导出点的下标。为了不把这个项目复杂化,我们不会在这里解释分割算法。

我们先建一个extract_indices.cpp

代码

#include <iostream>
#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.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/filters/voxel_grid.h>
#include <pcl/filters/extract_indices.h>
int
main (int argc, char** argv)
{pcl::PCLPointCloud2::Ptr cloud_blob (new pcl::PCLPointCloud2), cloud_filtered_blob (new pcl::PCLPointCloud2);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>), cloud_p (new pcl::PointCloud<pcl::PointXYZ>), cloud_f (new pcl::PointCloud<pcl::PointXYZ>);
// Fill in the cloud data
pcl::PCDReader reader;
reader.read ("table_scene_lms400.pcd", *cloud_blob);
std::cerr << "PointCloud before filtering: " << cloud_blob->width * cloud_blob->height << " data points." << std::endl;
// Create the filtering object: downsample the dataset using a leaf size of 1cm
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud (cloud_blob);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*cloud_filtered_blob);
// Convert to the templated PointCloud
pcl::fromPCLPointCloud2 (*cloud_filtered_blob, *cloud_filtered);
std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height << " data points." << std::endl;
// Write the downsampled version to disk
pcl::PCDWriter writer;
writer.write<pcl::PointXYZ> ("table_scene_lms400_downsampled.pcd", *cloud_filtered, false);
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
// Create the segmentation object
pcl::SACSegmentation<pcl::PointXYZ> seg;
// Optional
seg.setOptimizeCoefficients (true);
// Mandatory
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setMaxIterations (1000);
seg.setDistanceThreshold (0.01);
// Create the filtering object
pcl::ExtractIndices<pcl::PointXYZ> extract;
int i = 0, nr_points = (int) cloud_filtered->points.size ();
// While 30% of the original cloud is still there
while (cloud_filtered->points.size () > 0.3 * nr_points)
{// Segment the largest planar component from the remaining cloud
seg.setInputCloud (cloud_filtered);
seg.segment (*inliers, *coefficients);
if (inliers->indices.size () == 0)
{std::cerr << "Could not estimate a planar model for the given dataset." << std::endl;
break;
}
// Extract the inliers
extract.setInputCloud (cloud_filtered);
extract.setIndices (inliers);
extract.setNegative (false);
extract.filter (*cloud_p);
std::cerr << "PointCloud representing the planar component: " << cloud_p->width * cloud_p->height << " data points." << std::endl;
std::stringstream ss;
ss << "table_scene_lms400_plane_" << i << ".pcd";
writer.write<pcl::PointXYZ> (ss.str (), *cloud_p, false);
// Create the filtering object
extract.setNegative (true);
extract.filter (*cloud_f);
cloud_filtered.swap (cloud_f);
i++;
}
return (0);

代码解释

首先我们用体元栅格滤波器来对数据进行降低采样。在这里,更少的点意味着花费更少的时间进行计算。

  pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud (cloud_blob);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*cloud_filtered_blob);

下一个代码块将处理参数分割。

  pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
// Create the segmentation object
pcl::SACSegmentation<pcl::PointXYZ> seg;
// Optional
seg.setOptimizeCoefficients (true);
// Mandatory
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setMaxIterations (1000);
seg.setDistanceThreshold (0.01);

下面这行

 pcl::ExtractIndices<pcl::PointXYZ> extract;

    extract.setInputCloud (cloud_filtered);
extract.setIndices (inliers);
extract.setNegative (false);
extract.filter (*cloud_p);

代表了导出的滤波器后的真实的下标。为了处理多个模型,我们把这个教程在一个循环中进行处理,对于每一个被导出的模型,我们返回去获取指定的点,并且进行迭代,inliers(正常的好的点云)这个将在分割处理后获取。

运行结果

PointCloud before filtering: 460400 data points.
PointCloud after filtering: 41049 data points.
PointCloud representing the planar component: 20164 data points.
PointCloud representing the planar component: 12129 data points.

pcl从一个点云里面导出下标相关推荐

  1. QT+PCL+VTK 一个点云显示和处理软件

    今晚是201809月的一天,我刚开完一个很长的讨论会,会后做了一个ppt(因为明天上午还有讨论会,要发言),于是乎我开始对一个说长不长说短不短的时间里完成的工作进行了一个总结(也只做了两页ppt),相 ...

  2. PCL提取3D点云模型特征(1.0 点云曲率)

    一.随便扯扯的概述 在进入到计算机图形学的研究中已经过去了好几个月了,自然免不了要跟PCL打交道.在学习PCL的过程中,越来越觉得PCL真的是个非常强大的工具,让人爱不释手,但同时也让人感到沮丧,因为 ...

  3. arcengine遍历属性表_【程序之坑】小程序云开发导出数据到excel表

    本文解决了小程序云开发导出数据到excel的bug,并给出了分析的过程,同时简化了程序为一个云函数,一个本地函数,逻辑更简单.文章结尾给出了完整源代码 小程序云开发为没有服务器的小程序开发者提供了便利 ...

  4. 锤子手机便签导入另一个手机云便签中怎么操作?

    锤子手机便签导入另一个手机云便签中怎么操作? 由于锤子手机自带的便签内容不支持授权一键批量导出到第三方软件中,所以锤子手机便签内容需要手动导入到敬业签云便签中,可参考以下方法进行操作: 一.锤子手机便 ...

  5. PCL中3D点云特征描述与提取(三)

    PCL中3D点云特征描述与提取(三) 1 如何从一个深度图像中提取NARF特征 2 RoPs特征 2.1 理论基础 2.1.1 生物视觉认知学启示 2.1.2 局部参考坐标框架构建 2.1.3 RoP ...

  6. 点云库PCL学习笔记 -- 点云滤波Filtering -- 3. StatisticalOutlierRemoval 统计滤波器

    点云库PCL学习笔记 -- 点云滤波Filtering -- 3.StatisticalOutlierRemoval 统计滤波器 StatisticalOutlierRemoval 统计滤波器相关简介 ...

  7. ​QGIS Cloud 一个基于云的 GIS 平台

    地理信息系统云 QGIS Cloud 是一个基于云的 GIS 平台,允许用户创建.编辑.共享和发布地理空间数据和地图.它建立在开源 QGIS 软件之上,提供了一个用户友好的界面来管理地理空间数据. 优 ...

  8. PCL提取3D点云模型特征(3.0 FPFH快速点特征直方图)附完整代码

    一.概述 上一篇博客解释了PFH是什么以及如何利用PFH来提取点云的特征,那么讲了PFH(PCL提取3D点云模型特征(2.0 PFH点特征直方图 )附完整代码)之后肯定是要接着说FPFH的.本来想着把 ...

  9. PCL:激光点云车道线检测及最小二乘法拟合

    PCL:激光点云车道线检测及最小二乘法拟合 数学部分 代码实现 目前已经将车道线的最小二乘拟合及配合rviz可视化实现了. 数学部分 补充:拟合的数学模型是直线一般式 当x1≠x2,y1≠y2时,直线 ...

最新文章

  1. Linux之链接命令
  2. windows api中文文档_Web服务开发:Spring集成Swagger,3步自动生成API文档
  3. Runner站立会议08
  4. (Java)ArrayList集合
  5. matlab调用Java程序时出现 Java.lang.OutOfMemoryErrot: GC overhead limit exceeded
  6. Linux下配置CollabNet Subversion Edge
  7. 我的linux复习之一密码修改
  8. 117 Python程序中的线程操作-开启多线程(threading.Thread)
  9. (转)老男孩教育每日一题-汇总博客
  10. 管家婆云辉煌的打印样式设置
  11. 激进投资者卡尔·伊坎辞去雅虎董事职务(每日关注,10月24日)
  12. 碳带与标签匹配规则及效果测试
  13. 用docker安装tomcat并实现目录映射端口映射输入ip地址测试网页连接
  14. 马桶品牌十大排名榜2022 马桶什么牌子好又实惠
  15. 论文阅读:(NFM)Neural Factorization Machines for Sparse Predictive Analytics
  16. 进程三态与五态是什么?
  17. Bootstrap 组件 Button 按钮
  18. 【Typora】 自定义背景颜色(护眼绿) 高亮颜色 选中内容颜色 高亮快捷键
  19. 腾讯技术专家解读《FinOps,从上云到上好云》
  20. java ssm分公司分销商管理系统

热门文章

  1. JS监听DOM宽高的变化
  2. MyBatis-Plus——增删查改
  3. Bugzilla 使用指南
  4. matlab 粘连分割代码,【求助】图像中粘连字符切分代码,求注释!!!
  5. Vue 组件的自定义事件
  6. dijkstra算法_最短路径问题——迪杰斯特拉算法(Dijkstra)
  7. Git初学札记(五)————Branch分支管理
  8. LeetCode算法入门- Remove Element -day20
  9. 中fuse_保险丝座中保险丝的材质,结构,接线方式以及区别的介绍
  10. win8 mysql6_Win8系统 MySQL 6.0 安装图解