环境:ubuntu20.04
目录
KITTI数据集由德国卡尔斯鲁厄理工学院和丰田美国技术研究院联合创办,是目前国际上最大的自动驾驶场景下的计算机视觉算法评测数据集。该数据集用于评测立体图像(stereo),光流(optical flow),视觉测距(visual odometry),3D物体检测(object detection)和3D跟踪(tracking)等计算机视觉技术在车载环境下的性能。KITTI包含市区、乡村和高速公路等场景采集的真实图像数据,每张图像中最多达15辆车和30个行人,还有各种程度的遮挡与截断。 3D目标检测数据集由7481个训练图像和7518个测试图像以及相应的点云数据组成,包括总共80256个标记对象。
一、环境配置
ros一键安装,包含有pcl
wget http://fishros.com/install -O fishros && . fishros
在Linux终端输入指令,选择安装ros,继续配置好ros相关环境。
二、实现步骤
1、创建目录
- 新建文件夹:kitti(大家自行定义就好,这个是我的课程实验)作为根目录。
- 在【kitti】文件夹下新建文件夹datasets、bulid
- 在【datasets】文件夹下新建两个文件夹
bin
与pcd
,bin
中存放要转换的二进制文件,pcd
存放转换后的点云文件
2、创建文件
新建CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(bin2pcd)
find_package(PCL 1.10 REQUIRED)#根据自己的版本进行修改
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)
新建bin2pcd.cpp
#include <boost/program_options.hpp>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/common/io.h>
#include <pcl/io/vtk_io.h>
#include <vector>
#include <iostream>
#include <fstream>
using namespace pcl;
using namespace std;
void topcd(string name);
void topcd(string infile,string outfile) {
// 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 point cloud with " << i << " points, writing to " << outfile << endl;
pcl::PCDWriter writer;
// Save DoN features
writer.write<PointXYZI>(outfile, *points, false);
}
int main(int argc, char** argv) {
string binpath = "/home/yang/kitti/datasets/bin/";
string pcdpath = "/home/yang/kitti/datasets/pcd/";
vector<boost::filesystem::path> stream(boost::filesystem::directory_iterator{binpath}, boost::filesystem::directory_iterator{});
sort(stream.begin(), stream.end());
auto streamIterator = stream.begin();
int j = 0;
while(streamIterator != stream.end()){
string binfile((*streamIterator).string());
stringstream ss;
string str;
ss << setw(10) << setfill('0') << j; // 补零
ss >> str;
string surfix = ".pcd";
string pcdfile = pcdpath + str + surfix;
topcd(binfile,pcdfile);
streamIterator++;
j++;
}
return 0;
}
注意
string binpath = "/home/yang/kitti/datasets/bin/";
string pcdpath = "/home/yang/kitti/datasets/pcd/";
这个路径必须修改成你自己的路径
3、编译
进入build文件夹:
cmake .. && make -j12
或者,你在根目录下:
cmake . && make -j12
运行成功显示:
4、运行
./bin2pcd