【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】

和平面分割一样,pcl也支持圆柱分割。使用的方法和平面分割也差不多,都是基于ransac的基本原理。在pcl官方库当中,也给出了参考代码,注意关联的pcd文件,https://pcl.readthedocs.io/projects/tutorials/en/master/cylinder_segmentation.html#cylinder-segmentation

1、准备cylinder_segmentation.cpp文件

#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/passthrough.h>
#include <pcl/features/normal_3d.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>typedef pcl::PointXYZ PointT;int
main ()
{// All the objects neededpcl::PCDReader reader;pcl::PassThrough<PointT> pass;pcl::NormalEstimation<PointT, pcl::Normal> ne;pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg; pcl::PCDWriter writer;pcl::ExtractIndices<PointT> extract;pcl::ExtractIndices<pcl::Normal> extract_normals;pcl::search::KdTree<PointT>::Ptr tree (new pcl::search::KdTree<PointT> ());// Datasetspcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT>);pcl::PointCloud<PointT>::Ptr cloud_filtered (new pcl::PointCloud<PointT>);pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);pcl::PointCloud<PointT>::Ptr cloud_filtered2 (new pcl::PointCloud<PointT>);pcl::PointCloud<pcl::Normal>::Ptr cloud_normals2 (new pcl::PointCloud<pcl::Normal>);pcl::ModelCoefficients::Ptr coefficients_plane (new pcl::ModelCoefficients), coefficients_cylinder (new pcl::ModelCoefficients);pcl::PointIndices::Ptr inliers_plane (new pcl::PointIndices), inliers_cylinder (new pcl::PointIndices);// Read in the cloud datareader.read ("table_scene_mug_stereo_textured.pcd", *cloud);std::cerr << "PointCloud has: " << cloud->size () << " data points." << std::endl;// Build a passthrough filter to remove spurious NaNs and scene backgroundpass.setInputCloud (cloud);pass.setFilterFieldName ("z");pass.setFilterLimits (0, 1.5);pass.filter (*cloud_filtered);std::cerr << "PointCloud after filtering has: " << cloud_filtered->size () << " data points." << std::endl;// Estimate point normalsne.setSearchMethod (tree);ne.setInputCloud (cloud_filtered);ne.setKSearch (50);ne.compute (*cloud_normals);// Create the segmentation object for the planar model and set all the parametersseg.setOptimizeCoefficients (true);seg.setModelType (pcl::SACMODEL_NORMAL_PLANE);seg.setNormalDistanceWeight (0.1);seg.setMethodType (pcl::SAC_RANSAC);seg.setMaxIterations (100);seg.setDistanceThreshold (0.03);seg.setInputCloud (cloud_filtered);seg.setInputNormals (cloud_normals);// Obtain the plane inliers and coefficientsseg.segment (*inliers_plane, *coefficients_plane);std::cerr << "Plane coefficients: " << *coefficients_plane << std::endl;// Extract the planar inliers from the input cloudextract.setInputCloud (cloud_filtered);extract.setIndices (inliers_plane);extract.setNegative (false);// Write the planar inliers to diskpcl::PointCloud<PointT>::Ptr cloud_plane (new pcl::PointCloud<PointT> ());extract.filter (*cloud_plane);std::cerr << "PointCloud representing the planar component: " << cloud_plane->size () << " data points." << std::endl;writer.write ("table_scene_mug_stereo_textured_plane.pcd", *cloud_plane, false);// Remove the planar inliers, extract the restextract.setNegative (true);extract.filter (*cloud_filtered2);extract_normals.setNegative (true);extract_normals.setInputCloud (cloud_normals);extract_normals.setIndices (inliers_plane);extract_normals.filter (*cloud_normals2);// Create the segmentation object for cylinder segmentation and set all the parametersseg.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 coefficientsseg.segment (*inliers_cylinder, *coefficients_cylinder);std::cerr << "Cylinder coefficients: " << *coefficients_cylinder << std::endl;// Write the cylinder inliers to diskextract.setInputCloud (cloud_filtered2);extract.setIndices (inliers_cylinder);extract.setNegative (false);pcl::PointCloud<PointT>::Ptr cloud_cylinder (new pcl::PointCloud<PointT> ());extract.filter (*cloud_cylinder);if (cloud_cylinder->points.empty ()) std::cerr << "Can't find the cylindrical component." << std::endl;else{std::cerr << "PointCloud representing the cylindrical component: " << cloud_cylinder->size () << " data points." << std::endl;writer.write ("table_scene_mug_stereo_textured_cylinder.pcd", *cloud_cylinder, false);}return (0);
}

2、代码分析

代码的整个流程大体可以分成两个部分,第一个部分是提取平面,第二个部分是提取圆柱。

3、准备CMakeLists.txt

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(cylinder_segmentation)find_package(PCL 1.2 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable (cylinder_segmentation cylinder_segmentation.cpp)
target_link_libraries (cylinder_segmentation ${PCL_LIBRARIES})

4、生成sln工程,准备编译

5、运行exe文件,注意差别

3d激光雷达开发(圆柱分割)相关推荐

  1. 3d激光雷达开发(入门)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 大约在2017年的时候,学习百度的apollo系统的时候,就知道3d激光雷达了.3d激光雷达和普 ...

  2. 3d激光雷达开发(ransac的思想)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 前面我们写了平面分割(https://blog.csdn.net/feixiaoxing/art ...

  3. 3d激光雷达开发(pcl安装和使用)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 之前讨论过,目前3d激光雷达这块,算法部分用的最多的就是pcl库.网上很多教程都是讲pcl在li ...

  4. 3d激光雷达开发(平面分割)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 平面分割是点云数据经常需要处理的一个功能.在很多场景下面,平面数据都是没有用的.这个时候需要考虑 ...

  5. 3d激光雷达开发(从halcon看点云pcl库)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 做点云开发的,很少有不知道pcl库的,这一点就有点像做数字图像处理的,很少有不知道opencv的 ...

  6. 3d激光雷达开发(平面映射)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 3d点云当中,一个经常用到的方法就是先找到一个平面,然后将点映射到平面上面.这个里面用到的数据结 ...

  7. 3d激光雷达开发(多雷达标定)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 有过camera开发经验的朋友都知道,camera有两种标定.一种是内参标定,主要是标定切向畸变 ...

  8. 3d激光雷达开发(ndt匹配)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 除了icp匹配之外,ndt匹配也是使用比较多的一种方法.相比较icp而言,ndt匹配花的时间要少 ...

  9. 3d激光雷达开发(icp匹配)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 所谓匹配,其实就是看两个点云数据里面,哪些关键点是一样的.这样就可以把一个点云移动到另外合适的位 ...

最新文章

  1. 理论应用实例水杯_PID理解起来很难?系统讲解PID控制及参数调节,理论加实际才好...
  2. winform list集合怎么 in过滤_python3基础04字典(dict)和集合(set)
  3. 03_Android项目中读写文本文件的代码
  4. 告别2019,写给2020:干好技术,要把握好时光里的每一步
  5. ASP.NET Core文件上传、下载与删除
  6. 通过扩展方法,将C#的DateTime(日期)转换成人性化的显示
  7. prototype.js1.5平面结果导读图
  8. 一步一步搭建客服系统 (7) 多人共享的电子白板、画板
  9. 产品和运营的区别是什么?
  10. 【ambari】Ambari Rest api 使用
  11. 如果$.ajax函数迟迟得不到响应,那么最有可能出错的地方是请求参数写错了
  12. 计算机组成原理课设参考文献,计算机组成原理课程设计(全)..doc
  13. Django:(02)项目配置
  14. hdu 1061 Rightmost Digit解题报告
  15. windows7下redis的安装实践
  16. xampp的安装及使用
  17. undi是什么意思_undefined是什么意思
  18. php doc生成pdf文件怎么打开乱码,phpexcel 导出pdf文件乱码,该如何解决
  19. openEuler Summit | 胡欣蔚:全场景欧拉 – 志之所趋,无远弗届
  20. Tesseract-Ocr图片内容识别

热门文章

  1. request_irq与request_threaded_irq
  2. 2017-07-22 模拟赛
  3. java基础----变量与常量+作用域
  4. StateListDrawable 动态更换背景
  5. 第 19 章 保护方法调用
  6. 波形捕捉:(8)使用“捕捉缓冲区”
  7. linux --- 部署前后端分离项目
  8. 洛谷P4482 [BJWC2018]Border 的四种求法 字符串,SAM,线段树合并,线段树,树链剖分,DSU on Tree...
  9. 简单的进度条拖动效果及拖拽改变层大小
  10. centos6 下用yum 安装 nginx