PCL 平面模型分割


點雲操作中,平面的分割是經常遇到的問題,下面的例子就是如何利用PCL庫提擬合出的參數,之后就可以過濾掉在平面附近的點雲。

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/sample_consensus/method_types.h>   //隨機參數估計方法頭文件
#include <pcl/sample_consensus/model_types.h>   //模型定義頭文件
#include <pcl/segmentation/sac_segmentation.h>   //基於采樣一致性分割的類的頭文件

//過濾之后的點雲數據
//創建分割對象 -- 檢測平面參數
/*pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients); //存儲輸出的模型的系數
pcl::PointIndices::Ptr inliers(new pcl::PointIndices); //存儲內點,使用的點

pcl::SACSegmentation<pcl::PointXYZ> seg;
//可選設置
seg.setOptimizeCoefficients(true);
//必須設置
seg.setModelType(pcl::SACMODEL_PLANE); //設置模型類型,檢測平面
seg.setMethodType(pcl::SAC_RANSAC);      //設置方法【聚類或隨機樣本一致性】
seg.setMaxIterations(1000);
seg.setDistanceThreshold(0.01);
seg.setInputCloud(cloud_ptr_gridfilter);
seg.segment(*inliers, *coefficients);    //分割操作

//顯示模型的系數
std::cerr << "Model coefficients: " << coefficients->values[0] << " "
	      << coefficients->values[1] << " "
	      << coefficients->values[2] << " "
		<< coefficients->values[3] << std::endl;

// Extract the planar inliers from the input cloud  
pcl::ExtractIndices<pcl::PointXYZ> extract;
extract.setInputCloud(cloud_ptr_gridfilter);
extract.setIndices(inliers);
//除去平面之外的數據
extract.setNegative(true);
extract.filter(*cloud_filtered);

//進一步可利用點和平面的相對位置關系,進行篩選過濾掉平面附近的點

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM