我的天啊!bin转pcd

这个bin转pcd,困扰了我好久.先后配置了ubuntu+eclipse for C/C++ 配置好久好久(真的好久啊)都没成功,一气之下删掉了.打算配置emacs.还没动手.我现在都忘记了,我转成pcd要干什么.

不知道哪根筋抽了,我今天依托ros的package包成功编译了.原理具体是什么不太懂.

1.建立工作空间,建立软件包.

mkdir -p 1/src
cd 1
catkin_make
//得到 devel 和 build
source devel/setup.bash
cd src
catkin_create_pkg ao ros_pcl roscpp
//ao是package_name   后面两个包是depend libraries
//得到cmakelists.txt 和 package.xml

2.将从网上找到的bin2pcd.cpp放入src中

来自https://blog.csdn.net/u012411498/article/details/80716794,感谢!!!

#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>
 
using namespace pcl;
using namespace std;
 
namespace po = boost::program_options;
 
int main(int argc, char **argv){
	///The file to read from.
	string infile;
 
	///The file to output to.
	string outfile;
 
	// Declare the supported options.
	po::options_description desc("Program options");
	desc.add_options()
		//Options
		("infile", po::value<string>(&infile)->required(), "the file to read a point cloud from")
		("outfile", po::value<string>(&outfile)->required(), "the file to write the DoN point cloud & normals to")
		;
	// Parse the command line
	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
 
	// Print help
	if (vm.count("help"))
	{
		cout << desc << "\n";
		return false;
	}
 
	// Process options.
	po::notify(vm);
 
	// 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
    pcl::io::savePCDFileBinary(outfile, *points);
    //writer.write<PointXYZI> (outfile, *points, false);
}

3.对cmakelists.txt 和 package.xml进行修改

cmakelists.txt修改后如下:

cmake_minimum_required(VERSION 2.8.3)
project(ao)  //ao 是包名称

add_compile_options(-std=c++11)


find_package(catkin REQUIRED COMPONENTS
pcl_ros
roscpp
)

find_package(PCL 1.7 REQUIRED)

catkin_package(
  INCLUDE_DIRS include
  CATKIN_DEPENDS roscpp pcl_ros
)

include_directories(
 include
 ${catkin_INCLUDE_DIRS}
)
link_directories(${PCL_LIBRARY_DIRS})

add_executable(${PROJECT_NAME}_node src/ao_node.cpp)   
//!!!精华在这里,这个是从cpp生成可执行文件。   {PROJECT_NAME}_node  这是生成可执行文件的名字,
在此例中,是ao_node.  后面的ao_node.cpp是需要编译的文件。


target_link_libraries(${PROJECT_NAME}_node
  ${catkin_LIBRARIES}
  ${PCL_LIBRARIES}
)

生成的可执行文件的路径在终端会有显示。

本例package.pcl不需要修改。

4.在终端输入命令

i=1;for x in apollobin2pcd/data/*.bin; do 1/devel/lib/ao/ao_node --infile $x --outfile apollobin2pcd/data/$i.pcd; let i=i+1; done

注意:apollobin2pcd/data/*.bin 是bin文件所在路径,do 1/devel/lib/ao/ao_node是可执行文件所在路径,outfile apollobin2pcd/data/$i.pcd输出的pcd所在路径。

最后得到pcd酱紫的,开心啦啦啦。

卢卡卡卡啦。

猜你喜欢

转载自blog.csdn.net/qq_40297851/article/details/85274563
今日推荐