关闭

《PCL点云库学习&VS2010(X64)》Part 17 PCL1.72(VTK6.2.0)数据格式转换txt2pcd

标签: 点云格式转换
991人阅读 评论(4) 收藏 举报
分类:

《PCL点云库学习&VS2010(X64)》Part 17 PCL1.72(VTK6.2.0)数据格式转换txt2pcd

1、txt转换成pcd点云格式

#include<iostream>  

#include<fstream>  
#include <string>  
#include <vector>  
#include <pcl/io/pcd_io.h>  
#include <pcl/point_types.h>  

#include <pcl/visualization/pcl_visualizer.h> 

using namespace std;
int main()
{
	typedef struct tagPOINT_3D
	{
		double x;  //mm world coordinate x  
		double y;  //mm world coordinate y  
		double z;  //mm world coordinate z  
		double r;


	}POINT_WORLD;


	/////加载txt数据  
	int number_Txt;
	FILE *fp_txt;
	tagPOINT_3D TxtPoint;
	vector<tagPOINT_3D> m_vTxtPoints;
	fp_txt = fopen("D:/C++Workspace/Model/bunny1.txt", "r");


	if (fp_txt)
	{
		while (fscanf(fp_txt, "%lf %lf %lf", &TxtPoint.x, &TxtPoint.y, &TxtPoint.z) != EOF)
		{
			m_vTxtPoints.push_back(TxtPoint);
		}
	}
	else
		cout << "txt数据加载失败!" << endl;
	number_Txt = m_vTxtPoints.size();
	//pcl::PointCloud<pcl::PointXYZ> cloud;
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);


	// Fill in the cloud data  
	cloud->width = number_Txt;
	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 = m_vTxtPoints[i].x;
		cloud->points[i].y = m_vTxtPoints[i].y;
		cloud->points[i].z = m_vTxtPoints[i].z;
	}
	pcl::io::savePCDFileASCII("D:/C++Workspace/Model/txt2pcd_bunny1.pcd", *cloud);
	std::cerr << "Saved " << cloud->points.size() << " data points to txt2pcd.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;

	//PCL Visualizer
	// Viewer  
	pcl::visualization::PCLVisualizer viewer("Cloud Viewer");

	viewer.addPointCloud(cloud);
	viewer.setBackgroundColor(1, 0.5, 1);

	viewer.spin();
	system("pause");
	return 0;
}



将转换后的结果显示出来




2
0
查看评论

《PCL点云库学习&VS2010(X64)》Part 20 PCL1.72(VTK6.2.0)PCL控制台程序线程

《PCL点云库学习&VS2010(X64)》Part 20 PCL1.72(VTK6.2.0)PCL控制台程序线程 1、控制台中添加线程 #include …… while (!viewer.wasStopped()) { //在此处可以添加其他处...
  • sinat_24206709
  • sinat_24206709
  • 2016-09-04 16:11
  • 558

《PCL点云库学习&VS2010(X64)》Part 19 PCL1.72(VTK6.2.0)PCL程序计时

《PCL点云库学习&VS2010(X64)》Part 19 PCL1.72(VTK6.2.0)PCL程序计时 1、系统计时 clock() 头文件:time.h 函数原型:clock_t clock(void); 功能:该函数返回值是硬件滴答数,要换算成秒,需要除以CLK_TCK或者 C...
  • sinat_24206709
  • sinat_24206709
  • 2016-08-31 23:05
  • 558

pcl点云库学习笔记

点云文件的打开。 #include #include #include #include #include int main(int argc, char** argv) { pcl::PointCloud::Ptr cloud; cloud = pcl::...
  • u012283902
  • u012283902
  • 2015-04-26 16:52
  • 1915

《PCL点云库学习&VS2010(X64)》Part 18 PCL1.72(VTK6.2.0)编译CloudCompare注意点

《PCL点云库学习&VS2010(X64)》Part 17 PCL1.72(VTK6.2.0)编译CloudCompare注意点 1、CMake时注意boost的路径; 2、CMake时注意CMake_Install_Prefix的路径,该路径是CMake生成后,打开.sln文件,编译、安装...
  • sinat_24206709
  • sinat_24206709
  • 2016-08-31 17:04
  • 1947

《PCL点云库学习&VS2010(X64)》Part 13 PCL1.72(VTK6.2.0)ICP示例

Part 13 PCL1.72(VTK6.2.0)ICP示例 1、ICP cpp: #include #include #include #include #include int main(int argc, char** argv) { pcl::PointCloud::Ptr...
  • sinat_24206709
  • sinat_24206709
  • 2016-06-30 10:28
  • 1276

《PCL点云库学习&VS2010(X64)》Part 9 PCL1.72(VTK6.2.0)滤波例程

Part 9 PCL1.72(VTK6.2.0)滤波例程 一、直通滤波 1、新建空的控制台程序:passthrough,属性列表中加入.props属性配置文件。 2、代码passthrough.cpp: #include #include #include #include int main...
  • sinat_24206709
  • sinat_24206709
  • 2016-06-12 17:26
  • 2098

《PCL点云库学习&VS2010(X64)》Part 10 PCL1.72(VTK6.2.0)选点操作

Part 10 PCL1.72(VTK6.2.0)选点操作 1、单点选取程序: cpp: #include #include #include #include typedef pcl::PointXYZRGBA PointT; typedef pcl::PointCloud Poin...
  • sinat_24206709
  • sinat_24206709
  • 2016-06-21 20:31
  • 2777

《PCL点云库学习&VS2010(X64)》Part 11 PCL1.72(VTK6.2.0)点特征描述与提取

Part 11 PCL1.72(VTK6.2.0)点特征描述与提取 1、NARF_Feature_Extraction cpp /* \author Bastian Steder */ #include #include #include #include #include #includ...
  • sinat_24206709
  • sinat_24206709
  • 2016-06-22 09:50
  • 1812

《PCL点云库学习&VS2010(X64)》Part 15 PCL1.72(VTK6.2.0)三角网格化(2)之泊松重构

《PCL点云库学习&VS2010(X64)》Part 15 PCL1.72(VTK6.2.0)三角网格化(2)之泊松重构 1、cpp //点的类型的头文件 #include //点云文件IO(pcd文件和ply文件) #include #include //kd树 #include ...
  • sinat_24206709
  • sinat_24206709
  • 2016-07-14 20:57
  • 1751

《PCL点云库学习&VS2010(X64)》Part 14 PCL1.72(VTK6.2.0)点云分割(Point Cloud Segmentation)

Part 14 PCL1.72(VTK6.2.0)点云分割(Point Cloud Segmentation) 1、Plane Model Segmentation cpp: #include #include #include #include #include #include ...
  • sinat_24206709
  • sinat_24206709
  • 2016-06-30 12:27
  • 3174
    个人资料
    • 访问:165080次
    • 积分:3106
    • 等级:
    • 排名:第13263名
    • 原创:143篇
    • 转载:25篇
    • 译文:1篇
    • 评论:116条
    最新评论