zoukankan      html  css  js  c++  java
  • PCL点云转换为深度图并保存

    pcl转深度图主要是createFromPointCloud()函数,参数配置基本可以不变,照这个写就行.保存主要是两个函数getVisualImage(),saveRgbPNGFile()没什么难度,头写对了就没问题

    #include <stdio.h>
    #include <stdlib.h>
    #include <pcl/point_types.h>
    #include <pcl/io/pcd_io.h>
    #include <pcl/io/ply_io.h>
    #include <pcl/features/normal_3d.h>
    #include <pcl/filters/voxel_grid.h>
    #include <pcl/filters/extract_indices.h>
    #include <pcl/filters/statistical_outlier_removal.h>
    #include <pcl/filters/conditional_removal.h>
    #include <pcl/visualization/pcl_visualizer.h>
    #include <pcl/common/transforms.h>
    #include <pcl/range_image/range_image.h>
    #include <pcl/io/png_io.h>
    #include <pcl/visualization/common/float_image_utils.h>
    #include<iostream>
    #include<cstdlib>
    #include<ctime>
    using namespace std;
    
    //main
    int main(int argc, char** argv)
    {
    	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    
    #pragma region create_range_image
    	// 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 << "
    ";
    	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);
    #pragma endregion
    
    	//关于rangeImage.createFromPointCloud()参数的解释 (涉及的角度都为弧度为单位) :
    	// cloud 为创建深度图像所需要的点云
    	//angularResolution 深度传感器的角度分辨率
    	//maxAngleWidth 深度传感器的水平最大采样角度
    	//maxAngleHeight 垂直最大采样角度
    	//sensorPose 设置的模拟传感器的位姿是一个仿射变换矩阵,默认为4*4的单位矩阵变换
    	//coordinate_frame 定义按照那种坐标系统的习惯  默认为CAMERA_FRAME
    	//noiseLevel 获取深度图像深度时,邻近点对查询点距离值的影响水平
    	//minRange 设置最小的获取距离,小于最小的获取距离的位置为传感器的盲区
    	//borderSize 设置获取深度图像边缘的宽度 默认为0
    

    实际效果图

  • 相关阅读:
    JS日期比较,使用正则表达式转换
    Using SQL*Loader to create an external table
    USACO试题beads的两种解法
    activiti5学习资料(5.12版本流程图的生成)
    黑马程序员_day20_Map集合
    开发者使用JasperReport——不同数据源之Map数据源
    给自己科谱:控制字符
    507 Jill Rides Again
    探讨工作流能给公司带来的几点益处
    ubuntu linux安装双系统的方法Win7、XP下均可
  • 原文地址:https://www.cnblogs.com/MorganMa/p/13967603.html
Copyright © 2011-2022 走看看