点云处理:bin二进制文件转pcd文件

时间:2025-04-25 16:03:15
#include <boost/program_options.hpp> #include <pcl/point_types.h> #include <pcl/io/pcd_io.h> #include <pcl/common/point_operators.h> #include <pcl/common/> #include <pcl/search/> #include <pcl/search/> #include <pcl/search/> #include <pcl/features/normal_3d_omp.h> #include <pcl/filters/conditional_removal.h> #include <pcl/segmentation/sac_segmentation.h> #include <pcl/segmentation/extract_clusters.h> #include <pcl/surface/> #include <pcl/io/vtk_io.h> #include <pcl/filters/voxel_grid.h> #include <iostream> #include <fstream> 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; }