问题
The function below produces no result. In other words, the number of points in point cloud is exactly the same as before down-sampling. I tried various numbers for leaf size from 0.01 all the way to the ones you see below but all of them produce the same result. I had to ticker with the conversions (as you see below) going from pcl::PointCloud<T>
to pcl::PCLPointCloud2
so I am suspecting that they might the problem here.
Please let me know if you had similar problem and solved it. Thank you.
typedef pcl::PointCloud<pcl::PointXYZ>::Ptr PointCloudPtr;
void PlantVis::downsample(PointCloudPtr cloud) {
pcl::PCLPointCloud2::Ptr cloud2(new pcl::PCLPointCloud2());
pcl::toPCLPointCloud2(*cloud, *cloud2);
pcl::PCLPointCloud2::Ptr cloud_filtered(new pcl::PCLPointCloud2());
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud(cloud2);
sor.setLeafSize(500000000.01f, 500000000.01f, 500000000.01f);
sor.filter(*cloud_filtered);
pcl::PointCloud<pcl::PointXYZ>::Ptr m_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromPCLPointCloud2(*cloud_filtered, *m_cloud);
cloud = m_cloud;
}
回答1:
Why do you need all of the conversion? Try this instead:
void PlantVis::downsample(PointCloudPtr cloud) {
PointCloudPtr output(new pcl::PointCloud<pcl::PointXYZ>);
pcl::VoxelGrid<pcl::PointXYZ> sor;
sor.setInputCloud(input_cloud);
sor.setLeafSize(0.001f, 0.001f, 0.001f);
sor.filter(*output);
//display or do something else with output
}
来源:https://stackoverflow.com/questions/43245726/pcl-downsample-with-pclvoxelgrid