PCL库学习

一.I/O

1.The PCD File Format

1)3D点云存储格式:

  • PLY - a polygon file format, developed at Stanford University by Turk et al
  • STL - a file format native to the stereolithography CAD software created by 3D Systems
  • OBJ - a geometry definition file format first developed by Wavefront Technologies
  • X3D - the ISO standard XML-based file format for representing 3D computer graphics data
  • and many others
2)PCD版本

在PCL1.0发布之前PCD有许多版本,用 PCD_Vx (e.g., PCD_V5, PCD_V6, PCD_V7, etc) 表示版本0.x for the PCD file.PCL官方接口版本为0.7 (PCD_V7).

3)文件格式头

# .PCD v.7 - Point Cloud Data file format
VERSION .7 
FIELDS x y z rgb  #给域命名
SIZE 4 4 4 4  #域的字节
TYPE F F F F #域的类型,目前可以是I,U,F分别表示: int8 (char), int16 (short), and int32 (int), uint8 (unsigned char), uint16 (unsigned short), uint32 (unsigned int),float types
COUNT 1 1 1 1 #表示每个域里面数据的维度,可以使用一个域来存储高维度的描述子
WIDTH 213  
HEIGHT 1  #点云组织形式,可以类似图片那样以宽和高的形式组织
VIEWPOINT 0 0 0 1 0 0 0  #视角 translation (tx ty tz) + quaternion (qw qx qy qz). 
POINTS 213  #点的数量	
DATA ascii  #点云存储格式,在0.7版本提供ascii and binary两种存储格式
0.93773 0.33763 0 4.2108e+06

The ascii format allows users to open up point cloud files and plot them using standard software tools like gnuplot or manipulate them using tools like sedawk, etc.


2.reading files

1)PCD阅读:

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);

法1:
pcl::io::loadPCDFile<pcl::PointXYZ> ("test_pcd.pcd", *cloud) == -1) 
法2:
pcl::PCLPointCloud2 cloud_blob;
pcl::io::loadPCDFile ("test_pcd.pcd", cloud_blob);
pcl::fromPCLPointCloud2 (cloud_blob, *cloud); //* convert from pcl/PCLPointCloud2 to pcl::PointCloud<T>
可以先把点云读入2进制文件PCLPointCloud2,loadPCDFile允许读二进制的文件(PCL1.x中才行),然后把二进制点云转换成特定格式的点云。

2)cmake格式

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(pcd_read)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (pcd_read pcd_read.cpp)
target_link_libraries (pcd_read ${PCL_LIBRARIES})
3)PCL风格的错误处理

  PCL_ERROR ("Couldn't read file test_pcd.pcd \n");
    return (-1);

3.Writing Point Cloud data to PCD files

1)PointXYZ是一种结构体

2)写文件:

struct PointXYZ
{
  float x;
  float y;
  float z;
};
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
  pcl::PointCloud<pcl::PointXYZ> cloud;
 cloud.width    = 5;
  cloud.height   = 1;
  cloud.is_dense = false;
  cloud.points.resize (cloud.width * cloud.height);

  for (size_t i = 0; i < cloud.points.size (); ++i)
  {
    cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
  }
  pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
3)遍历图片中的每一个点

  for (size_t i = 0; i < cloud->points.size (); ++i)
    std::cout << "    " << cloud->points[i].x
              << " "    << cloud->points[i].y
              << " "    << cloud->points[i].z << std::endl;
4.融合两个点云数据

1)融合点:

要求两片点云域的类型和个数一致

pcl::PointCloud<pcl::PointXYZ> cloud_a, cloud_b, cloud_c;
cloud_c  = cloud_a;
cloud_c += cloud_b;

2)融合数据域

要求两块点云,点的数量相同

  pcl::PointCloud<pcl::Normal> n_cloud_b;
  pcl::PointCloud<pcl::PointNormal> p_n_cloud_c;
  pcl::concatenateFields (cloud_a, n_cloud_b, p_n_cloud_c);
遍历类型: pcl :: PointCloud < pcl :: PointNormal >

 for (size_t i = 0; i < p_n_cloud_c.points.size (); ++i)
      std::cerr << "    " <<
        p_n_cloud_c.points[i].x << " " << p_n_cloud_c.points[i].y << " " << p_n_cloud_c.points[i].z << " " <<
        p_n_cloud_c.points[i].normal[0] << " " << p_n_cloud_c.points[i].normal[1] << " " << p_n_cloud_c.points[i].normal[2] << std::endl;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值