PCL:访问 pcl::ModelCoefficients::Ptr 的字段以使用 RANSAC 进行线模型近似

PCL: Accessing fields of pcl::ModelCoefficients::Ptr for line model approximation using RANSAC

我正在尝试使用点云库提供的 RANSAC 方法估计通过点云点的线。 我可以创建对象,并毫无问题地估计线模型,如下所示:

pcl::PointCloud<pcl::PointXYZ>::ConstPtr source_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::ModelCoefficients::Ptr line_coefficients(new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers (new pcl::PointIndices);

// Populate point cloud...

// Create the segmentation object 
pcl::SACSegmentation<pcl::PointXYZ> seg;
seg.setModelType (pcl::SACMODEL_LINE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setDistanceThreshold (distance_thresh);
seg.setInputCloud (source_cloud); 
seg.segment (*inliers, *line_coefficients);

我现在尝试访问模型参数,但我太笨了,无法做到...根据 API 应该有六个可访问参数:

The six coefficients of the line are given by a point on the line and the direction of the line as: [point_on_line.x point_on_line.y point_on_line.z line_direction.x line_direction.y line_direction.z]

因此我尝试这样访问它们:

line_coefficients->line_direction->x

但是,这不起作用。我不断收到错误消息:

No member named 'line_direction' in in 'pcl::ModelCoefficients'.

我真的不知道我做错了什么...有人有什么想法吗? 提前致谢!

文档只是告诉您如何解释这些值。 pcl::ModelCoefficients 是一个结构,它有一个类型为 std::vector<float> 的成员 values

所以要得到 line_directionpoint_on_line 做:

const auto pt_line_x = line_coefficients->values[0];
const auto pt_line_y = line_coefficients->values[1];
const auto pt_line_z = line_coefficients->values[2];
const auto pt_direction_x = line_coefficients->values[3];
const auto pt_direction_y = line_coefficients->values[4];
const auto pt_direction_z = line_coefficients->values[5];