出现这个错误可能的原因是 点击打开链接
而我在处理云点时,问题出在指针,刚开始我只通过
pcl::PointIndices::Ptr inliers
定义了inliers, 而没有为它开辟空间,因此在seg.segment函数中进行传参时,指针出现问题。所以,要注意通过函数传参返回运算结果时,一定要先开辟好存储空间,在存储。
int Ransac::PlaneEstimation(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud,
int count, pcl::ModelCoefficients::Ptr model_coefficients,
const char* outputpath) {
// Create the segmentation object
pcl::SACSegmentation<pcl::PointXYZRGB> seg;
pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
// Optional
seg.setOptimizeCoefficients(true);
// Mandatory
seg.setModelType(pcl::SACMODEL_PLANE);
seg.setMethodType(pcl::SAC_RANSAC);
seg.setDistanceThreshold(0.5);
seg.setMaxIterations(300);
//seg.setProbability(p);
seg.setInputCloud(cloud);
seg.segment(*inliers, *model_coefficients);
if (inliers->indices.size() == 0)
{
PCL_ERROR("Could not estimate a planar model for the given dataset.");
return 0;
}
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_plane(new pcl::PointCloud<pcl::PointXYZRGB>);
// Extract the planar inliers from the input cloud
pcl::ExtractIndices<pcl::PointXYZRGB> extract;
extract.setInputCloud(cloud);
extract.setIndices(inliers);
// Get the points associated with the planar surface
extract.filter(*cloud_plane);
string fn = string(outputpath) + "\\plane" +to_string(count) + ".txt";
write2txt(fn.c_str(), cloud_plane);
extract.setNegative(true);
cloud->clear();
extract.filter(*cloud);
return 1;
}