资源简介
本文描述了如何通过KITTI数据集,读取激光雷达点云数据,并通过ground truth进行点云建图的过程。其代码的主要功能包括:1)点云文件的格式转换2)点云转换矩阵计算3)点云地图构建
代码片段和文件信息
#include “Comprocess.h“
#include “config.h“
#include
#include
#include
Comprocess::Comprocess()
{
}
Comprocess::~Comprocess()
{
}
int Comprocess::executebin2pcd(char *source_dir) {
listFiles(source_dir);
for (int i = 0; i < filelist.size(); i++) {
bin2pcd(source_dir filelist[i]);
}
return 1;
}
vector Comprocess::listFiles(const char * dir)
{
char dirNew[200];
strcpy(dirNew dir);
strcat(dirNew “\\*.*“); //
intptr_t handle;
_finddata_t findData;
handle = _findfirst(dirNew &findData);
if (handle == -1) //
return filelist;
do
{
if (findData.attrib & _A_SUBDIR)
{
if (strcmp(findData.name “.“) == 0 || strcmp(findData.name “..“) == 0)
continue;
cout << findData.name << “\t\n“;
//
strcpy(dirNew dir);
strcat(dirNew “\\“);
strcat(dirNew findData.name);
listFiles(dirNew);
}
else {
//cout << findData.name << “\t“ << findData.size << “ bytes.\n“;
filelist.push_back(findData.name);
}
} while (_findnext(handle &findData) == 0);
_findclose(handle); //
return filelist;
}
void Comprocess::bin2pcd(const char * dir const string filename) {
string inputfilename = filename;
inputfilename = inputfilename.insert(0 dir);
const char* inptfile = inputfilename.data();
int32_t num = 1000000;
float *data = (float*)malloc(num * sizeof(float));
//
float *px = data + 0;
float *py = data + 1;
float *pz = data + 2;
float *pr = data + 3;//
//
FILE *stream;
fopen_s(&stream inptfile “rb“);
num = fread(data sizeof(float) num stream) / 4;//
fclose(stream);
int32_t after_erase_num = 0;
int distance_threshold=20;
float *px_t = px;
float *py_t = py;
float *pz_t = pz;
float *pr_t = pr;//
for (int32_t i = 0; i < num; i++)
{
//setting a threshold according to the distance between the point and centre to decrease the points
double distance = sqrt((*px_t)*(*px_t) + (*py_t)*(*py_t) + (*pz_t)*(*pz_t));
if (distance < distance_threshold) {
after_erase_num += 1;
}
px_t += 4; py_t += 4; pz_t += 4; pr_t += 4;
}
const char* outfile;
string outputfilename = filename;
outputfilename = outputfilename.replace(outputfilename.find(“.“) + 1 3 “pcd“);
outfile = outputfilename.insert(0 PCD_OUTPUT_PATH).data();
FILE *writePCDStream;
fopen_s(&writePCDStream outfile “wb“);
fprintf(writePCDStream “VERSION 0.7\n“);//
fprintf(writePCDStream “FIELDS x y z\n“);//
fprintf(writePCDStream “SIZE 4 4 4\n“);//
fprintf(writePCDStream “TYPE F F F\n“);//
fprintf(writePCDStream “WIDTH %d\n“ after_erase_num);//
fprintf(writePCDStream “HEIGHT 1\n“);//
fprintf(writePCDStream “POINTS %d\n“ after_erase_num);//
fprintf(writePCDStream “DATA ascii\n“);//
for (int32_t i = 0; i < num; i++)
{
double distance = sqrt((*px)*(*px) + (*py)*(*py) + (*pz)*(*pz));
if (distance < distance_threshold) {
fprintf(writePC
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2382 2020-02-17 19:50 mapping.cpp
文件 176684 2013-10-31 18:58 07.txt
文件 3987 2020-02-17 19:34 Comprocess.cpp
文件 602 2020-02-17 17:23 Comprocess.h
文件 80 2020-02-16 12:41 config.cpp
文件 447 2020-02-17 19:35 config.h
文件 8521096 2020-02-17 19:10 map.pcd
----------- --------- ---------- ----- ----
8705278 7
- 上一篇:PDFPasswordRemover 最新版+注册码
- 下一篇:万能驱动IC卡读卡器
评论
共有 条评论