PCL 根據參數模型將點雲數據映射到指定的幾何模型

// projectpoints.cpp : 定義控制檯應用程序的入口點。
//

#include "stdafx.h"

//
//int _tmain(int argc, _TCHAR* argv[])
//{
//	return 0;
//}

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/filters/project_inliers.h>
using namespace std;


int
main(int argc, char** argv)
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected(new pcl::PointCloud<pcl::PointXYZ>);

	
	pcl::PCDReader reader;
	// Replace the path below with the path where you saved your file
	reader.read<pcl::PointXYZ>("table_scene_lms400.pcd", *cloud);

	// Create a set of planar coefficients with X=Y=0,Z=1 創建一組平面係數
	pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients());
	coefficients->values.resize(4);//values是一個定義的實數型vector 作用???
	coefficients->values[0] = coefficients->values[1] = 0;
	coefficients->values[2] = 1;
	coefficients->values[3] = 0;

	// Create the filtering object
	pcl::ProjectInliers<pcl::PointXYZ> proj;//創建 參數模型投影對象
	proj.setModelType(pcl::SACMODEL_PLANE);//SAC 應該是Sampling Consensus 採樣一致性 選擇SAC中的平面模型
	proj.setInputCloud(cloud);//同時初始化input_和indices_
	proj.setModelCoefficients(coefficients);//設置模型參數
	proj.filter(*cloud_projected);

	
	pcl::PLYWriter write;
	write.write<pcl::PointXYZ>("pm_map_table_plane.ply", *cloud_projected);

	return (0);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章