After pcl::VoxelGrid downsampling and filtering, the point cloud is explosive

Keywords: PHP PCL

Question introduction:

slam builds the map, first reduces the line sampling, then carries on the visualization or the storage. However, after downsampling, the point cloud data is scattered into a mass without error. Show the code and point cloud data as follows,

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

Lidar::PointCloudPtr mapPointCloud(new Lidar::PointCloudType); //Filter input variable
//...
//Fill data into input variables
//...

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);

 

Problem analysis:

The conjecture is that the input and output of the downsampling filter are the same pointer variables, and the memory is confused in the process of processing, resulting in the error of the point cloud data.

 

Solution:

Two different variables are used as the input and output of the downsampling filter, and the variables as the output are cleared every time.

After the problem is solved, the code and point cloud data are shown as follows,

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

Lidar::PointCloudPtr mapPointCloud(new Lidar::PointCloudType); //Filter input variable
//...
//Fill data into input variables
//...

Lidar::PointCloudPtr filter_mapPointCloud(new Lidar::PointCloudType); // Filter output variable
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);

 

 

As for the specific reason, it's not known until now. Forget the master or the elder's guidance.  

Posted by trystan on Sun, 03 Nov 2019 09:09:05 -0800