目录

2.1 IO模块接口

2.2 PCD数据读写

(1) PCD数据解析

(2)PCD文件读写示例

2.3 PLY数据读写

(1)PLY数据解析

(2)PLY文件读写示例

2.4 OBJ数据读写

(1)OBJ数据解析

(2)OBJ文件读写示例

2.5 VTK数据读写

(1)VTK数据解析

(2)VTK文件读写示例

2.6 保存为PNG


2.1 IO模块接口

参考文章:PCL函数库摘要——IO模块_pcl/io_悠缘之空的博客-CSDN博客

(1)Class pcl::FileReader

类FileReader定义了PCD文件的读取接口,主要用做其他读取类的父类。

(2)Class pcl::FileWriter

类FileWriter 与 FileReader对应,是写人PCD文件的类接口定义,可以作为其它写入类的父类。

(3)Class pcl::Grabber

类Grabber为PCL1.X对应的设备驱动接口的基类定义。

(4)Class openni_wrapper::OpenNIDevice

类OpenNIDevice定义OpenNI设备的基类,继承该基类可以实现不同的OpenNI设备子类,用于获取包括红外数据、RGB数据、深度图像数据等。

(5)Class openni_wrapper::DeviceKinect

(6)Class openni_wrapper::DevicePrimesense

(7)Class openni_wrapper::DeviceXtionPro

以上3个类分别封装了Kinect,Primesense,XtionPro相关设备操作和数据获取操作实现,其详细接口参考其父类OpenNIDevice的关键函数说明。

(8)Class openni_wrapper::DeviceONI

封装了利用ONI文件回放虚拟类kinect设备的操作和数据获取操作实现,其详细接口参考其父类OpenNIDevice的关键函数说明。

(9)Class openni_wrapper::OpenNIDriver

类OpenNIDriver采用单例模式实现对底层驱动的封装,里面包含一xn::Context对象,提供给所有设备使用。该类提供了枚举和访问所有设备的方法实现。

(10)Class openni_wrapper::OpenNIException

类OpenNIException封装一般的异常处理实现。

(11)Class openni_wrapper::Image

类Image是简单的图像数据封装基类。

(12)Class openni_wrapper::ImageBayerGRBG

(13)Class openni_wrapper::ImageRGB24

(14)Class openni_wrapper::ImageYUV422 Class Reference

以上3个类分别实现了对原始数据 BayerGRBG ,RGB24、YUV422到图像转化接口,详细参考其父类关键函数说明。

(15)Class pcl::OpenNIGrabber

类OpenNIGrabber 实现对OpenNI设备(例如Primesense PSDK,MicrosoftKinect,Asus XTion Pro/Live)数据的采集接口,详细参考其父类Grabber 关键函数说明。

(16)Class pcl::PCDReader

(17)Class pcl::PLYReader

以上两个类分别是PCD、PLY文件格式读入接口的实现,详细参考其父类pcl: :FileReader。

(18)Class pcl::PLYWriter

(19)Class pcl::PCDWriter

以上两个类分别是PCD、PLY文件格式写出接口的实现,详细参考其父类pcl: :FileWriter。

(20)Class pcl::io::IOException

类pcl::io::IOException 是I/O相关的异常处理接口实现,详细参考其父类PCLEx-ception。

(21)I/O模块其他关键成员

2.2 PCD数据读写

(1) PCD数据解析

# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z _
SIZE 4 4 4 1
TYPE F F F U
COUNT 1 1 1 4
WIDTH 112099
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 112099
DATA binary

            I:可表示int8,int16,int32。
            U:可表示uint8,unit16,uint32。
            F:表示float(上图所用的为浮点类型)。

(2)PCD文件读写示例

cmake_minimum_required(VERSION 2.6)
project(pcd)find_package(PCL 1.10 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable(pcd pcd.cpp)target_link_libraries (pcd ${PCL_LIBRARIES})install(TARGETS pcd RUNTIME DESTINATION bin)
#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>using namespace std;int main()
{pcl::PCDReader reader;pcl::PCLPointCloud2 org;pcl::io::loadPCDFile("../pcdfile.pcd",org);for(auto &f : org.fields)cout << f.name;pcl::PointCloud<pcl::PointXYZ> cloud;pcl::fromPCLPointCloud2<pcl::PointXYZ>(org,cloud);pcl::PCDWriter writer;pcl::io::savePCDFileBinaryCompressed("../savepcdfile.pcd",cloud);pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer);viewer->setWindowName("PCDFile");viewer->addPointCloud(cloud.makeShared());while (!viewer->wasStopped()){viewer->spinOnce(100);}return 0;
}

2.3 PLY数据读写

(1)PLY数据解析

典型的PLY文件结构:

ply
format ascii 1.0
element vertex 14806
property float x
property float y
property float z
property float nx
property float ny
property float nz
element face 0
property list uchar int vertex_indices
end_header
0.91441 -0.536438 0.822624 -0.0442205 -0.930906 0.362575
0.933494 -0.545228 0.820276 0.073409 -0.981856 0.174844
...

(2)PLY文件读写示例

cmake_minimum_required(VERSION 2.6)
project(ply)find_package(PCL 1.10 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable(ply ply.cpp)target_link_libraries (ply ${PCL_LIBRARIES})install(TARGETS ply RUNTIME DESTINATION bin)
#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/io/ply_io.h>
#include <pcl/visualization/pcl_visualizer.h>using namespace std;int main()
{pcl::PCLPointCloud2 cloud;pcl::io::loadPLYFile("../ply.ply",cloud);pcl::PLYReader reader;pcl::PLYWriter writer;pcl::PointCloud<pcl::PointXYZ> cloud1;pcl::fromPCLPointCloud2<pcl::PointXYZ>(cloud,cloud1);pcl::io::savePLYFile("saveply.ply",cloud,Eigen::Vector4f::Zero (),Eigen::Quaternionf::Identity (),true);pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer);viewer->setWindowName("PLYFile");pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> color(cloud1.makeShared(), "y");viewer->addPointCloud(cloud1.makeShared(),color);viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,2);while(!viewer->wasStopped())viewer->spinOnce(100);return 0;
}

2.4 OBJ数据读写

(1)OBJ数据解析

mtllib cube.mtl
g default
v -0.500000 -0.500000 0.500000
v 0.500000 -0.500000 0.500000
v -0.500000 0.500000 0.500000
v 0.500000 0.500000 0.500000
v -0.500000 0.500000 -0.500000
v 0.500000 0.500000 -0.500000
v -0.500000 -0.500000 -0.500000
v 0.500000 -0.500000 -0.500000
vt 0.001992 0.001992
vt 0.998008 0.001992
vt 0.001992 0.998008
vt 0.998008 0.998008
...

mtllib:代表材质库,通常指向到某个mtl文件

其他参考:obj格式解析_obj格式详解_风翼冰舟的博客-CSDN博客

(2)OBJ文件读写示例

cmake_minimum_required(VERSION 2.6)
project(obj)find_package(PCL 1.10 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable(obj obj.cpp)target_link_libraries (obj ${PCL_LIBRARIES})install(TARGETS obj RUNTIME DESTINATION bin)
#include <iostream>#include <pcl/point_cloud.h>
#include <pcl/io/obj_io.h>
#include <pcl/visualization/pcl_visualizer.h>using namespace std;int main()
{pcl::PolygonMesh mesh;pcl::PCLPointCloud2 cloud;pcl::TextureMesh tmesh;#if 0pcl::io::loadOBJFile("../obj.obj",cloud);pcl::io::loadOBJFile("../obj.obj",mesh);pcl::io::loadOBJFile("../obj.obj",tmesh);
#elsepcl::OBJReader objreader;objreader.read("../obj.obj",cloud);objreader.read("../obj.obj",mesh);objreader.read("../obj.obj",tmesh);
#endifpcl::io::saveOBJFile("../saveobj.obj",mesh);pcl::PointCloud<pcl::PointXYZ> cloudxyz;pcl::fromPCLPointCloud2<pcl::PointXYZ>(cloud,cloudxyz);pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer);viewer->setWindowName("OBJFile");pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> color(cloudxyz.makeShared(), "z");viewer->addPointCloud(cloudxyz.makeShared(),color);viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,2);viewer->addPolygonMesh(mesh);while(!viewer->wasStopped())viewer->spinOnce(100);return 0;
}

2.5 VTK数据读写

(1)VTK数据解析

# vtk DataFile Version 2.0
vtk output
ASCII
DATASET POLYDATA
POINTS 2312 float
0.263107 0 0.425176 0.33131 0 0.374478 0.389942 0 0.312962
0.43731 0 0.242405 0.472045 0 0.164845 0.493143 0 0.0825238 

(2)VTK文件读写示例

cmake_minimum_required(VERSION 2.6)
project(vtkfile)find_package(PCL 1.10 REQUIRED)
find_package(VTK REQUIRED)include(${VTK_USE_FILE})
link_directories(${VTK_LIBRARY_DIRS})include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable(vtkfile vtkfile.cpp)target_link_libraries (vtkfile ${PCL_LIBRARIES} ${VTK_LIBRARIES})
target_link_libraries (vtkfile ${VTK_LIBRARIES})install(TARGETS vtkfile RUNTIME DESTINATION bin)
#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/io/vtk_io.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/io/obj_io.h>using namespace std;int main()
{pcl::PCLPointCloud2 cloud;pcl::PolygonMesh mesh,mesh1,mesh2;#if 0pcl::io::loadPolygonFile("../vtk.vt",mesh);
#elsepcl::io::loadPolygonFileVTK("../vtk.vtk",mesh);pcl::io::loadPolygonFileVTK("../vtk.vtk",mesh2);
#endifpcl::PointCloud<pcl::PointXYZ> cloudxyz;pcl::fromPCLPointCloud2<pcl::PointXYZ>(mesh.cloud,cloudxyz);pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer);viewer->setWindowName("VTKFile");pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> color(cloudxyz.makeShared(),"y");viewer->addPointCloud(cloudxyz.makeShared(),color);viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,3);viewer->addPolygonMesh(mesh);while(!viewer->wasStopped())viewer->spinOnce(100);return 0;
}

2.6 保存为PNG

#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/png_io.h>
#include <pcl/visualization/pcl_visualizer.h>using namespace std;int main()
{pcl::PCDReader reader;pcl::PCLPointCloud2 org;pcl::io::loadPCDFile("../cow.pcd",org);for(auto &f : org.fields)cout << f.name << endl;pcl::PointCloud<pcl::PointXYZ> cloud;pcl::fromPCLPointCloud2<pcl::PointXYZ>(org,cloud);pcl::io::savePNGFile("../savepng.png",cloud,"rgb");pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> color(cloud.makeShared(), "z");pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer);viewer->setWindowName("savePNG");viewer->addPointCloud(cloud.makeShared(),color);viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,2);while(!viewer->wasStopped())viewer->spinOnce(100);return 0;
}}

PCL点云库(2) — IO模块相关推荐

  1. PCL点云库安装及学习(2021.7.28)

    PCL点云库学习 2021.7.28 1.PCL简介 2.Win10系统下PCL环境配置 2.1 前提环境(Win10 64位+Visual Studio 2015) 2.2 方式一:源码编译(过程繁 ...

  2. 编译安装PCL点云库,Kinect2驱动,乐视Astra相机驱动

    编译安装PCL点云库 安装方法一 3d点云安装 apt-cache cearch pcl 安装 sudo apt install 上面查出来的 opencv不建议用以上方法因为需要 安装 opencv ...

  3. PCL点云库:ICP算法

    ICP(Iterative Closest Point迭代最近点)算法是一种点集对点集配准方法.在VTK.PCL.MRPT.MeshLab等C++库或软件中都有实现,可以参见维基百科中的ICP Alg ...

  4. PCL点云库(Point Cloud Library)简介

    PCL点云库(Point Cloud Library)简介 什么是PCL PCL(Point Cloud Library)是在吸收了前人点云相关研究基础上建立起来的大型跨平台开源C++编程库,它实现了 ...

  5. 《PCL点云库学习VS2010(X64)》Part 34 旋转平移矩阵用法

    <PCL点云库学习&VS2010(X64)>Part 34 旋转平移矩阵用法 1.变换与投影矩阵讲解: https://en.wikipedia.org/wiki/Transfor ...

  6. Kinectfusion开源实现_配置Kinfu环境_Cmake编译PCL点云库_Kinect3D重建

    Kinectfusion开源实现-配置Kinfu环境-Cmake编译PCL点云库 注: 1.此教程在win10_x64.VS2010_x86环境下,配置运行Kinfu.编译PCL点云库成功,其他环境也 ...

  7. 《PCL点云库学习VS2010(X64)》Part 41 图形学领域的关键算法及源码链接

    <PCL点云库学习&VS2010(X64)>Part 41 图形学领域的关键算法及源码链接 原文链接: Conference papers Graphics Conference ...

  8. ubuntu pcl 点云库使用

    pcl 点云库使用(cmakeList.xtx) cmake_minimum_required(VERSION 2.6) project(pcl_test)   find_package(PCL 1. ...

  9. 《PCL点云库学习VS2010(X64)》Part 45 点云压缩算法—扫描线(DouglasPeuckerAlgorithm)

    <PCL点云库学习&VS2010(X64)>Part 45 点云压缩算法-扫描线(DouglasPeuckerAlgorithm) 道格拉斯-普克算法主要应用有点云滤波.点云压缩. ...

最新文章

  1. 如何替换 Ubuntu 11.10 登录屏幕背景和logo
  2. python字符串逆序_python之字符串逆序
  3. 开发者强势围观!Gartner 发布 2020 年十大战略科技发展趋势
  4. 云搜索服务在APP搜索场景的应用
  5. PowerDesigner生成的建表脚本中如何把对象的双引号去掉
  6. java学习路径1--转自byr
  7. 离线仿真调试,加快项目进度!
  8. e5服务器系列天梯图,最新的至强e5处理器天梯图
  9. Alexa 世界排名推进工具--阿雷克斯(转)
  10. html5分镜头脚本范例,分镜头脚本范例
  11. NLP - Gensim
  12. 使用VNC连接树莓派4b如何全屏1080p分辨率,一次更改永久有效!
  13. C++头文件和源文件的编译过程
  14. c++面试 掌握的东西总结
  15. CUDA:CUDA out of memory. Tried to allocate 100.00 MiB (GPU 0; 15.78 GiB total capacity; 14.24 GiB al
  16. 【进阶实战】使用PaddlePaddle测试土壤有机质预测含氮量
  17. 无线网卡插上电脑没反应的解决办法
  18. 百度、豆丁、道客巴巴文库免费下载
  19. 我的周刊(第017期)
  20. 富文本编辑器iceEditor中上传word并回显

热门文章

  1. python 执行shell_从python执行Shell脚本与变量
  2. Visual Studio 2017 企业版密匙
  3. 【Android Camera2】玩转图像数据 -- NV21图像旋转,镜像,转rgba代码分析,性能优化
  4. 吴恩达 深度神经网络,吴恩达神经网络课程
  5. mplayer-2.3节:视频输出设备 .
  6. 98岁国学大师自曝只喜欢18岁的年轻美女
  7. 为什么打印还要另存为_为什么打印时会出现另存为保存文件
  8. 如何更好地理解中间件和洋葱模型
  9. 【传送门】 Linux软件安装合集
  10. 采集人物经历来佐证子平术