.dat文件三维点云可视化
来源:互联网 发布:java singleton模式 编辑:程序博客网 时间:2024/05/18 02:45
我们做点云重建,很多情况下激光扫描仪回传的点云数据是保存为.txt或者.dat的,而并非PCL所支持的PCD格式,这个时候就需要我们自行写代码进行读取
.dat文件读取
我们的点云数据文件如下所示,为二进制.dat文件,其中每一行是二维扫描仪线扫的数据,这么多行是因为云台转动得到的三维扫描数据。其中每一行的前52个字节是一些校验码等无效数据,我们需要自己写代码进行读取。
C++读取.dat文件没什么难度,重点是有个技巧需要知道,就是这个数据每4个字节是一个int型数据代表了点距离扫描仪的距离,因此我读取的时候必须每次读取4字节的16进制数存入一个int型变量。采用的方法如下:
int dst_temp;for (int m = 0; m < 4; m++){ char *p = (char *)&dst_temp; dataFile.read(p + 3 - m, sizeof(char));}
思路就是,对一个int变量进行取址,将其地址强制转成char*,那么,这个指针char* p指向的就是int的首地址,我们每次读取一位,读四次刚好存满这个int。由于int存储的时候是先低位后高位,因此我们需要将先读的放到后面,后读的放到前面。上程序就是完成这个读取。
完整代码如下:
#include <pcl/visualization/cloud_viewer.h>#include <iostream>#include <pcl/io/io.h>#include <pcl/io/pcd_io.h>#include <fstream>#include <queue>#include <sstream>#include <stack>#include <string>#include <math.h>using namespace std;int user_data;int main(){ ifstream dataFile; pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointXYZ point_temp; //上一点 pcl::PointXYZ point_3D; //当前点 int dstOri, plsOri; //原始距离值和反射率 double pls, dst; //处理后距离值和反射率 dataFile.open("201715172734.dat",ios::binary); //以二进制形式打开文件 if (dataFile) { for (int i = 0; i < 600; i++) //600行数据 { dataFile.seekg(52 + i * 8056); //不读无效数据 for (int j = 0; j < 1000; j++) //每行1000个点 { int dst_temp = 0; //距离 int pls_temp=0; //反射率 float theta, alpha; //坐标变换的角度 for (int m = 0; m < 4; m++) //读取距离 { char *p = (char *)&dst_temp; dataFile.read(p + 3 - m, sizeof(char)); } for (int m = 0; m < 4; m++) //读取反射率 { char *p = (char *)&pls_temp; dataFile.read(p + 3 - m, sizeof(char)); } dstOri = dst_temp; plsOri = pls_temp; if (dstOri == -2147483648 || dstOri == 2147483647) point_3D = point_temp; else { dst = dstOri / 10000.0; //进行坐标变换 theta = (500 * M_PI - j*M_PI) / 1998; alpha = -0.3 + i*0.001; point_3D.x = dst*sin(theta); point_3D.y = dst*cos(theta)*sin(alpha); point_3D.z = -dst*cos(theta)*cos(alpha); } point_temp = point_3D; pointcloud->push_back(point_3D);//将点存入pointcloud } } cout << pointcloud->size() << endl; pcl::visualization::CloudViewer viewer("Cloud Viewer");//点云可视化 //blocks until the cloud is actually rendered viewer.showCloud(pointcloud); while (!viewer.wasStopped()) { //you can also do cool processing here //FIXME: Note that this is running in a separate thread from viewerPsycho //and you should guard against race conditions yourself... user_data++; } } else { cout << "No datafile"; } dataFile.close(); return 0;}
效果如下:
重建效果:
0 0
- .dat文件三维点云可视化
- OpenGL+MFC对三维点云的法向量实现可视化
- 三维点云表示
- GPU可编程渲染的矢量点要素符号三维可视化
- dat文件
- 可视化点云出错
- 三维点云求取------2
- 三维点云数据集
- 三维点云数据集
- matllab处理三维点云
- 医学影像三维可视化软件
- Meshlab读取三维点云、三维点云重建以及三维点云法向量计算
- PCL可视化显示点云
- 点云的简单可视化
- PCL可视化显示点云
- index.dat文件剖析
- 删除wkNtFsLdf.dat文件
- VC读取dat文件
- React学习之事件绑定处理机制(五)
- 动态规划-蓝桥杯-入学考试-采草药问题
- virtualenvs error: deactivate must be sourced. Run 'source deactivate' instead of 'deactivate'
- 安卓打包出现问题
- QT之GUI学习笔记(八)----菜单和工具条的优化
- .dat文件三维点云可视化
- java se 01
- Lintcode 最小子串覆盖
- Android中去掉EditText的下划线
- PCL常用语句
- office技巧(一)——excel如何流畅输入
- Linux系统入门学习:教你在VirtualBox 安装 Ubuntu 15.04
- React项目的打包与部署到腾讯云
- eclipse配置tomcat8.5报错The Apache Tomcat installation at this directory is version 8.5.4. A Tomcat 8.0