一、前言

最近在学习点云库,由于刚刚入门,很多东西也不是很了解,如果大家有什么问题,都可以跟我沟通交流。除了通过博客交流外,欢迎你加入我的QQ群(326866692),一起交流有关于机器学习、深度学习、计算机视觉的内容。目前我并未确定具体的研究方向,所以现在处于广泛涉猎阶段,希望我们能够一起沟通。

今天要分享的是PCL中的范围图像

二、RangeImage简介及代码解析

1、RangeImage介绍

RangeImage有人翻译成距离影像,有人翻译成范围影像。这并不重要,重要的是RangeImage的含义。

RangeImage是指将从图像采集器到场景中各点的距离值作为像素值的图像,它直接反应了景物可见表面的几何形状

2、全部代码

#include "stdafx.h"
#include <pcl/range_image/range_image.h>

void main() {
pcl::PointCloud<pcl::PointXYZ> pointCloud;

// Generate the data
for (float y = -0.5f; y <= 0.5f; y += 0.01f) {
for (float z = -0.5f; z <= 0.5f; z += 0.01f) {
pcl::PointXYZ point;
point.x = 2.0f - y;
point.y = y;
point.z = z;
pointCloud.points.push_back(point);
}
}
pointCloud.width = (uint32_t)pointCloud.points.size();
pointCloud.height = 1;

// We now want to create a range image from the above point cloud, with a 1deg angular resolution
float angularResolution = (float)(1.0f * (M_PI / 180.0f)); // 1.0 degree in radians
float maxAngleWidth = (float)(360.0f * (M_PI / 180.0f)); // 360.0 degree in radians
float maxAngleHeight = (float)(180.0f * (M_PI / 180.0f)); // 180.0 degree in radians
Eigen::Affine3f sensorPose = (Eigen::Affine3f)Eigen::Translation3f(0.0f, 0.0f, 0.0f);
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
float noiseLevel = 0.00;
float minRange = 0.0f;
int borderSize = 1;

pcl::RangeImage rangeImage;
rangeImage.createFromPointCloud(pointCloud, angularResolution, maxAngleWidth, maxAngleHeight,sensorPose, coordinate_frame, noiseLevel, minRange, borderSize);

std::cout << rangeImage << "\n";

system("pause");
}

 

三、代码分段解析

1.头文件

#include "stdafx.h"
#include <pcl/range_image/range_image.h>

2.生成点云数据

pcl::PointCloud<pcl::PointXYZ> pointCloud;

// Generate the data
for (float y = -0.5f; y <= 0.5f; y += 0.01f) {
for (float z = -0.5f; z <= 0.5f; z += 0.01f) {
pcl::PointXYZ point;
point.x = 2.0f - y;
point.y = y;
point.z = z;
pointCloud.points.push_back(point);
}
}
pointCloud.width = (uint32_t)pointCloud.points.size();
pointCloud.height = 1;

3.定义RangeImage参数

maxAngleWidth = 360和maxAngleHeight = 180表示我们正在模拟的范围传感器具有完整的360度周围视图。(注:范围图像将仅裁剪为自动观察到某些内容的区域)。

也可以通过减少值来节省一些计算。例如,对于180度视图朝前的激光扫描仪,可以观察到传感器后面没有点,maxAngleWidth = 180就足够了。

sensorPose将虚拟传感器的6DOF位置定义为roll = pitch = yaw = 0的原点。

coordinate_frame = CAMERA_FRAME告诉系统x面向右,y向下,z轴向前。另一种选择是LASER_FRAME,x面向前方,y位于左侧,z位于上方。

对于noiseLevel = 0,使用普通z缓冲区创建范围图像。然而,如果想平均落在同一个单元格中的点数,可以使用更高的值。0.05表示所有与最近点的最大距离为5cm的点用于计算范围。

如果minRange大于0,则将忽略所有更近的点。

borderSize大于0将在裁剪时在图像周围留下未观察到的点边框。

float angularResolution = (float)(1.0f * (M_PI / 180.0f));  //   1.0 degree in radians
float maxAngleWidth = (float)(360.0f * (M_PI / 180.0f)); // 360.0 degree in radians
float maxAngleHeight = (float)(180.0f * (M_PI / 180.0f)); // 180.0 degree in radians
Eigen::Affine3f sensorPose = (Eigen::Affine3f)Eigen::Translation3f(0.0f, 0.0f, 0.0f);
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
float noiseLevel = 0.00;
float minRange = 0.0f;
int borderSize = 1;

4.创建RangeImage

可视化的目的是为了让大家能够更好的看到效果。

注:这里的可视化是创建可视化变量,并开辟一个窗口来展示图像。在后面的代码才会显示点云文件。

pcl::RangeImage rangeImage;
rangeImage.createFromPointCloud(pointCloud, angularResolution, maxAngleWidth, maxAngleHeight,sensorPose, coordinate_frame, noiseLevel, minRange, borderSize);

std::cout << rangeImage << "\n";

执行结果如下:

header:

seq: 0 stamp: 0 frame_id:

points[]: 1360

width: 40

height: 34

sensor_origin_: 0 0 0

sensor_orientation_: 0 0 0 1

is_dense: 0

angular resolution: 1deg/pixel in x and 1deg/pixel in y.