Les données téléchargées depuis KITTI sont au format bin binaire, mais il semble que pcl ne puisse lire que les fichiers pcd. Pour la visualisation, convertissez d'abord les fichiers bin en fichiers pcd.
Sous home, créez un nouveau dossier PointCloud (je l'ai construit ici, tout le monde est libre), continuez à créer un nouveau dossier bin2pcd dans le fichier PointCloud, continuez à créer un nouveau dossier velodyne et à le construire dans le fichier bin2pcd, et créez un nouveau document bin2pcd.cpp et CMakeLists.txt , entrez les nouveaux fichiers velodyne et continuez à créer de nouveaux dossiers bin et pcd À ce stade, la nouvelle opération est terminée.
Ensuite, placez le fichier bin testé dans le dossier bin de velodyne, je n'ai mis que 7 fichiers bin ici. Remplissez ensuite le code des documents vides bin2pcd.cpp et CMakeLists.tx, le code et les opérations ci-dessus, comme illustré dans la figure suivante :
code source
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)
Allez construire et ouvrez le 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 Il s'agit d'une boucle qui traverse tous les fichiers bin d'entrée, en transmettant le chemin absolu d'un fichier bin à x à chaque fois
- do build/bin2pcd consiste à exécuter le fichier bin2pcd généré précédemment, et le chemin est ajusté en fonction de la situation réelle
- --infile est le fichier d'entrée, --outfile est le fichier de sortie
- i est le nom du fichier de sortie, i= KaTeX parse error : '}' attendu, '#' en position 3 : {x#̲* b} signifie intercepter le caractère après le premier "_" (trait de soulignement) dans x chaîne
Avis:/home/xxxxx/Desktop/work/pcl_projectPassez à votre propre chemin de projet Le
test est réussi !
Une fois tous les codes exécutés avec succès, vérifiez le dossier pcd sous le fichier velodyne et vous trouverez le fichier pcd généré, comme indiqué ci-dessous :
référence
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/détails/100023615