The data downloaded from KITTI is in binary bin format, but it seems that pcl can only read pcd files. For visualization, first convert the bin files to pcd files.
Under home, create a new folder PointCloud (I built it here, everyone is free), continue to create a new folder bin2pcd in the PointCloud file, continue to create a new folder velodyne and build in the bin2pcd file, and create a new document bin2pcd.cpp and CMakeLists.txt , enter the new velodyne files, and continue to create new folders bin and pcd. At this point, the new operation is over.
Then put the tested bin file into the bin folder in velodyne, I only put 7 bin files here. Then fill in the code of the empty documents bin2pcd.cpp and CMakeLists.tx, the code and the above operations, as shown in the following figure:
source code
bin2pcd.cpp
#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
writer.write<PointXYZI> (outfile, *points, false);
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
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)
Go to build and open the terminal
cmake ..
make -j8
i=1;for x in /home/xxxxx/Desktop/work/pcl_project/PointCloud/bin2pcd/velodyne/bin/*.bin; do /home/xxxxx/Desktop/work/pcl_project/PointCloud/bin2pcd/build/bin2pcd --infile $x --outfile /home/xxxxx/Desktop/work/pcl_project/PointCloud/bin2pcd/velodyne/pcd/$i.pcd; let i=i+1; done
- for x in your/input/data/*.bin This is a loop that traverses all input bin files, passing the absolute path of a bin file to x each time
- do build/bin2pcd is to run the bin2pcd file generated earlier, and the path is adjusted according to the actual situation
- --infile is the input file, --outfile is the output file
- i is the name of the output file, i= KaTeX parse error: Expected '}', got '#' at position 3: {x#̲* b} means to intercept the character after the first "_" (underscore) in x string
Notice:/home/xxxxx/Desktop/work/pcl_projectChange to your own project path The
test is successful!
After all the codes are successfully executed, check the pcd folder under the velodyne file, and you will find the generated pcd file, as shown below:
reference
1、https://www.manongdao.com/article-955482.html
2、https://blog.csdn.net/qq_35491306/article/details/82903371
3、https://blog.csdn.net/MAX_Hope/article/details/100023615