本文主要是介绍《PCL点云库学习VS2010(X64)》Part 17 PCL1.72(VTK6.2.0)数据格式转换txt2pcd,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
《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);}}elsecout << "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;
}
将转换后的结果显示出来
这篇关于《PCL点云库学习VS2010(X64)》Part 17 PCL1.72(VTK6.2.0)数据格式转换txt2pcd的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!