点云数据以浮点二进制文件格式存储,每行包含8个数据,每个数据由四位十六进制数表示(浮点数),每个数据通过空格隔开。一个点云数据由四个浮点数数据构成,分别表示点云的x、y、z、r(强度 or 反射值),点云的存储方式如下表所示:
即每行包含两点的XYZI,那么只需要对一个点赋值对应的XYZI值,并将该点压入点云中即可。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace pcl;
using namespace std;
void topcd(string name);
void topcd(string name) {
//string name = "0000000000";
///The file to read from.
string infile = "D:/数据集/道路点云数据集/2011_09_26/2011_09_26_drive_0070/velodyne_points/data/" + name + ".bin";
///The file to output to.
string outfile = "D:/数据集/道路点云数据集/2011_09_26/2011_09_26_drive_0070/velodyne_points/pcddata/" + name + ".pcd";
// load point cloud
fstream input(infile.c_str(), ios::in | ios::binary);
if (!input.good()) {
cerr << "Could not read file: " << infile << endl;
exit(EXIT_FAILURE);
}
input.seekg(0, ios::beg);
pcl::PointCloud<PointXYZI>::Ptr points(new pcl::PointCloud<PointXYZI>);
int i;
for (i = 0; input.good() && !input.eof(); i++) {
PointXYZI point;
input.read((char*)&point.x, 3 * sizeof(float));
input.read((char*)&point.intensity, sizeof(float));
points->push_back(point);
}
input.close();
cout << "Read KTTI point cloud with " << i << " points, writing to " << outfile << endl;
pcl::PCDWriter writer;
// Save DoN features
writer.write<PointXYZI>(outfile, *points, false);
}
int main(int argc, char** argv) {
string name;
for (int i = 0; i < 420; i++) {
stringstream ss;
ss << setw(10) << setfill('0') << i;
string str;
ss >> str; //将字符流传给 str
topcd(str);
}
return 0;
}
结果如下:
根据data文件夹下的二进制文件生成了对应点云数据。
二进制文件:
pcd文件
pcd文件简单显示:
需要适应于自己的文件名和文件夹哦!