【Range Image】 创建Range Image

1 介绍

范围图像是一种将点云数据转换为二维图像的表示形式。它将点云中的每个点映射到图像中的像素,每个像素表示了点在三维空间中的距离信息。范围图像的每个像素包含了点的深度信息,可以用来表示物体的形状和几何结构。范围图像通常用于进行深度感知和三维重建等任务。

范围图像在PCL中使用 pcl::RangeImage 类型表示,它包含了范围图像的像素数据以及相关的参数和方法。范围图像可以从点云数据中创建,并可以通过可视化工具进行可视化。

2 创建Range Image代码

#include <pcl/range_image/range_image.h>

#include <pcl/visualization/pcl_visualizer.h>

int main ()
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud(new pcl::PointCloud<pcl::PointXYZ>);

// 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->push_back(point);
        }
    }
    pointCloud->width = pointCloud->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";



    pcl::visualization::PCLVisualizer vis("cloud vis");
    pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> color_handler(rangeImage.makeShared(), 255, 255 ,255);
    vis.addPointCloud<pcl::PointWithRange>(rangeImage.makeShared(), color_handler, "range_image");
    vis.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "range_image");
    vis.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_REPRESENTATION, pcl::visualization::PCL_VISUALIZER_REPRESENTATION_SURFACE, "range_image");

    while(!vis.wasStopped())
    {
        vis.spinOnce();
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_45824067/article/details/134615914
今日推荐