PCL点云转换为深度图并保存
pcl转深度图主要是createFromPointCloud()函数,参数配置基本可以不变,照这个写就行.保存主要是两个函数getVisualImage(),saveRgbPNGFile()没什么难度,头写对了就没问题
复制代码
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
using namespace std;
//main
int main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// 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(*cloud, angularResolution, maxAngleWidth, maxAngleHeight,
sensorPose, coordinate_frame, noiseLevel, minRange, borderSize);
std::cout << rangeImage << "\n";
float* ranges = rangeImage.getRangesArray();
unsigned char* rgb_image = pcl::visualization::FloatImageUtils::getVisualImage(ranges, rangeImage.width, rangeImage.height);
pcl::io::saveRgbPNGFile("ha.png", rgb_image, rangeImage.width, rangeImage.height);
复制代码
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
//关于rangeImage.createFromPointCloud()参数的解释 (涉及的角度都为弧度为单位) :
// cloud 为创建深度图像所需要的点云
//angularResolution 深度传感器的角度分辨率
//maxAngleWidth 深度传感器的水平最大采样角度
//maxAngleHeight 垂直最大采样角度
//sensorPose 设置的模拟传感器的位姿是一个仿射变换矩阵,默认为4*4的单位矩阵变换
//coordinate_frame 定义按照那种坐标系统的习惯 默认为CAMERA_FRAME
//noiseLevel 获取深度图像深度时,邻近点对查询点距离值的影响水平
//minRange 设置最小的获取距离,小于最小的获取距离的位置为传感器的盲区
//borderSize 设置获取深度图像边缘的宽度 默认为0
实际效果图
本文作者:callcall
本文链接:https://www.cnblogs.com/MorganMa/p/13967603.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步