SACSegmentation检测奇数平面模型

时间:2017-03-16 21:30:56

标签: c++ 3d point-cloud-library point-clouds ransac

我试图将平面模型拟合到点云(具有类似平面的结构)。

我遇到的问题是拟合平面只是云的一小部分,即使距离阈值设置为相对较大的值。

以下是结果的一些图像:(白点是模型内点)

enter image description here

您可以看到云在这里有多薄:

enter image description here

enter image description here

我已经调整了SACSegmentation对象的各种参数,甚至尝试了PCL没有运气的多种RANSAC方法。

这是点云显示: https://drive.google.com/file/d/0B0PUIShwQuU7RmFKUW1Cd2V1Zk0/view?usp=sharing

以下是本教程后面的最小代码:

#include <iostream>
#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>


int
main(int argc, char** argv)
{
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
    pcl::io::loadPCDFile<pcl::PointXYZI>("test.pcd", *cloud); //* load the file

    pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
    pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
    // Create the segmentation object
    pcl::SACSegmentation<pcl::PointXYZI> seg;
    // Optional
    seg.setOptimizeCoefficients(true);
    // Mandatory
    seg.setModelType(pcl::SACMODEL_PLANE);
    seg.setMethodType(pcl::SAC_RANSAC);
    seg.setDistanceThreshold(0.025);

    seg.setInputCloud(cloud);
    seg.segment(*inliers, *coefficients);

    if (inliers->indices.size() == 0)
    {
        PCL_ERROR("Could not estimate a planar model for the given dataset.");
        return (-1);
    }

    std::cerr << "Model coefficients: " << coefficients->values[0] << " "
        << coefficients->values[1] << " "
        << coefficients->values[2] << " "
        << coefficients->values[3] << std::endl;

    //add points to plane that fit plane model
    pcl::PointCloud<pcl::PointXYZI>::Ptr output(new pcl::PointCloud<pcl::PointXYZI>);
    for (size_t i = 0; i < inliers->indices.size(); ++i)
    {
        output->push_back(cloud->points[inliers->indices[i]]);
    }

    displaySubcloud(cloud, output);
    displayPlane(cloud, coefficients, "plane");

    return (0);
}

1 个答案:

答案 0 :(得分:0)

我已经找到了解决方案,但我不知道为什么要修复它。通过将云移近原点,可以检测到正确的平面模型。