gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 04:25:10 30 4
gpt4 key购买 nike

我正在尝试使用点云库提供的 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 是一个结构,它有一个成员 values类型 std::vector<float> .

因此,要获得 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];

关于c++ - PCL:使用 RANSAC 访问 pcl::ModelCoefficients::Ptr 的字段以进行线模型近似,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54494275/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com