PCL 点云噪声去除:体素滤波和半径滤波实现
这段代码实现了一个点云噪声去除的函数,具体流程如下:
- 创建一个 VoxelGrid 对象
vg,用于进行体素滤波,简化计算。 - 创建一个空的
PointCloud<PointXYZRGB>指针对象cloud_Voxel,用于存放过滤后的数据。 - 将输入点云
noise_cloud设置为初始点云,并将体素栅格叶大小设置为 0.001。 - 调用
vg.filter(*cloud_Voxel)函数,将过滤后的数据存入cloud_Voxel中。 - 输出过滤后的数据点数。
- 创建一个
RadiusOutlierRemoval<PointXYZRGB>对象radius_fliter,用于进行半径滤波,移除离群点。 - 创建一个空的
PointCloud<PointXYZRGB>指针对象cloud_radius,用于存放半径滤波后的数据。 - 将输入点云设置为上一步中的
cloud_Voxel,并将半径和最小邻居点数分别设置为 0.03 和 100。 - 调用
radius_fliter.filter(*cloud_radius)函数,将半径滤波后的数据存入cloud_radius中。 - 输出半径滤波后的数据点数。
- 返回
cloud_radius指针对象。
PointCloud<PointXYZRGB>::Ptr Preprocessed::noise_removal(PointCloud<PointXYZRGB>::Ptr noise_cloud)
{
//noise removal函数的实现方法
//Voxel filtering, simplified calculation
VoxelGrid<pcl::PointXYZRGB> vg; //创建滤波对象vg
PointCloud<pcl::PointXYZRGB>::Ptr cloud_Voxel(new PointCloud<PointXYZRGB>); //创建一个空的指针对象存放过滤后的数据
vg.setInputCloud(noise_cloud); //设置输入点云为初始点云
float leaf = 0.001;
vg.setLeafSize(leaf, leaf, leaf); // setLeafSize (float lx, float ly, float lz) //setLeafSize后面的三个参数表示体素栅格叶大小,分别表示体素在XYZ方向的尺寸,以米为单位
vg.filter(*cloud_Voxel); //output
std::cout << "PointCloud after VoxelGrid filtering has: " << cloud_Voxel->points.size() << " data points." << std::endl;
std::cout << "--------------------------------------------------------------------------------------------- " << std::endl;
RadiusOutlierRemoval<PointXYZRGB> radius_fliter;
PointCloud<PointXYZRGB>::Ptr cloud_radius(new PointCloud<PointXYZRGB>);
radius_fliter.setInputCloud(cloud_Voxel);
radius_fliter.setRadiusSearch(0.03); // Set the radius to 0.03 m to find the nearest point
radius_fliter.setMinNeighborsInRadius(100); // Sets the number of neighbor point sets of the query point to less than 100 Delete
radius_fliter.filter(*cloud_radius);
cout << "PointCloud after RadiusOutlierRemoval has: " << cloud_radius->size() << " data points. " << endl;
return cloud_radius;
}
总之,该函数通过使用体素滤波和半径滤波算法,实现了点云噪声的去除,提高了点云数据的质量。
原文地址: https://www.cveoy.top/t/topic/nxvJ 著作权归作者所有。请勿转载和采集!