PCL SACSegmentation - How to use setAxis and setEpsAngle

asked 2022-11-18 00:03:04 -0500

I am doing plane detection using pcl. And I wrote the following code because I want to pick up the plane that is perpendicular to the ground among the detected planes. However, when you run it, the vertical and non-perpendicular surfaces (such as the ground) are randomly output, and seg.setAxis(axis); does not work. Also, even if there is no seg.setAxis(axis); , the output result does not change. Do you know the solution?

Excerpt only where necessary

 const Eigen::Vector3f axis(0.0,1.0,0.0);

 pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud2(new pcl::PointCloud<pcl::PointXYZ>);
 pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud3(new pcl::PointCloud<pcl::PointXYZ>);
 sensor_msgs::PointCloud2::Ptr output_cloud(new sensor_msgs::PointCloud2);

  pcl::SACSegmentation<pcl::PointXYZ> seg;//
  pcl::ExtractIndices<pcl::PointXYZ> extr;//

  pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
  pcl::PointIndices::Ptr indices(new pcl::PointIndices);

  seg.setOptimizeCoefficients (true);
  seg.setModelType (pcl::SACMODEL_PERPENDICULARL_PLANE);
  seg.setMethodType (pcl::SAC_RANSAC);
  seg.setDistanceThreshold (0.1);
  seg.setInputCloud (filtered_cloud2);
  seg.segment (*indices, *coefficients);
  seg.setMaxIterations(100);
  seg.setProbability(0.95);
  seg.setAxis(axis);
  seg.setEpsAngle(30.0*(M_PI/180.0));
  extr.setInputCloud(filtered_cloud2);
  extr.setIndices(indices);
  extr.setNegative(false);
  extr.filter(*filtered_cloud3);

  pcl::toROSMsg(*filtered_cloud3, *output_cloud);
  points_pub.publish(*output_cloud);
edit retag flag offensive close merge delete