通常情况下,当PCL执行基于地面的RGBD检测时,可以使用以下示例代码:
pcl::PointCloudpcl::PointXYZ::Ptr cloud(new pcl::PointCloudpcl::PointXYZ);
pcl::PointCloudpcl::PointXYZ::Ptr cloud_filtered(new pcl::PointCloudpcl::PointXYZ);
// ... 读取或生成点云数据
pcl::PassThroughpcl::PointXYZ pass;
pass.setInputCloud(cloud);
pass.setFilterFieldName("z");
pass.setFilterLimits(0.0, 1.0);
pass.filter(*cloud_filtered);
pcl::GroundPlaneDetectionpcl::PointXYZ gp;
gp.setInputCloud(cloud_filtered);
gp.setMinPlaneSize(0.2);
gp.setDetectDistance(true);
gp.setDistanceThreshold(0.05);
gp.setMaxAngle(45.0);
gp.setAngularThreshold(0.02);
gp.setCurvatureThreshold(1.0);
gp.setMinClusterSize(10);
gp.setRefineModel(false);
gp.segment();
// .. 执行进一步的处理
然而,有时在执行gp.segment()时会出现std::length错误。这是由于在以上代码示例中,没有指定gp.setInputNormals()。解决此问题的方法是在gp.setInputCloud(cloud_filtered)之后添加以下代码:
pcl::PointCloudpcl::Normal::Ptr normals(new pcl::PointCloudpcl::Normal);
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normalEstimator;
normalEstimator.setInputCloud(cloud_filtered);
normalEstimator.setRadiusSearch(0.03);
normalEstimator.compute(*normals);
gp.setInputNormals(normals);
执行这些步骤后,PCL基于地面的RGBD检测功能应该可以正常工作了。