背景介绍
关于pcl,各种介绍文章以及官网也不少, 这篇仅仅针对pcap格式的雷达数据包转码pcl(官网给出的方法)进行一个复现, 补充一些个人在转换过程中的心得.毕竟此前从未接触过pcl相关领域.
相关参考文章
不得不说, 在使用过程中,对于pcl库的使用, 配置相关的依赖环境也折腾了很多时间…
pcl官方-macOS对pcl以及其依赖环境的安装
pcl官网-pacp转pcl
官方pcap数据下载地址
pcl文件(.pcd)的数据格式理解
读取pcl文件(.pcd)并显示
这里仅仅截取一段pcd文件,展示一下pcd文件的文件格式,知道的小伙伴就跳过好了,还没了解的可以自己先去了解
# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z
SIZE 4 4 4
TYPE F F F
COUNT 1 1 1
WIDTH 35947
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 35947
DATA ascii
-1.10698 3.272394 -0.447241
-1.80195 3.367094 -0.704211
-4.12496 5.602794 2.824819
2.44725 3.493394 1.427299
0.41545 3.145894 -0.179121
贴一下读取并可视化的代码pcd文件的代码,这里我写了一个PcdRead类, 这里我们读取pcl官网给出的经典的兔子点云数据.
//
// Created by tianNanYiHao on 2019-07-18.
//
#include "PcdRead.h"
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/io/io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp>
using namespace std;
using namespace pcl;
/**
* 读取pcd文件内容
* @param filePath 文件路径
*/
void PcdRead::readPcdFile(const string filePath) {
//创建了一个名为cloud的指针,储存XYZ类型的点云数据
PointCloud<PointXYZ>::Ptr cloud(new PointCloud<PointXYZ>);
/*打开点云文件*/
if (io::loadPCDFile<PointXYZ>(filePath, *cloud) == -1) {
PCL_ERROR("Couldn't read file xxx.pcd\n");
return ;
}
cout << "Loaded:" << cloud->width * cloud->height << "data points from test_pcd.pcd with the following fields:"
<< endl;
for (size_t i = 0; i < cloud->points.size(); ++i) {
cout << " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z
<< " " << endl;
}
cout << cloud->points.size() << endl;
cout << "from rabbit.pcd" << endl;
/*点云pcd文件可视化*/
visualization::PCLVisualizer::Ptr viewer (new visualization::PCLVisualizer ("3D Viewer"));
viewer->addPointCloud (cloud, "rabbit-cloud");
viewer->spin();
}
写入点云数据,并生成pcd格式文件
写入点云数据的相关文章其实网上很多,这里也贴一下,毕竟是pcap转pcd过程中的一个前置知识环节,同样知道的小伙伴也可以快速调过,这里补充一些,PcdWrite类大家只要看关于点云相关的内容就好, 关于json解析的那段其实是一开始我用wireshark软件提取了pacp的json格式,以为这玩意儿就是数据内容了,其实并不是,哈哈,尴尬.
//
// Created by tianNanYiHao on 2019-07-18.
//
#include "PcdWrite.h"
#include