问题介绍

slam构建地图,先进行降采样,再进行可视化或存储。然而经过降采样后,代码没有报错的情况下,点云数据散成一团。将代码和点云数据展示如下,

pcl::VoxelGrid<Lidar::PointType> voxel_filter;
voxel_filter.setLeafSize(0.02, 0.02, 0.02);

Lidar::PointCloudPtr mapPointCloud(new Lidar::PointCloudType); //滤波器输入变量
//...
//往输入变量中填充数据
//...

voxel_filter.setInputCloud(mapPointCloud);
voxel_filter.filter(*mapPointCloud);
std::cout << "after voxel_filter, mapPointCloud size : " << mapPointCloud->points.size() << std::endl;
std::string index = std::to_string(ndtCount);
pcl::io::savePCDFileASCII ("/home/gordon/fase_ws/src/ddd_wall_mapping/filter_map_"+index+".pcd",
                               *mapPointCloud);

PCL智能指针疑云 <二> 使用同一智能指针作为PCL预处理API的输入和输出

 

问题分析

猜想是由于降采样滤波器的输入和输出是同一个指针变量,在处理过程中内存混乱,导致点云数据出错。

 

解决方案

使用两个不同的变量作为降采样滤波器的输入和输出,并且作为输出的变量每次都要进行清空操作。

问题解决后的代码和点云数据展示如下,

pcl::VoxelGrid<Lidar::PointType> voxel_filter;
voxel_filter.setLeafSize(0.02, 0.02, 0.02);

Lidar::PointCloudPtr mapPointCloud(new Lidar::PointCloudType); //滤波器输入变量
//...
//往输入变量中填充数据
//...

Lidar::PointCloudPtr filter_mapPointCloud(new Lidar::PointCloudType); // 滤波器输出变量
voxel_filter.setInputCloud(mapPointCloud);
voxel_filter.filter(*filter_mapPointCloud);
mapPointCloud->clear();
*mapPointCloud += *filter_mapPointCloud;
std::cout << "after voxel_filter, mapPointCloud size : " << mapPointCloud->points.size() << std::endl;
std::string index = std::to_string(ndtCount);
pcl::io::savePCDFileASCII ("/home/gordon/fase_ws/src/ddd_wall_mapping/filter_map_"+index+".pcd", *mapPointCloud);

 

PCL智能指针疑云 <二> 使用同一智能指针作为PCL预处理API的输入和输出

 

至于具体原因,至今不详,忘高手或前辈指点迷津。 

相关文章:

  • 2021-09-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案