目录

  • 1 从点云创建深度图像
  • 2 从深度图像中提取边界
  • 3 深度图像精通级实例解析:点云到深度图的变换与曲面重建

1 从点云创建深度图像

#include <pcl/range_image/range_image.h>int main (int argc, char** argv) {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.points.push_back(point);    //添加点云数据到点云对象}}pointCloud.width = (uint32_t) pointCloud.points.size();pointCloud.height = 1;//设置点云对象的头信息/************************************************************************************这段程序首先创建一组数据作为点云的数据内容,在设置文件头文件的信息,整个实现生成一个呈现矩形形状的点云。***************************************************************************/
//以1度为角分辨率,从上面创建的点云创建深度图像。float angularResolution = (float) (  1.0f * (M_PI/180.0f));
// 1度转弧度float maxAngleWidth     = (float) (360.0f * (M_PI/180.0f));
// 360.0度转弧度float maxAngleHeight    = (float) (180.0f * (M_PI/180.0f));
// 180.0度转弧度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";
}


这部分定义了创建深度图像时需要的设置参数,将角分辩率定义为1°,意味着由邻近的像素点所对应的每个光束之间相差 1°;maxAngleWidth =360和maxAngleHeight=180意味着,我们进行模拟的距离传感器对周围的环境拥有一个完整的360°视角,用户在任何数据集下都可以使用此设置,因为最终获取的深度图像将被裁剪到有空间物体存在的区域范围。但是,用户可以通过减小数值来节省一些计算资源,例如:当传感器后面没有可以观测的点时,一个水平视角为180°的激光 扫描仪,即maxAngleWidth=180就足够了,这样只需要观察距离传感器前面就可以了,因为后面没有需要观察的场景。sensorPose 定义了模拟深度图像获取传感器的6自由度位置,其原始值为横滚角roll、 俯仰角pitch、偏航角yaw都为 0。coordinate_frame=CAMERA_ _FRAME 说明系统的X轴是向右的,Y轴是向下的,Z轴是向前的。另外一个选择是LASER_FRAME,其X轴向前,Y轴向左,Z轴向上。noiseLevel=0 是指使用一个归一化的Z缓冲器来创建深度图像,但是如果想让邻近点集都落在同一个像素单元,用户可以设置一个较高的值,例如noiseLevel =0. 05可以理解为,深度距离值是通过查询点半径为5cm的圆内包含的点以平均计算而得到的。如果minRange>0,则所有模拟器所在位置半minRange内的邻近点都将被忽略,即为盲区。在裁剪图像时,如果borderSize>0,将在图像周围留下当前视点不可见点的边界。

2 从深度图像中提取边界

/* \author Bastian Steder */
#include <iostream>
#include <boost/thread/thread.hpp>
#include <pcl/range_image/range_image.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/range_image_visualizer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/features/range_image_border_extractor.h>
#include <pcl/console/parse.h>
typedef pcl::PointXYZ PointType;
// --------------------
// -----参数-----
// --------------------
float angular_resolution = 0.5f;
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
bool setUnseenToMaxRange = false;
// --------------
// -----帮助-----
// --------------
void
printUsage (const char* progName)
{std::cout << "\n\nUsage: "<<progName<<" [options] <scene.pcd>\n\n"<< "Options:\n"<< "-------------------------------------------\n"<< "-r <float>   angular resolution in degrees (default "<<angular_resolution<<")\n"<< "-c <int>     coordinate frame (default "<< (int)coordinate_frame<<")\n"<< "-m           Treat all unseen points to max range\n"<< "-h           this help\n"<< "\n\n";
}
// --------------
// -----主函数-----
// --------------
int
main (int argc, char** argv)
{// --------------------------------------// -----解析命令行参数-----// --------------------------------------if (pcl::console::find_argument (argc, argv, "-h") >= 0){printUsage (argv[0]);return 0;}if (pcl::console::find_argument (argc, argv, "-m") >= 0){setUnseenToMaxRange = true;cout << "Setting unseen values in range image to maximum range readings.\n";}int tmp_coordinate_frame;if (pcl::console::parse (argc, argv, "-c", tmp_coordinate_frame) >= 0){coordinate_frame = pcl::RangeImage::CoordinateFrame (tmp_coordinate_frame);cout << "Using coordinate frame "<< (int)coordinate_frame<<".\n";}if (pcl::console::parse (argc, argv, "-r", angular_resolution) >= 0)cout << "Setting angular resolution to "<<angular_resolution<<"deg.\n";angular_resolution = pcl::deg2rad (angular_resolution);// ------------------------------------------------------------------// -----读取pcd文件,如果没有给出pcd文件则创建一个示例点云-----// ------------------------------------------------------------------pcl::PointCloud<PointType>::Ptr point_cloud_ptr (new pcl::PointCloud<PointType>);pcl::PointCloud<PointType>& point_cloud = *point_cloud_ptr;pcl::PointCloud<pcl::PointWithViewpoint> far_ranges;Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ());std::vector<int> pcd_filename_indices = pcl::console::parse_file_extension_argument (argc, argv, "pcd");if (!pcd_filename_indices.empty ()){std::string filename = argv[pcd_filename_indices[0]];if (pcl::io::loadPCDFile (filename, point_cloud) == -1){cout << "Was not able to open file \""<<filename<<"\".\n";printUsage (argv[0]);return 0;}scene_sensor_pose = Eigen::Affine3f (Eigen::Translation3f (point_cloud.sensor_origin_[0],point_cloud.sensor_origin_[1],point_cloud.sensor_origin_[2])) *Eigen::Affine3f (point_cloud.sensor_orientation_);std::string far_ranges_filename = pcl::getFilenameWithoutExtension (filename)+"_far_ranges.pcd";if (pcl::io::loadPCDFile(far_ranges_filename.c_str(), far_ranges) == -1)std::cout << "Far ranges file \""<<far_ranges_filename<<"\" does not exists.\n";}else{cout << "\nNo *.pcd file given => Genarating example point cloud.\n\n";for (float x=-0.5f; x<=0.5f; x+=0.01f){for (float y=-0.5f; y<=0.5f; y+=0.01f){PointType point;  point.x = x;  point.y = y;  point.z = 2.0f - y;point_cloud.points.push_back (point);}}point_cloud.width = (int) point_cloud.points.size ();  point_cloud.height = 1;}// -----------------------------------------------// -----从点云创建深度图像-----// -----------------------------------------------float noise_level = 0.0;float min_range = 0.0f;int border_size = 1;boost::shared_ptr<pcl::RangeImage> range_image_ptr (new pcl::RangeImage);pcl::RangeImage& range_image = *range_image_ptr;   range_image.createFromPointCloud (point_cloud, angular_resolution, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f), scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);range_image.integrateFarRanges (far_ranges);if (setUnseenToMaxRange)range_image.setUnseenToMaxRange ();// --------------------------------------------// -----打开三维浏览器并添加点云-----// --------------------------------------------pcl::visualization::PCLVisualizer viewer ("3D Viewer");viewer.setBackgroundColor (1, 1, 1);viewer.addCoordinateSystem (1.0f);pcl::visualization::PointCloudColorHandlerCustom<PointType> point_cloud_color_handler (point_cloud_ptr, 0, 0, 0);viewer.addPointCloud (point_cloud_ptr, point_cloud_color_handler, "original point cloud");//PointCloudColorHandlerCustom<pcl::PointWithRange>   range_image_color_handler (range_image_ptr, 150, 150, 150);//viewer.addPointCloud (range_image_ptr, range_image_color_handler, "range image");//viewer.setPointCloudRenderingProperties (PCL_VISUALIZER_POINT_SIZE, 2, "range image");// -------------------------// -----提取边界-----// -------------------------pcl::RangeImageBorderExtractor border_extractor (&range_image);pcl::PointCloud<pcl::BorderDescription> border_descriptions;border_extractor.compute (border_descriptions);// ----------------------------------// -----在三维浏览器中显示点集-----// ----------------------------------pcl::PointCloud<pcl::PointWithRange>::Ptr border_points_ptr(new pcl::PointCloud<pcl::PointWithRange>), veil_points_ptr(new pcl::PointCloud<pcl::PointWithRange>), shadow_points_ptr(new pcl::PointCloud<pcl::PointWithRange>);pcl::PointCloud<pcl::PointWithRange>& border_points = *border_points_ptr, & veil_points = * veil_points_ptr, & shadow_points = *shadow_points_ptr;for (int y=0; y< (int)range_image.height; ++y){for (int x=0; x< (int)range_image.width; ++x){if (border_descriptions.points[y*range_image.width + x].traits[pcl::BORDER_TRAIT__OBSTACLE_BORDER])border_points.points.push_back (range_image.points[y*range_image.width + x]);if (border_descriptions.points[y*range_image.width + x].traits[pcl::BORDER_TRAIT__VEIL_POINT])veil_points.points.push_back (range_image.points[y*range_image.width + x]);if (border_descriptions.points[y*range_image.width + x].traits[pcl::BORDER_TRAIT__SHADOW_BORDER])shadow_points.points.push_back (range_image.points[y*range_image.width + x]);}}pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> border_points_color_handler (border_points_ptr, 0, 255, 0);viewer.addPointCloud<pcl::PointWithRange> (border_points_ptr, border_points_color_handler, "border points");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "border points");pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> veil_points_color_handler (veil_points_ptr, 255, 0, 0);viewer.addPointCloud<pcl::PointWithRange> (veil_points_ptr, veil_points_color_handler, "veil points");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "veil points");pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> shadow_points_color_handler (shadow_points_ptr, 0, 255, 255);viewer.addPointCloud<pcl::PointWithRange> (shadow_points_ptr, shadow_points_color_handler, "shadow points");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "shadow points");//-------------------------------------// -----在深度图像中显示点集-----// ------------------------------------pcl::visualization::RangeImageVisualizer* range_image_borders_widget = NULL;range_image_borders_widget =pcl::visualization::RangeImageVisualizer::getRangeImageBordersWidget (range_image, -std::numeric_limits<float>::infinity (), std::numeric_limits<float>::*******infinity (), false, border_descriptions, "Range image with borders" );                     // -------------------------------------//--------------------// -----主循环-----//--------------------while (!viewer.wasStopped ()){range_image_borders_widget->spinOnce ();viewer.spinOnce ();pcl_sleep(0.01);}
}

3 深度图像精通级实例解析:点云到深度图的变换与曲面重建

#include <pcl/range_image/range_image.h>
#include <pcl/range_image/range_image_planar.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
#include <pcl/console/print.h>
#include <pcl/surface/organized_fast_mesh.h>
#include <pcl/console/time.h>
#include <Eigen/StdVector>
#include <Eigen/Geometry>
#include <iostream>
#include <pcl/surface/impl/organized_fast_mesh.hpp>
#include <boost/thread/thread.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/vi**sualization/range_image_visualizer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/console/parse.h>using namespace pcl::console;int main (int argc, char** argv) {// Generate the dataif (argc<2){print_error ("Syntax is: %s input.pcd -w 640 -h 480 -cx 320 -cy 240 -fx 525 -fy 525 -type 0 -size 2\n", argv[0]);print_info ("  where options are:\n");print_info ("                     -w X = width of detph iamge ");return -1;}std::string filename = argv[1];/**************************************************************
定义从点云到深度图像转换时所需的参数,并可以接受用户命令行的参数设置。
***********************************************************/ int width=640,height=480,size=2,type=0;float fx=525,fy=525,cx=320,cy=240;parse_argument (argc, argv, "-w", width); //深度图像宽度parse_argument (argc, argv, "-h", height);//深度图像高度parse_argument (argc, argv, "-cx", cx);//光轴在深度图像上的x坐标parse_argument (argc, argv, "-cy", cy);//光轴在深度图像上的y坐标parse_argument (argc, argv, "-fx", fx);//水平方向焦距parse_argument (argc, argv, "-fy", fy);//垂直方向焦距parse_argument (argc, argv, "-type", type);//曲面重建时三角化的方式parse_argument (argc, argv, "-size", size);//曲面重建时的面片大小/**************************************************************
加载原始点云,同时创建RangeImagePlanar对象,利用改对象的函数createFromPointCloudWithFixedSize()进行深
度图像的生成,这里的参数除了上面用户设置的参数外,还需要提供相机成像的位姿,以及成像遵循的坐标系统。
***********************************************************/ pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);pcl::io::loadPCDFile (filename, *cloud);print_info ("Read pcd file successfully\n");Eigen::Affine3f sensorPose;sensorPose.setIdentity(); pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;float noiseLevel=0.00;//成像时模拟噪声水平float minRange = 0.0f;//成像时考虑阈值外的点pcl::RangeImagePlanar::Ptr rangeImage(new pcl::RangeImagePlanar);rangeImage->createFromPointCloudWithFixedSize(*cloud,width,height,cx,cy,fx,fy,sensorPose,coordinate_frame);std::cout << rangeImage << "\n";//convert unorignized point cloud to orginized point cloud end//可视化深度图像pcl::visualization::RangeImageVisualizer range_image_widget ("range image");range_image_widget.showRangeImage (*rangeImage);range_image_widget.setWindowTitle("range image");/**************************************************************完成从点云到深度图像的生成后,我们利用该深度图像作为输人,来使用曲面重建模块中的简单三角化类生成曲面模型。创建OrganizedFastMesh对象,该算法的输人参数有size,通过setTrianglePixelSize( )函数接口来改变,其控制重建曲面的精细程度。另外一个 参数是setTriangulationType( )方法设置的三角化的类型,是个枚举变量,包含三角形、四边形等。***********************************************************/ //triangulation based on range imagepcl::OrganizedFastMesh<pcl::PointWithRange>::Ptr tri(new pcl::OrganizedFastMesh<pcl::PointWithRange>);pcl::search::KdTree<pcl::PointWithRange>::Ptr tree (new pcl::search::KdTree<pcl::PointWithRange>);tree->setInputCloud(rangeImage);pcl::PolygonMesh triangles;tri->setTrianglePixelSize(size);tri->setInputCloud(rangeImage);tri->setSearchMethod(tree);tri->setTriangulationType((pcl::OrganizedFastMesh<pcl::PointWithRange>::TriangulationType)type);tri->reconstruct(triangles);boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("range image"));viewer->setBackgroundColor(0.5,0.5,0.5);viewer->addPolygonMesh(triangles,"tin");viewer->addCoordinateSystem();while (!range_image_widget.wasStopped ()&&!viewer->wasStopped()){range_image_widget.spinOnce ();pcl_sleep (0.01);viewer->spinOnce ();}
}

终端输入:

//1.pcd为要输入的点云,第二个用于控制重建曲面时的精细程度
./greedy_projection ../1.pcd pcd-size 2

输出:


原始点云:

PCL——4.深度图像相关推荐

  1. PCL深度图像(1)

    目前深度图像的获取方法有激光雷达深度成像法,计算机立体视觉成像,坐标测量机法,莫尔条纹法,结构光法等等,针对深度图像的研究重点主要集中在以下几个方面,深度图像的分割技术 ,深度图像的边缘检测技术 ,基 ...

  2. PCL点云与深度图像

    PCL点云与深度图像 1 RangeImage概念及相关算法 1.1 深度图像简介 1.2 PCL中RangeImage的相关类 2 从一个点云创建一个深度图像 3 从深度图像中提取边界 4 点云到深 ...

  3. 深度图像基础知识(一)

    深度图像(depth image)也被称为距离影像(range image),是指将从图像采集器到场景中各点的距离(深度)作为像素值的图像,它直接反映了景物可见表面的几何形状.深度图像经过坐标转换可以 ...

  4. 如何从点云创建深度图像,看这篇你就懂了(附详细代码)

    作者I Roar冷颜@CSDN 编辑I 3D视觉开发者社区 前言 目前,深度图像的获取方法有:激光雷达深度成像法.计算机立体视觉成像.坐标测量机法.莫尔条纹法.结构光法等.针对深度图像的研究重点主要集 ...

  5. 动态捕捉(四)深度图像基础知识

    第一部分: 深度图像(depth image)也被称为距离影像(range image),是指将从图像采集器到场景中各点的距离(深度)作为像素值的图像,它直接反映了景物可见表面的几何形状.深度图像经过 ...

  6. PCL点云生成深度图像

    https://www.cnblogs.com/li-yao7758258/p/6476046.html (1)点云到深度图与可视化的实现 区分点云与深度图本质的区别 1.深度图像也叫距离影像,是指将 ...

  7. 利用PCL库从点云数据生成深度图像及关键点提取

    利用PCL库从点云数据生成生成深度图像及关键点提取 利用PCL库从点云数据生成深度图像及关键点提取 本想利用标准点云数据库分割成若干块,利用标准点云数据生成深度图像作为数据库用来验证算法,目前效果不是 ...

  8. PCL 由点云生成深度图像

    前言:在电脑上的pcl1.8.0版本可能是由于版本问题,无法在窗口显示深度图像,但是深度图像确实是生成了的,可以通过一个API将深度图像保存为一个png格式的图片然后查看. 该函数如下: //save ...

  9. PCL深度图像(2)

    (1)点云到深度图与可视化的实现 区分点云与深度图本质的区别 1.深度图像也叫距离影像,是指将从图像采集器到场景中各点的距离(深度)值作为像素值的图像.获取方法有:激光雷达深度成像法.计算机立体视觉成 ...

最新文章

  1. 某程序员吐槽自己追求某字节HR,暧昧半年,见面后却被告知是普通朋友!心态已崩!网友:别追HR!道行太深!...
  2. C++文件读写 打开方式等比较全
  3. LeetCode Max Consecutive Ones
  4. SAP-ABAP三种定义嵌套型结构的方法
  5. 【揭秘】网易云视频点播加解密系统架构
  6. Android开发之git提交代码到GitHub仓库教程
  7. 详解JavaScript变量类型判断及domReady原理 写得很好
  8. 第89天:HTML5中 访问历史、全屏和网页存储API
  9. 在硅晶片上实现量子计算,英特尔可能改变了这项技术的未来
  10. 1006. Sign In and Sign Out (25)-PAT甲级真题
  11. 解决SurfaceView调用setZOrderOnTop(true)遮挡其他控件的问题
  12. Shell脚本学习-阶段十二-在CentOS 7上给一个网卡分配多个IP地址
  13. P2986 [USACO10MAR]伟大的奶牛聚集(思维,dp)
  14. excel文件被写保护怎么解除_u盘被写保护怎么解除_u盘怎么解除写保护状态
  15. MS-TS:免费微软TTS语音合成工具(一键合成导出MP3音频)
  16. 最好的输入法--陈桥五笔5.806(绿色可自动卸载版)
  17. Window10 和 Ubuntu20.04 双系统安装
  18. php中的乐观锁和悲观锁
  19. uni-app 170邀请加入群聊(二)
  20. 微信小程序开发时,下载node.js安装后出错误怎么办

热门文章

  1. php 5.5.1,PHP5.3.1 不再支持ISAPI
  2. python获取上个月最后一天_在Python中获取本月的最后一天
  3. oracle目录解析,Oracle目录分析与比较
  4. 软件工程导论 06章详细设计
  5. PyTorch 学习笔记(一):让PyTorch读取你的数据集
  6. 100分制的成绩转换(C语言)(查表法)
  7. ## CSP 201612-1 中间数(C语言)(100分)
  8. python 绘图中设置颜色对比强烈的组合
  9. VsCode crtl + 鼠标右键 python代码无法跳转
  10. 禁止logback输出状态信息