Detection of ground plane using PCL library where I have other planes in the point cloud as well

788 Views Asked by At

I want to detect the ground plane in a point cloud which also has other planes. The other planes are from a box and have larger area which is why RANSAC is not removing the ground plane.

What I have done is use passthrough filter so I can remove the other planes by only using certain values of y coordinate (vertical) and then use RANSAC for removing the ground plane but now I am struggling with how to filter the ground plane points from the original point cloud. Any help would be appreciated as I am new to PCL, thanks.

Here is my code so far, in case it might help.

`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.setIndices(inliers);
  extract.setNegative(true);
  extract.filter(*cloud);

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

  return (0);`
1

There are 1 best solutions below

2
rooky On

If you are trying to extract the ground floor plane you could use pcl::SACMODEL_PERPENDICULAR_PLANE, as the ground floor should be perpendicular on the Y axis. Have a look at this code.