PCL_将点云数据写入PCD格式文件

#include //标准输入输出流  
#include //PCL的PCD格式文件的输入输出头文件  
#include //PCL对各种格式的点的支持头文件 

int main(int argc, char**argv)
{
	pcl::PointCloudcloud;// 创建点云(不是指针)  

	//Fill in the cloud data
	cloud.width = 5;
	cloud.height = 1;
	cloud.is_dense = false;//非密集型  
	cloud.points.resize(cloud.width*cloud.height);//变形,无序  
	//设置这些点的坐标  
	for (size_t i = 0; i < cloud.points.size(); ++i)
	{
		cloud.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
		cloud.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);

	}
	//保存到PCD文件
	pcl::io::savePCDFileASCII("test_pcd", cloud);//将点云保存到PCD文件中
	std::cerr << "Saved" << cloud.points.size() << "data points to test_pcd.pcd" << std::endl;
	//显示点云数据
	for (size_t i = 0; i < cloud.points.size(); ++i)
		std::cerr << "" << cloud.points[i].x << "" << cloud.points[i].y<< "" << cloud.points[i].z << std::endl;

	//waitKey(0);
	system("pause");
	return(0);
}
VS2013+opencv3.0

你可能感兴趣的:(study)