資源簡(jiǎn)介
使用PCL中RANSAC探測(cè)識(shí)別平面,并且可將探測(cè)出的多個(gè)平面進(jìn)行單獨(dú)保存。
代碼片段和文件信息
//RANSAC探測(cè)多個(gè)平面
#include
#include?
#include?
#include?
#include????//隨機(jī)參數(shù)估計(jì)方法頭文件
#include????//模型定義頭文件
#include????//基于采樣一致性分割的類(lèi)的頭文件
#include?
#include?
#include
#include?
#include
using?namespace?std;
int?GetRandomNumber()
{
int?RandomNumber;
RandomNumber?=?rand()?%?(256)?+?0;//0到255之間選擇顏色
//生成其他范圍的數(shù)字:RandomNumber?=?rand()?%?(b-a+1)?+?a;
return?RandomNumber;
}
void?main()
{
//第一步:定義輸入的原始數(shù)據(jù)及濾波后的點(diǎn),以及分割獲得的點(diǎn)、平面系數(shù)coefficients、存儲(chǔ)內(nèi)點(diǎn)的索引集合對(duì)象inliers、用于顯示的窗口
pcl::PointCloud::Ptr?cloud(new?pcl::PointCloud);
pcl::PointCloud::Ptr?planar_segment(new?pcl::PointCloud);//創(chuàng)建分割對(duì)象
pcl::io::loadPCDFile(“E:\\program_study\\C++\\pcd_data\\table_scene_lms400.pcd“?*cloud);
//pcl::io::loadPCDFile(“E:\\program_study\\C++\\pcd_data\\cubic.pcd“?*cloud);
pcl::ModelCoefficients::Ptr?coefficients(new?pcl::ModelCoefficients);//模型系數(shù)
pcl::PointIndices::Ptr?inliers(new?pcl::PointIndices);//索引列表
pcl::SACSegmentation?seg;//分割對(duì)象
pcl::visualization::PCLVisualizer?viewer(“planar?segment“);
viewer.setBackgroundColor(0?0?0);
pcl::ExtractIndices?extract;//提取器
int?n_piece=2;//需要探測(cè)的面的個(gè)數(shù)
//第二步:將原始點(diǎn)加載進(jìn)入
pcl::visualization::P
評(píng)論
共有 條評(píng)論