【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱: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. 行人识别学习资料整理2018
  2. securecrt7.0.0合并多个窗口
  3. 电子设计竞赛电源题(2)-检波与采样
  4. Java 面向对象的程序设计(二)
  5. 实现深拷贝的几种方法
  6. golang中package的4种导入方式
  7. hdu4521 小明系列的问题——小明序列(LIS变种 (段树+单点更新解决方案))
  8. 使用git建立本地仓储管理代码【转】
  9. android fragment实例化,Android使得Fragment 切换时不重新实例化
  10. 读了王兴一万条饭否,我想送你几十本《王兴的一万条饭否》
  11. lammps后处理:ovito选择原子高级技巧讲解
  12. linux注册浏览器协议,在Linux系统上安装Beaker浏览器的方法
  13. 大规模机器集群-单机/集群/服务/机房/从零恢复的快速交付
  14. android拓展内存卡,都取消存储卡拓展,而它却解决了安卓手机的大问题
  15. 你关心的2023年PMP的考试时间和地点在这里
  16. 台式机网线连接笔记本通过wifi上网
  17. 英语不好,能不能学软件编程?不懂英文能学编程吗
  18. 企业选择托管服务器的一些因素
  19. Alessandro De Luca 大神级任务广义动量应用于动力学解决方案
  20. chrome控制台如何把vw显示成px_罗技lua怎么做到在脚本控制台显示中文的? - 『悬赏问答区』 - 吾爱破解 - LCG...

热门文章

  1. 《Spring 3.0就这么简单》——1.5 业务层
  2. JAVA EE 开发中 常用的API包
  3. liveness 生存性/活性
  4. 表单的管理作业及答案
  5. ActiveMQ消息的持久化策略
  6. exc_bad_access(code=1, address=0x789870)野指针错误
  7. 窥探算法之美妙——寻找数组中最小的K个数python中巧用最大堆
  8. checkboxlist详细用法、checkboxlist用法、checkboxlist
  9. 实现qq邮箱换肤(第一季 )
  10. 为什么程序必须得会C语言?