首页 > 其他分享 >3d激光雷达开发(圆柱分割)

3d激光雷达开发(圆柱分割)

时间:2022-11-23 23:00:51浏览次数:39  
标签:圆柱 cylinder seg 激光雷达 pcl PointCloud extract cloud 3d


        和平面分割一样,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 needed
pcl::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> ());

// Datasets
pcl::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 data
reader.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 background
pass.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 normals
ne.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 parameters
seg.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 coefficients
seg.segment (*inliers_plane, *coefficients_plane);
std::cerr << "Plane coefficients: " << *coefficients_plane << std::endl;

// Extract the planar inliers from the input cloud
extract.setInputCloud (cloud_filtered);
extract.setIndices (inliers_plane);
extract.setNegative (false);

// Write the planar inliers to disk
pcl::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 rest
extract.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 parameters
seg.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 coefficients
seg.segment (*inliers_cylinder, *coefficients_cylinder);
std::cerr << "Cylinder coefficients: " << *coefficients_cylinder << std::endl;

// Write the cylinder inliers to disk
extract.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工程,准备编译

3d激光雷达开发(圆柱分割)_#include

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

3d激光雷达开发(圆柱分割)_机器学习_02

  

标签:圆柱,cylinder,seg,激光雷达,pcl,PointCloud,extract,cloud,3d
From: https://blog.51cto.com/feixiaoxing/5881895

相关文章

  • 3d激光雷达开发(ndt匹配)
        除了icp匹配之外,ndt匹配也是使用比较多的一种方法。相比较icp而言,ndt匹配花的时间要少一些。此外,ndt匹配还需要输入估计的yaw、pitch、roll、x、y、z,这个可以根......
  • 3d激光雷达开发(icp匹配)
        所谓匹配,其实就是看两个点云数据里面,哪些关键点是一样的。这样就可以把一个点云移动到另外合适的位置,组成一个新的点云。一般来说,单个机器人上面,3d激光扫描到的......
  • ASW3642pin√pin替代TS3DV642无需更改电路
    TS3DV642是一种12通道1:2或2:1双向多路替代器/多路解复用器。TS3DV642接入2.6V至4.5V的电源供电,适用于电池供电。电阻(RON)最小和I/O电容较小,能够实现典型值高达7.5GHz的带宽......
  • 3DMAX2018安装
    1.下载3DMAX2018安装包并解压2.打开解压后的文件点击Setup选择语言和安装位置点击下一步安装完成后点击enteraserialnumber输入序列号066-66666666,密钥128J1后点......
  • 大咖说·先临三维|技术入云塑造3D视觉行业新模式
    高精度3D视觉技术主要的工作原理是什么?它的开发难度在哪里?数字化技术对其有何助力?本期大咖说,看先临三维副总裁兼研究院副院长江腾飞如何分享。嘉宾介绍江腾飞:先......
  • Matplotlib数据可视化——3D视图
    """绘制三维图形"""importnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3Dfig=plt.figure()ax=Axes3D(fig)X=np.ara......
  • Android实现3D页面加载进度条动画
    一.概述最近在研究公司的代码,发现每次切换页面时做的进度条效果还挺不错的,所以想深入研究一下,今天就带大家来看看到底是如何实现的,首先上效果图二.实现上面的进度条最大的......
  • 在博客园随笔中插入3D分子模型
    技术背景博主对前端技术不甚了解,只是想在博客中直接展示一些已有的分子结构,而且需要是可以交互的。而我们了解到通过3Dmol这样的前端工具可以实现,通过在博客园随笔中直接......
  • Cesium关于3Dtiles的细节分享
    介绍介绍一下Cesium中有关3dTiles的奇淫技巧,存在一些埋坑的地方,以下内容仅为自己摸索的细节和方法,仅供参考,若有更好的办法欢迎讨论通用快速获取feature中包含的属性信息......
  • 服饰3D柔性渲染调研及实践
    服饰3D柔性渲染调研及实践调研背景 当前全球服装制造的产业链中,我国的中小企业的难以参与到其中利润最高的环节比如产品的设计和研发,主要原因就是服装设计的难度......