首页 > 解决方案 > 当我尝试进行平面模型分割时,pcl 代码中的“分割错误(核心转储)”

问题描述

当我尝试使用 pcl 进行平面模型分割时,出现“分割错误(核心转储)”。

这是一个在 ubuntu16.04、CMake、pcl-1.8 中运行的 .cpp 文件,

    #include <pcl-1.8/pcl/filters/extract_indices.h>
    #include <pcl-1.8/pcl/filters/impl/extract_indices.hpp>
    #include <pcl-1.8/pcl/segmentation/sac_segmentation.h>
    #include <pcl-1.8/pcl/segmentation/impl/sac_segmentation.hpp>

    PCL_INSTANTIATE(SacSegmentationExtraction, PointXYZIT);

    void remove_wake(pcl::PointCloud<PointXYZIT>::Ptr in_filtered, pcl::PointCloud<PointXYZIT>::Ptr out_filtered)
    {
      pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
      pcl::PointIndices::Ptr inliers (new pcl::PointIndices);

      pcl::SACSegmentation<PointXYZIT> seg;
      seg.setOptimizeCoefficients (true);
      seg.setModelType (pcl::SACMODEL_PLANE);
      seg.setMethodType (pcl::SAC_RANSAC);

      seg.setDistanceThreshold (0.2);
      seg.setInputCloud (in_filtered);
      seg.segment (*inliers, *coefficients);

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

      std::cerr << "Model inliers: " << inliers->indices.size () << std::endl;


      pcl::ExtractIndices<PointXYZIT> extract;
      extract.setInputCloud (in_filtered);
      extract.setIndices (inliers); 
      extract.setNegative (true);
      extract.filter (*out_filtered);
      pcl::io::savePCDFileASCII<PointXYZIT>("remove_plane.pcd", *out_filtered);
    }

这就是整个代码,当我 catkin_make 时它会好的,但是当我 rosrun 时,它显示错误:分段错误(核心转储)我认为定义中没有空 ptr,没有多线程,没有使用的字符串。我不知道该怎么做。

标签: segmentation-faultrospoint-cloud-library

解决方案


推荐阅读