我正在尝试使用点云库提供的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,应该有六个可访问参数:
因此,我试图这样访问它们:
line_coefficients->line_direction->x
但是,这不起作用。我不断收到错误:
我真的不知道我在做什么错...有人有任何想法吗?
提前致谢!
最佳答案
该文档只是告诉您如何解释这些值。 pcl::ModelCoefficients
是具有values
类型的成员std::vector<float>
的结构。
因此,要获取 line_direction 和 point_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];