使用 PCL 库检测地平面,我在点云中也有其他平面

问题描述 投票:0回答:0

我想在也有其他平面的点云中检测地平面。其他平面来自盒子并且面积更大,这就是 RANSAC 不移除地平面的原因。

我所做的是使用 passthrough 过滤器,这样我就可以通过仅使用 y 坐标(垂直)的某些值来删除其他平面,然后使用 RANSAC 删除地平面,但现在我正在努力研究如何从中过滤地平面点原始点云。感谢任何帮助,因为我是 PCL 的新手。

到目前为止,这是我的代码,以防万一。

`pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
  
  pcl::PointIndicesPtr ground(new pcl::PointIndices);
  pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
  pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
  pcl::ExtractIndices<pcl::PointXYZ> extract;

  pcl::SACSegmentation<pcl::PointXYZ> seg;
  

  pcl::PassThrough<pcl::PointXYZ> pass;
  pass.setInputCloud (cloud);
  pass.setFilterFieldName ("y");
  pass.setFilterLimits (0.08, 0.5);
  //pass.setNegative (true);
  pass.filter (*cloud_filtered);



  seg.setOptimizeCoefficients(true);
  seg.setModelType(pcl::SACMODEL_PLANE);
  seg.setMethodType(pcl::SAC_RANSAC);
  seg.setDistanceThreshold(0.01);
  seg.setInputCloud(cloud_filtered);
  seg.segment(*inliers, *coefficients);

  extract.setInputCloud(cloud);
  extract.setCoefficients(coefficients);
  extract.setNegative(true);
  extract.filter(*cloud);

  pcl::io::savePCDFileASCII ("pcdout.pcd", *cloud);
 

  return (0);`
image-segmentation point-cloud-library point-clouds ransac pcl
© www.soinside.com 2019 - 2024. All rights reserved.