利用vs pcl库将多个PCD文件合并成一张PCD地图
主机环境:win10系统,pcl库1.11.1,
vs2019 pcl库安装以及环境配置如下连接:
https://www.jb51.net/article/190710.htm
代码很简单,主要是做个坐标转换,如下:
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <iostream> //标准输入输出流
#include <pcl/io/pcd_io.h> //PCL的PCD格式文件的输入输出头文件
#include <pcl/point_types.h> //PCL对各种格式的点的支持头文件
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/cloud_viewer.h>
void GetAllFiles(string path, vector<string>& files)
{
long 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));
}
}
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 long 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);
}
}
{
string filePath = "C:\\Users\\CTOS\\Desktop\\newpcd";
vector<string> files;
const char* distAll = "*.pcd";
string format = ".pcd";
GetAllFormatFiles(filePath, files, format);
ofstream ofn(distAll);
int size = files.size();
cout << size << endl;
ofn << size << endl;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); // 创建点云(指针)
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_prt(new pcl::PointCloud<pcl::PointXYZ>); // 创建点云(指针)
pcl::PointCloud<pcl::PointXYZ>::Ptr transformed_cloud(new pcl::PointCloud<pcl::PointXYZ>); // 创建点云(指针)
for (int i = 0; i < size; i++)
{
ofn << files[i] << endl;
cout << files[i] << endl;
if (pcl::io::loadPCDFile<pcl::PointXYZ>(files[i], *cloud_prt) == -1) //* 读入PCD格式的文件,如果文件不存在,返回-1
{
cout << "Couldn't read file pcd \n"<< endl; //文件不存在时,返回错误,终止程序。
return (-1);
}
Eigen::Vector4f p = cloud_prt->sensor_origin_.matrix();
Eigen::Quaternionf q;
q = cloud_prt->sensor_orientation_.matrix();
Eigen::Vector3f eulerAngle = q.matrix().eulerAngles(2, 1, 0);
Eigen::Affine3f transform = Eigen::Affine3f::Identity();
transform.translation() << p[0], p[1], p[2];
transform.rotate(q);
std::cout << transform.matrix() << std::endl;
pcl::transformPointCloud(*cloud_prt, *transformed_cloud, transform);
*cloud += *transformed_cloud;
cloud_prt->clear();
transformed_cloud->clear();
Sleep(1);
}
pcl::visualization::CloudViewer viewer("pcd viewer");
viewer.showCloud(cloud);
while (!viewer.wasStopped())
{
}
ofn.close();
return 0;
}

利用vs pcl库将多个PCD文件合并成一张PCD地图的更多相关文章
- PCL点云库中怎样读取指定的PCD文件,又一次命名,处理后保存到指定目录
我一直想把处理后的pcd文件重命名,然后放到指定的目录,尝试了好久最终做到了: 比方我想读取 "table_scene_lms400.pcd" 把它进行滤波处理,重命名为 &qu ...
- PCD文件格式详解及在PCL下读取PCD文件
一.PCD简介 1.1 PCD版本 在点云库PCL 1.0发布之前,PCD文件格式就已经发展更新了许多版本.这些新旧不同的版本用PCD_Vx来编号(例如PCD_V5.PCD_V6和PCD_V7等),分 ...
- PCL Save VTK File With Texture Coordinates 使用PCL库来保存带纹理坐标的VTK文件
我之前有一篇博客Convert PLY to VTK Using PCL 1.6.0 or PCL 1.8.0 使用PCL库将PLY格式转为VTK格式展示了如何将PLY格式文件转化为VTK格式的文件, ...
- 利用私有的库MobileCoreServices检测正在安装的应用
利用的私有库检测正在安装的app 分为两步:第一,通过placeholderApplications获得所有的正在安装的app的信息 第二,遍历正在安装的app的信息,根据名称获得你想检测的app是否 ...
- Convert PLY to VTK Using PCL 1.6.0 使用PCL库将PLY格式转为VTK格式
PLY格式是比较流行的保存点云Point Cloud的格式,可以用MeshLab等软件打开,而VTK是医学图像处理中比较常用的格式,可以使用VTK库和ITK库进行更加复杂的运算处理.我们可以使用Par ...
- c# 利用动态库DllImport("kernel32")读写ini文件(提供Dmo下载)
c# 利用动态库DllImport("kernel32")读写ini文件 自从读了设计模式,真的会改变一个程序员的习惯.我觉得嘛,经验也可以从一个人的习惯看得出来,看他的代码编写习 ...
- PCL 库安装
参考资料: http://www.cnblogs.com/newpanderking/articles/4022322.html VS2010+PCL配置 PCL共有两种安装方式 安全安装版,个人配置 ...
- Window7下手动编译最新版的PCL库
PCL简介 PCL是Point Cloud Library的缩写,是一个用于处理二维图像,三维深度图像和三维点云的C++库.该库是完全开源的,可免费用于商业和学术研究. 官方网站:http://poi ...
- Ubuntu 16.04 安装PCL库以及测试
参考链接:https://blog.csdn.net/dantengc/article/details/78446600 参考博客,官网一直安装不成功,后来参照一篇博客终于安装成功了,记录如下. 1. ...
随机推荐
- ceph bluestore的db分区应该预留多大的空间
前言 关于bluestore的db应该预留多少空间,网上有很多资料 如果采用默认的 write_buffer_size=268435456 大小的话 那么几个rocksdb的数据等级是 L0: in ...
- python-基础入门-5(模块、类和对象)
模块 模块用import来调用,例如 from sys import argv 调用sys中argv模块 在模块里有多个def的函数 import调用全部或其中一个 类和对象 下面定义了一个类 1 c ...
- 仿射密码-fanfie--affine
仿射密码 仿射密码 是一种专情密码,一对一替换 ~~ 加密函数是 e(x) = ax + b (mod m) 其中a和m 互质,m是字母的数目. 解码函数是 d(x) = a^-1(x - b) (m ...
- 硕思logo设计师注册码去哪里找,文末附链接
硕思logo设计师注册码去哪里找呢?当然是硕思logo设计师官网啦! 最近小编总是会被网友们咨询关于logo设计的问题,其中很多网友并不是专业的设计人员,特别是一些设计公司面对新手设计时,往往会不知所 ...
- 教您使用OCR编辑器复制文档内容
ABBYY FineReader 15允许用户复制图像或者扫描页面上的内容,可复制其中的文本.图片和表格的信息.在复制过程中,用户无需将图像或扫描页面转换为可编辑的格式,可以直接在ABBYY Fine ...
- 使用Camtasia来消除视频中的声音
大多数情况下,我们在录制电脑屏幕的时候都会把音频输出也一起录制下来,但也会有时候要后期进行重新配音,需要把事先一同录制的音频消除掉,今天小编来给大家说一说如何消除这种的视频声音. 首先打开Camtas ...
- mac下让iterm2记住远程ssh连接
brew安装sshpass brew install http://git.io/sshpass.rb 在根目录下建立passowrd目录用来管理密码,vim testserver 输入明文密码,保存 ...
- oracle整表数据被误删除之寻踪
问题描述 开发同事在在14点左右发现任务表task_info数据不正确,3个小时之前的数据消失了,数据截至时间11:38:27 问题分析 查询过dba_source,只找到一个删除该表的存储过程,而且 ...
- gsap基础一[from,to,fromTo]
学了几天基础了,感觉总算有点入了一个门的感觉啦,gasp不难,想想一年前我看着官网跟天文一样,今年真的进步很大,在外网发现学习的新世界, 自己的获取知识和查看api源码的能力也增强了许多,现在国内的气 ...
- jwt介绍
jwt原理 最简单理解:jwt本质就是, 把用户信息通过加密后生成的一个字符串 JWT的原则是在服务器身份验证之后,将生成一个JSON对象并将其发送回用户 { "UserName" ...