1 区别
1.1 原理
- VoxelGrid体素采样,对点云进行体素化,创建一个三维体素栅格。在每个体素里面,求取该立方体内的所有点云重心点来代表这个立方体的表示,以此达到下采样的目的。
- ApproximateVoxelGrid体素采样,对点云用每个体素栅格的中心点来近似该体素内的点,提升了速度,但是也损失了原始点云的局部形态精细度。
1.2 引用
- 1、VoxelGrid体素采样引入头文件:
include
ApproximateVoxelGrid体素采样引入头文件:
include
2常用函数
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:c983340c-6ee9-4764-b60b-3e17344823f5
[En]
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:21e7fb7a-894a-4910-9147-2319200d8946
- void pcl::VoxelGrid< PointT >::filter (PointCloud & output )
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:98da2f6b-a9f8-493f-b4c4-43e765f7446c[En]
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:86b33626-7236-4f8b-b3a4-676572905d9c
pcl::VoxelGrid<pcl::PointXYZ> sor; sor.setInputCloud(cloud); sor.filter(*cloud_filter);
- void pcl::VoxelGrid< PointT >::setDownsampleAllData (bool downsample)
功能:如果所有字段都需要采样,则设为true,如果只有XYZ则设为false。
pcl::VoxelGrid<pcl::PointXYZ> sor; sor.setInputCloud(cloud); sor.setDownsampleAllData(1); sor.filter(*cloud_filter);
- void pcl::VoxelGrid< PointT >::setLeafSize (float lx,float ly,float lz )
功能:设置体素大小。
pcl::VoxelGrid<pcl::PointXYZ> sor; sor.setInputCloud(cloud); sor.setDownsampleAllData(1); sor.setLeafSize(0.01f, 0.01f, 0.01f); sor.filter(*cloud_filter);
效果:
1、setLeafSize(0.005f, 0.005f, 0.005f)
2、setLeafSize(0.05f, 0.05f, 0.05f)
- void pcl::VoxelGrid< PointT >::setMinimumPointsNumberPerVoxel (unsigned int min_points_per_voxel)
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:bd9bdda8-0a62-409c-98b3-e561d020313b[En]
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:0b9d7438-6882-41b2-acfb-6dfe40622c54
pcl::VoxelGrid<pcl::PointXYZ> sor; sor.setInputCloud(cloud); sor.setDownsampleAllData(1); sor.setLeafSize(0.01f, 0.01f, 0.01f); sor.setMinimumPointsNumberPerVoxel(5); sor.filter(*cloud_filter);
效果:
3最后奉上代码
#include
#include
#include
#include
#include
#include
int main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filter(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCDReader reader;
reader.read<pcl::PointXYZ>("20201216-14-56-26_sor.pcd", *cloud);
std::cerr << "Cloud before filtering: " << std::endl;
std::cerr << *cloud << std::endl;
pcl::visualization::PCLVisualizer viewer("滤波");
int v1(0);
int v2(1);
viewer.createViewPort(0.0, 0.0, 0.5, 1, v1);
viewer.setBackgroundColor(1, 1, 1, v1);
viewer.createViewPort(0.5, 0.0, 1, 1, v2);
viewer.setBackgroundColor(1, 1, 1, v2);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> cloud_out_green(cloud, 255, 20, 147);
viewer.addPointCloud(cloud, cloud_out_green, "cloud_out1", v1);
pcl::VoxelGrid<pcl::PointXYZ> sor;
sor.setInputCloud(cloud);
sor.setDownsampleAllData(1);
sor.setLeafSize(0.01f, 0.01f, 0.01f);
sor.setMinimumPointsNumberPerVoxel(5);
sor.filter(*cloud_filter);
std::cerr << "Cloud after filtering: " << *cloud_filter << std::endl;
pcl::PCDWriter writer;
writer.write<pcl::PointXYZ> ("20201216-14-56-26_vox.pcd", *cloud_filter, false);
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> cloud_out_orage(cloud_filter, 122, 103, 238);
viewer.addPointCloud(cloud_filter, cloud_out_orage, "cloud_out2", v2);
while (!viewer.wasStopped())
{
viewer.spinOnce();
}
return 0;
}
Original: https://blog.csdn.net/qq_42827488/article/details/112545023
Author: 二更鼓响
Title: PCL(5)点云聚类 之 VoxelGrid体素采样与ApproximateVoxelGrid体素采样
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/561482/
转载文章受原作者版权保护。转载请注明原作者出处!