0

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 Answers1

1

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.

rooky
  • 76
  • 1
  • 7
  • 1
    I eventually ended up taking in PC data in such a way where the ground plane was always the biggest plane. I am not sure if your solution would have worked considering both the box plane and ground plane are perpendicular. – Atta Ur Rahman Mar 23 '23 at 11:55
  • Well, yes, if it works that's ok, but probably the best solution will be to combine them: take the biggest plane that is also perpendicular on the Y axis. The reason for this is that if your ground floor plane suffers from camera distortions (noise, multi-path interference etc.) then you might be tempted to set some more loose constraints on RANSAC which might result in labeling points from different planes as part of the same plane, but, of course, this is just if your point clouds are affected by such distortions. – rooky Mar 23 '23 at 14:02