【PCL】(十五)从点云创建距离图像

(十五)从点云创建距离图像

以下代码实现从生成的点云数据创建距离图像。

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.

官方文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二进制人工智能

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值