c++ - SACSegmentation检测奇平面模型

标签 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);
}

最佳答案

我已经找到了解决方案,但我不知道为什么它能解决这个问题。通过将云平移到更接近原点的位置,它能够检测到正确的平面模型。

关于c++ - SACSegmentation检测奇平面模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42845136/

相关文章:

linux - Linux 上的 OpenNI 示例

c++ - 动态数组释放(赋值运算符与复制构造函数)

matlab - 从视频重建 3D 轨迹(由单个相机拍摄)

Java 升级后 OSX 上的 JavaFX 渲染问题

c++ - PCL : Failed to find match for field 'rgba'

c++ - 这个预定义函数降低了我程序的性能

c++ - 字符串数组和指针

c++ map赋值给end()后,它仍然执行一次迭代

c++ - g++在进行复制初始化时找不到正确的复制构造函数

json - 创建 3d 模型并将它们转换为 WebGL 可用的形式 - 初学者指南?