前言

代码是网上找的(基于ubuntu的),我改成了windows可用的,更改输入输出目录后,可直接用在kitti的点云文件上,将bin格式转成pcd格式。 需要用到pcl库。

运行环境

window10 +vs2019 debug x64

一、代码

#include <ctime>
#include <string>
#include <vector>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <iostream>
#include <fstream>
#include <io.h>using namespace std;static std::vector<std::string> file_lists;bool computePairNum(std::string pair1, std::string pair2)
{return pair1 < pair2;
}void sort_filelists(std::vector<std::string>& filists, std::string type)
{if (filists.empty())return;std::sort(filists.begin(), filists.end(), computePairNum);
}void readKittiPclBinData(std::string& in_file, std::string& out_file)
{// load point cloudstd::fstream input(in_file.c_str(), std::ios::in | std::ios::binary);if (!input.good()) {std::cerr << "Could not read file: " << in_file << std::endl;exit(EXIT_FAILURE);}input.seekg(0, std::ios::beg);pcl::PointCloud<pcl::PointXYZI>::Ptr points(new pcl::PointCloud<pcl::PointXYZI>);int i;for (i = 0; input.good() && !input.eof(); i++) {pcl::PointXYZI point;input.read((char*)&point.x, 3 * sizeof(float));input.read((char*)&point.intensity, sizeof(float));points->push_back(point);}input.close();std::cout << "Read KTTI point cloud with " << i << " points, writing to " << out_file << std::endl;pcl::PCDWriter writer;// Save DoN featureswriter.write< pcl::PointXYZI >(out_file, *points);//pcl::io::savePCDFileASCII(out_file, *points);
}//获取所有的文件名
void GetAllFiles(string path, vector<string>& files)
{//long   hFile = 0;intptr_t   hFile = 0;//文件信息  struct _finddata_t fileinfo;string p;if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1){do{if ((fileinfo.attrib & _A_SUBDIR)){if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0){files.push_back(p.assign(path).append("\\").append(fileinfo.name));GetAllFiles(p.assign(path).append("\\").append(fileinfo.name), files);}}else{files.push_back(p.assign(path).append("\\").append(fileinfo.name));}} while (_findnext(hFile, &fileinfo) == 0);_findclose(hFile);}}//获取特定格式的文件名
void GetAllFormatFiles(string path, vector<string>& files, string format)
{//文件句柄  //long   hFile = 0;intptr_t hFile = 0;//文件信息  struct _finddata_t fileinfo;string p;if ((hFile = _findfirst(p.assign(path).append("\\*" + format).c_str(), &fileinfo)) != -1){do{if ((fileinfo.attrib & _A_SUBDIR)){if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0){//files.push_back(p.assign(path).append("\\").append(fileinfo.name) );GetAllFormatFiles(p.assign(path).append("\\").append(fileinfo.name), files, format);}}else{files.push_back(p.assign(path).append("\\").append(fileinfo.name));}} while (_findnext(hFile, &fileinfo) == 0);_findclose(hFile);}
}int main(int argc, char** argv)
{std::string bin_path = "E:\\kitti\\data_object_velodyne\\testing\\velodyne";std::string pcd_path = "E:\\kitti\\data_object_velodyne\\testing\\pcd";GetAllFormatFiles(bin_path, file_lists, "bin");sort_filelists(file_lists, "bin");for (int i = 0; i < file_lists.size(); ++i){std::string bin_file = file_lists[i];int pos = bin_file.rfind("\\");std::string file_name_bin = bin_file.substr(pos, 11);std::string file_name = file_name_bin.substr(0, 7);std::string pcd_file = pcd_path+ file_name+ ".pcd";readKittiPclBinData(bin_file, pcd_file);}return 0;
}

二、问题及解决方案
1.使用pcdWriter的时候报错,link2019,无法解析的外部命令。
原因是没有包含pcl的lib库,将这两个库(pcl_iod.ilb和pcl_commond.lib)加入到链接器的输入中(debug模式)
如果是release的,就将pcl_io.ilb和pcl_common.lib加入到链接器的输入中
这些文件都在pcl的安装目录lib下面

链接器常规中的附加库目录记得设置一下

2.生成成功,但是运行的时候显示没有OpenNI2.dll

解决办法:在pcl的目录下找到这个OpenNI2.dll,复制粘贴到.exe的路径下即可。

Kitti点云文件bin转pcd相关推荐

  1. Open3d读写pcd点云文件

    1 Open3d 安装 Open3d是由Intel发布的一个开源库,支持快速开发和处理3D数据.Open3D在c++和Python中公开了一组精心选择的数据结构和算法.后端是高度优化的,并且是为并行化 ...

  2. 点云学习笔记19——使用pcl将bin文件转化为pcd文件

    从KITTI下载的数据是二进制bin格式,但是pcl似乎只能读取pcd文件,为了可视化,先将bin文件转换为pcd文件. 在home下,新建文件夹PointCloud(我建在这里,大家随意),在Poi ...

  3. 点云数据bin格式转换为pcd格式的方法

    申明:再找到一款点云标注工具(https://blog.csdn.net/r1141207831/article/details/103788891)的时候发现只能输入pcd文件,那么现有的bin文件 ...

  4. 激光点云格式转换 bin 相互 pcd转换

    代码在git kitti-velodyne-viewer View kitti lidar point cloud with bounding box label by single file. Re ...

  5. C 怎么读取Cpp文件_从PCD文件写入和读取点云数据

    (1)学习向PCD文件写入点云数据 建立工程文件ch2,然后新建write_pcd.cpp CMakeLists.txt两个文件 write_pcd.cpp : #include <iostre ...

  6. soidworks 生成PCD点云文件

    这里写自定义目录标题 1 soidworks转.obj 2 .obj文件转.pcd soidworks 生成PCD点云文件 1 soidworks转.obj 1.1打开soidworks插件 菜单栏– ...

  7. python处理点云数据_python将指定点云文件(asc)转换为PCD格式

    起因 由于自己大部分的点云文件都是.asc格式的,但最近用pcl做点云方面的研究,从asc文件到pcd文件手动转化太麻烦,而且效率较低,故此写一个不太成熟的python脚本实现从asc文件到pcd格式 ...

  8. 基恩士CSV点云文件转PCD文件 PYTHON版

    简介 将点云文件从矩阵形式存储的csv点云文件(CloudCompare 称为Matrix CSV)文件转换为PCD格式的点云文件 运行环境 Python3 运行需要的库 numpy open3d f ...

  9. 从bag包中提取图片和点云数据为pcd格式点云文件

    从bag包中提取图片和点云数据为pcd格式点云文件 1 开始提取bag包之前的准备工作 2 从bag包中提取图片和点云数据 首先说明一下我运行的系统环境: python2 Ubuntu18.04 RO ...

最新文章

  1. 读论文七步走!CV老司机万字长文:一篇论文需要读4遍
  2. PRML是模式识别和机器学习领域的经典著作
  3. 关于各种回归评价指标MSE、RMSE、MAE、R-Squared、Standard Deviation(标准差)
  4. “习惯测试”三步法,打造完美用户体验
  5. java rsa内容超长_RSA 非对称加密解密,超长字符串分块处理
  6. Array 复制到ArrayList中
  7. PostgreSQL源码学习(1)--PG13代码结构
  8. 苹果秋季新品发布会终于官宣:然而并不会发布新iPhone?
  9. 不是shell具有的功能和特点的是_环境监控主机具有哪些功能特点
  10. 计算机平面设计要学语数英吗,《计算机平面设计与制作》课程标准规范.doc
  11. 读书随笔《36岁, 半熟人生》
  12. Linux UDP协议栈中的片段分析 - udp_recvmsg
  13. python正态分布拟合曲线怎么打印出中位数值,如何用对数正态分布函数拟合数据...
  14. 计算机课excel,计算机excel教学课件.doc
  15. 计算机语言phal语言,2.7 PhalApi 2.x 国际化
  16. 侧滑、、、mark一下、、、
  17. 记一次全局/后台弹窗处理
  18. 开源应用中心 | 无需开发,如何快速搭建一款轻量级CRM系统?
  19. 支付系统架构V1.0
  20. npm yarn pnpm 的区别

热门文章

  1. 什么是DrawCall?
  2. 智能投影机android系统,投影仪内置安卓系统的好吗?当贝OS有多强?
  3. c语言改变输出字体颜色渐变,如何为Qt视图中的文字实现彩虹渐变效果
  4. 九宫格输入法(最易懂版本)
  5. html中outline属性,css outline属性怎么用?
  6. 跟着鬼哥学PyQtPart.3
  7. 良心到难以置信的网站推荐第6期丨上网必备
  8. 查看ES版本号(Elasticsearch)
  9. android tv闹钟_Android开发之闹钟
  10. SLAM经典:FSAT-LIO算法梳理