(十五)从点云创建距离图像
以下代码实现从生成的点云数据创建距离图像。
range_image_creation.cpp
#include <pcl/range_image/range_image.h>
int main () {
pcl::PointCloud<pcl::PointXYZ> pointCloud;
//生成点云数据
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.push_back(point);
}
}
pointCloud.width = pointCloud.size();
pointCloud.height = 1;
/*定义我们要创建的范围图像的参数。*/
// 角分辨率为1度,这意味着由相邻像素表示的光束相差一度。
float angularResolution = (float) ( 1.0f * (M_PI/180.0f));
// maxAngleWidth=360和maxAngleHeight=180意味着我们正在模拟的范围传感器具有周围环境的完整360度视图。
float maxAngleWidth = (float) (360.0f * (M_PI/180.0f));
float maxAngleHeight = (float) (180.0f * (M_PI/180.0f));
// 将虚拟传感器的6DOF位置定义为原点处,滚转角=俯仰角=偏航角=0。
Eigen::Affine3f sensorPose = (Eigen::Affine3f)Eigen::Translation3f(0.0f, 0.0f, 0.0f);
// 告诉系统x向右,y向下,z轴向前。另一种选择是LASER_FRAME,x向前,y向左,z向上。
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
// 对于noiseLevel=0,使用normal z-buffer(//https://blog.csdn.net/jurbo/article/details/75007260)创建距离图像。
// 如果你想对落在同一单元格中的点进行平均,你可以使用更高的值。例如0.05意味着距离点5cm以内的所有点都用于计算均值。
float noiseLevel=0.00;
// 最小距离,距离传感器minRange以内的点被忽略
float minRange = 0.0f;
// borderSize大于0将在裁剪图像时在图像周围留下未观察到的点的边界。
int borderSize = 1;
/* 根据给定参数创建距离图像*/
pcl::RangeImage rangeImage;
rangeImage.createFromPointCloud(pointCloud, angularResolution, maxAngleWidth, maxAngleHeight,
sensorPose, coordinate_frame, noiseLevel, minRange, borderSize);
std::cout << rangeImage << "\n";
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(range_image_creation)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (range_image_creation range_image_creation.cpp)
target_link_libraries (range_image_creation ${PCL_LIBRARIES})
编译并运行:
./range_image_creation
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.