点云数据经过pcl::VoxelGrid降采样滤波后,点云呈爆炸状

问题介绍

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::VoxelGrid降采样滤波后,点云呈爆炸状

 

问题分析

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

 

解决方案

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

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

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::VoxelGrid降采样滤波后,点云呈爆炸状

 

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

上一篇:2d lidar


下一篇:苹果或将为iPhone 13全系配备LiDAR