我正在接收ROS消息,类型为
sensor_msgs::PointCloud2ConstPtr在我的回调函数中,我将它转换为
pcl::PointCloud<pcl::PointXYZ>::Ptr使用函数
pcl::fromROSMsg.之后,使用pcl教程中的代码进行正常估计:
void OrganizedCloudToNormals(
const pcl::PointCloud<pcl::PointXYZ>::Ptr &_inputCloud,
pcl::PointCloud<pcl::PointNormal>::Ptr &cloud_normals
)
{
pcl::console::print_highlight ("Estimating scene normals...\n");
pcl::NormalEstimationOMP<pcl::PointXYZ,pcl::PointNormal> nest;
nest.setRadiusSearch (0.001);
nest.setInputCloud (_inputCloud);
nest.compute (*cloud_normals);
//write 0 wherever is NaN as value
for(int i=0; i < cloud_normals->points.size(); i++)
{
cloud_normals->points.at(i).normal_x = isnan(cloud_normals->points.at(i).normal_x) ? 0 : cloud_normals->points.at(i).normal_x;
cloud_normals->points.at(i).normal_y = isnan(cloud_normals->points.at(i).normal_y) ? 0 : cloud_normals->points.at(i).normal_y;
cloud_normals->points.at(i).normal_z = isnan(cloud_normals->points.at(i).normal_z) ? 0 : cloud_normals->points.at(i).normal_z;
cloud_normals->points.at(i).curvature = isnan(cloud_normals->points.at(i).curvature) ? 0 : cloud_normals->points.at(i).curvature;
}
}之后,我得到了pcl::PointNormal类型的点云,并尝试对其进行下采样
const float leaf = 0.001f; //0.005f;
pcl::VoxelGrid<pcl::PointNormal> gridScene;
gridScene.setLeafSize(leaf, leaf, leaf);
gridScene.setInputCloud(_scene);
gridScene.filter(*_scene);其中_scene的类型为
pcl::PointCloud<pcl::PointNormal>::Ptr _scene (new pcl::PointCloud<pcl::PointNormal>); 然后经过过滤,我最终得到了我的点云_scene,它里面只有一个点。我试着改变树叶的大小,但这并没有改变结果。
有人知道我做错了什么吗?
提前感谢
发布于 2020-07-07 16:52:37
我找到问题出在哪里了。类型pcl::PoinNormal有字段x,y,z,normal_x,normal_y和normal_z,但在我的函数OrganizedCloudToNormals中,我只填充了字段normal_x,normal_y和normal_z,字段x,y和z的每个点都有值0。当我从输入点云中填充字段x,y和z时,过滤(下采样)问题消失了,我已经过滤了内部超过1个点的云。在x,y和z字段中缺少值可能会导致稍后在体素网格对象的filter方法中出现问题。
https://stackoverflow.com/questions/62740730
复制相似问题