批量转换Bin文件为同名pcd文件

#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/io.h>
#include <pcl/search/organized.h>
#include <pcl/search/octree.h>
#include <pcl/search/kdtree.h>
#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/gp3.h>
#include <pcl/io/vtk_io.h>
#include <pcl/filters/voxel_grid.h>
 
#include <iostream>
#include <fstream>
#include <sys/types.h>  
#include <dirent.h> 
#include <vector>
 
using namespace pcl;
using namespace std;
 
namespace po = boost::program_options;
 void GetFileNames(string& path, vector<string>& filenames)
    {
        DIR *pDir;
        struct dirent* ptr;
        if(!(pDir = opendir(path.c_str())))
            return;
        while((ptr = readdir(pDir))!=0) {
            if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0)
                filenames.push_back(ptr->d_name);
        }
        closedir(pDir);
    }
int main(int argc, char **argv){

	string path1 = "/home/zjh/Dataset/KITTI_road/data_road_velodyne/testing/velodyne/";
	string path2 = "/home/zjh/文档/pcd/";
	vector<string> filenames;
	GetFileNames(path1,filenames);
	for(int j=0;j<filenames.size();j++)
	{
			///The file to read from.
		string infile = path1 + filenames[j];
	
		///The file to output to.
		string outfile = path2 + filenames[j].substr(0,filenames[j].rfind(".")) + ".pcd";
	
		fstream input(infile.c_str(), ios::in | ios::binary);
		// cout<<infile.c_str()<<endl;

		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);
	}
	
}

Cmakelist:

cmake_minimum_required(VERSION 2.6)
project(bin2pcd)
 
find_package(PCL 1.2 REQUIRED)
 
# 加入Boost setting
find_package(Boost COMPONENTS program_options REQUIRED )
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
 
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
 
add_executable(bin2pcd bin2pcd.cpp)
 
target_link_libraries (bin2pcd ${PCL_LIBRARIES} ${Boost_LIBRARIES}) #此处也有修改
 
install(TARGETS bin2pcd RUNTIME DESTINATION bin)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值