PCL downsample with pcl::VoxelGrid

陌路散爱 提交于 2019-12-13 00:22:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!