PCL點雲讀取和顯示


#include <iostream> //標準輸入輸出流
#include <pcl/io/pcd_io.h> //PCL的PCD格式文件的輸入輸出頭文件
#include <pcl/point_types.h> //PCL對各種格式的點的支持頭文件
#include <pcl/visualization/cloud_viewer.h>
 
int main(int argc, char** argv)
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); // 創建點雲(指針)
 
	if (pcl::io::loadPCDFile<pcl::PointXYZ>("E:/rabbit_gra.pcd", *cloud) == -1) //* 讀入PCD格式的文件,如果文件不存在,返回-1
	{
		PCL_ERROR("Couldn't read file test_pcd.pcd \n"); //文件不存在時,返回錯誤,終止程序。
		return (-1);
	}
	std::cout << "Loaded "
		<< cloud->width * cloud->height
		<< " data points from test_file.pcd with the following fields: "
		<< std::endl;
	for (size_t i = 0; i < cloud->points.size (); ++i) //顯示所有的點
	//for (size_t i = 0; i < cloud->size(); ++i) // 爲了方便觀察,只顯示前5個點
		std::cout << "    " << cloud->points[i].x
		<< " " << cloud->points[i].y
		<< " " << cloud->points[i].z << std::endl;
	pcl::visualization::CloudViewer viewer("pcd viewer");
	viewer.showCloud(cloud);
	system("pause");
	return (0);
}

 

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