1. 程式人生 > >我的天啊!bin轉pcd

我的天啊!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醬紫的,開心啦啦啦。

盧卡卡卡啦。