点云创建深度图像并保存为图片
博客参考:http://pointclouds.org/documentation/tutorials/range_image_creation.php#range-image-creation 和 https://blog.csdn.net/baidu_26408419/article/details/53912532
依据点云信息生成深度图像(投影定理和正交定理)
#include <pcl/io/png_io.h> #include <pcl/range_image/range_image.h> #include <pcl/visualization/pcl_visualizer.h> #include <pcl/visualization/common/float_image_utils.h> #include <pcl/visualization/range_image_visualizer.h> #include <Eigen/Core> using namespace Eigen; float angularResolution = (float)(0.1f * (M_PI / 180.0f)); // 1.0 degree in radians float maxAngleWidth = (float)(60.0f * (M_PI / 180.0f)); // 360.0 degree in radians float maxAngleHeight = (float)(45.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::LASER_FRAME; float noiseLevel = 0.00; float minRange = 0.0f; int borderSize = 1; pcl::RangeImage rangeImage; rangeImage.createFromPointCloud(*rangePoints, angularResolution, maxAngleWidth, maxAngleHeight, sensorPose, coordinate_frame, noiseLevel, minRange, borderSize);
显示或者保存深度图像
//可视化深度图 //pcl::visualization::RangeImageVisualizer range_image_widget("Range image"); //range_image_widget.showRangeImage(rangeImage);
float* ranges = rangeImage.getRangesArray(); unsigned char* rgb_image = pcl::visualization::FloatImageUtils::getVisualImage(ranges, rangeImage.width, rangeImage.height); pcl::io::saveRgbPNGFile("saveRangeImageRGB.png", rgb_image, rangeImage.width, rangeImage.height);