从 pcl::PointCloud<pcl::PointXYZRGB> 中移除点

3

我是PCL的新手。我正在使用PCL库,并且正在寻找一种从点云中提取点或将特定点复制到新点云的方法。我想对每个点进行验证,以确定它是否符合条件,并且我想获得仅包含好点的点云。谢谢!


欢迎来到StackOverflow。请发布您已经尝试过的代码以及您遇到的具体问题所在。 - Gerriet
3个回答

22

使用ExtractIndices类:

  • 将要删除的点添加到PointIndices变量中
  • 将这些Indices传递给ExtractIndices
  • 以“否定”的方式运行filter()方法,以获得原始点云减去您的点

示例:

  pcl::PointCloud<pcl::PointXYZ>::Ptr p_obstacles(new pcl::PointCloud<pcl::PointXYZ>);
  pcl::PointIndices::Ptr inliers(new pcl::PointIndices());
  pcl::ExtractIndices<pcl::PointXYZ> extract;
  for (int i = 0; i < (*p_obstacles).size(); i++)
  {
    pcl::PointXYZ pt(p_obstacles->points[i].x, p_obstacles->points[i].y, p_obstacles->points[i].z);
    float zAvg = 0.5f;
    if (abs(pt.z - zAvg) < THRESHOLD) // e.g. remove all pts below zAvg
    {
      inliers->indices.push_back(i);
    }
  }
  extract.setInputCloud(p_obstacles);
  extract.setIndices(inliers);
  extract.setNegative(true);
  extract.filter(*p_obstacles);

0

只需使用PCL迭代器进行逐点操作,假设您想要在云中相对于z值进行操作,则可以执行以下操作;

for (pcl::PointCloud<pcl::PointXYZRGB>::iterator it = cloud_filtered->begin(); it != cloud_filtered->end(); it++) {
    if (it->z > 3.0) {
        cloud_filtered->erase(it);
    }
}

-2

问题在于每个点都有一个基于z坐标的不同条件。 - mrx
你的第二个链接返回了404错误。你有更新的链接吗? - Mason
1
链接失效,回答无帮助。 - user37309
更新了离群值教程的链接:https://pcl.readthedocs.io/projects/tutorials/en/latest/statistical_outlier.html - Peter Mitrano

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接