当前位置:网站首页>未知点云结构文件转换需求
未知点云结构文件转换需求
2022-08-04 21:25:00 【moneymyone】
未知点云结构文件转换需求
需求描述
有一批点云,二进制的,字段非常规类型。
但是可以看出来总共有6个字段,其中两个字段是
_,没有具体规定是什么字段。现在要把这两个不知名的字段去掉,保留剩余4个字段
x y z intensity。

格式转换
还是同理,通过自定义点类型实现点云文件转换。
定义点类型的时候,短横类型设置为int 或者 string对于结果没有影响。
struct MyPointType //定义点类型结构
{
PCL_ADD_POINT4D; //该点类型有4个元素
/*尝试新增一个自定义*/
unsigned m; //定义自己新增的类型名称
//测试了添加这么多个也没问题
float intensity;
unsigned k;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW //确保new操作符对齐操作
}EIGEN_ALIGN16; //强制SSE 对齐
POINT_CLOUD_REGISTER_POINT_STRUCT(MyPointType, //注册点类型宏
(float ,x,x)
(float ,y,y)
(float ,z,z)
(unsigned char ,m,m)
(float ,intensity,intensity)
(unsigned ,k,k)
)
主代码如下,可实现对文件夹下所有点云文件的批量转换:
/*
* @Description:
* @version: 1.0.0
* @Author: qianchengjun
* @Date: 2022-02-22 14:33:45
* @LastEditors: qianchengjun
* @LastEditTime: 2022-02-22 16:49:34
*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <stdio.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
using namespace std;
void ConvertPCD(std::string file)
{
pcl::PointCloud<MyPointType> cloudsrc;
pcl::PointCloud<pcl::PointXYZI> cloudtar;
if (pcl::io::loadPCDFile<MyPointType>(file, cloudsrc) == -1)
{
PCL_ERROR("Couldn'n read file! \n");
return;
}
std::cout << cloudsrc.points.size() << std::endl;
for (size_t i = 0; i < cloudsrc.points.size(); i++)
{
pcl::PointXYZI pt;
pt.x = cloudsrc[i].x;
pt.y = cloudsrc[i].y;
pt.z = cloudsrc[i].z;
pt.intensity = cloudsrc[i].intensity;
cloudtar.push_back(pt);
}
std::string newfile = file.replace(file.rfind(".pcd"),4,"_new.pcd");
pcl::PCDWriter writer;
writer.write<pcl::PointXYZI> (newfile, cloudtar, true); // 保存文件
}
int main(int argc, char** argv)
{
//目标文件夹路径
std::string folder = "/home/qiancj/Documents/M1/Underground_Garage/4.5mleft_head/";
vector<string> files;
getFiles(folder.c_str(), files);
for_each(files.begin(), files.end(), [](const string &file){
ConvertPCD(file);
cout << "finish convert file: " << file << endl; });
return 0;
}
结果如下:
所有新转换的文件名称都变为了“XXXXX_new.pcd”

边栏推荐
- Go----Go 语言基础之标识符、关键字、命名规范、变量、常量
- SPSS-System Clustering Software Practice
- adb控制常用命令
- matlab 画图
- unity2D横版游戏教程8-音效
- [2022 Hangzhou Electric Power Multi-School 5 1012 Questions Buy Figurines] Application of STL
- 括号匹配
- Spss-系统聚类软件实操
- Re24:读论文 IOT-Match Explainable Legal Case Matching via Inverse Optimal Transport-based Rationale Ext
- SPSS-unary regression practice
猜你喜欢

Red team kill-free development practice of simulated confrontation

Win11如何开启Telnet客户端?

PyTorch Geometric (PyG) 安装教程

proe和creo的区别有哪些

AXI interface application of Zynq Fpga image processing - the use of axi_lite interface

【PCBA方案设计】握力计方案

数电快速入门(二)(复合逻辑运算和逻辑代数的基本定律的介绍)

立即升级!WPS Office 出现 0day 高危安全漏洞:可完全接管系统,官方推出紧急更新

大势所趋之下的nft拍卖,未来艺术品的新赋能

stm32mp157系统移植 | 移植ST官方5.10内核到小熊派开发板
随机推荐
【2022杭电多校5 1012题 Buy Figurines】STL的运用
后缀式的计算
顺序队列
LayaBox---TypeScript---首次接触遇到的问题
laravel whereDoesntHave
buu web
知识分享|如何设计有效的帮助中心,不妨来看看以下几点
【uiautomation】微信好友列表获取(存储到txt中)
ini怎么使用? C#教程
结构体小结
unity2D横版游戏教程9-对话框dialog
In action: 10 ways to implement delayed tasks, with code!
传奇服务器需要什么配置?传奇服务器租用价格表
实战:10 种实现延迟任务的方法,附代码!
AtCoder Beginner Contest 262 D - I Hate Non-integer Number
大势所趋之下的nft拍卖,未来艺术品的新赋能
【1403. 非递增顺序的最小子序列】
js数据类型、节流/防抖、点击事件委派优化、过渡动画
dotnet 使用 lz4net 压缩 Stream 或文件
C语言知识大全(一)——C语言概述,数据类型