关于pcl中ransac算法识别直线时报错error segmenting the model! no solution found

在使用ransac算法识别直线时,当代码如下时不能正常识别,会报错“error segmenting the model! no solution found”“no samples could be selected!”
代码如下

for (unsigned int i = 0; i < n; ++i)
    {
        fscanf(fp_1, "%lf %lf %lf", &x, &y, &z);
        //x = x * 1000; y = y * 1000; z = z * 1000;
        cloud_ptr->push_back(pcl::PointXYZ(0, y, z));
        boundary.push_back(osg::Vec2(y, z));
    }

    pcl::ModelCoefficients::Ptr coefficients_line(new pcl::ModelCoefficients);
    pcl::PointIndices::Ptr inliers_line(new pcl::PointIndices);
    pcl::SACSegmentation<pcl::PointXYZ> seg;//ransac进行直线识别
    seg.setOptimizeCoefficients(true);
    seg.setModelType(pcl::SACMODEL_LINE);
    seg.setMethodType(pcl::SAC_RANSAC);
    seg.setMaxIterations(100);
    seg.setDistanceThreshold(1);
    seg.setInputCloud(cloud_ptr);
    seg.segment(*inliers_line, *coefficients_line);

但当把cloud_ptr->push_back那一栏的代码修改后,代码如下,便可以正常识别

for (unsigned int i = 0; i < n; ++i)
    {
        fscanf(fp_1, "%lf %lf %lf", &x, &y, &z);
        //x = x * 1000; y = y * 1000; z = z * 1000;
        /*cloud_ptr->push_back(pcl::PointXYZ(0, y, z));*/
        if (i%2==0)
        {
            cloud_ptr->push_back(pcl::PointXYZ(0, y, z));
        }
        else
        {
            cloud_ptr->push_back(pcl::PointXYZ(0.002, y, z));
        }
        boundary.push_back(osg::Vec2(y, z));
    }

    pcl::ModelCoefficients::Ptr coefficients_line(new pcl::ModelCoefficients);
    pcl::PointIndices::Ptr inliers_line(new pcl::PointIndices);
    pcl::SACSegmentation<pcl::PointXYZ> seg;//ransac进行直线识别
    seg.setOptimizeCoefficients(true);
    seg.setModelType(pcl::SACMODEL_LINE);
    seg.setMethodType(pcl::SAC_RANSAC);
    seg.setMaxIterations(100);
    seg.setDistanceThreshold(1);
    seg.setInputCloud(cloud_ptr);
    seg.segment(*inliers_line, *coefficients_line);

区别就是让x的这维坐标不再是恒定的,便可以正常识别了,为什么会出现这种情况,求解惑

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问