PCL系列——如何可视化深度图像
2016-03-30 21:20
260 查看
PCL系列
PCL系列——读入PCD格式文件操作PCL系列——将点云数据写入PCD格式文件
PCL系列——拼接两个点云
PCL系列——从深度图像(RangeImage)中提取NARF关键点
PCL系列——如何可视化深度图像
PCL系列——如何使用迭代最近点法(ICP)配准
PCL系列——如何逐渐地配准一对点云
PCL系列——三维重构之泊松重构
PCL系列——三维重构之贪婪三角投影算法
PCL系列——三维重构之移动立方体算法
说明
通过本教程,我们将会学会:如何通过两种方式可视化深度图像。
一种方式是在3D viewer中以点云的方式显示。(深度图来源于点云图)
一种方式是作为一幅图像显示(以不同的颜色表示不同的深度值)
操作
在VS2010 中新建一个文件 range_image_visualization.cpp,然后将下面的代码复制到文件中。参照之前的文章,配置项目的属性。设置包含目录和库目录和附加依赖项。
#include <iostream> //标准输入/输出 #include <boost/thread/thread.hpp> //多线程 #include <pcl/common/common_headers.h> #include <pcl/range_image/range_image.h> //深度图有关头文件 #include <pcl/io/pcd_io.h> //pcd文件输入/输出 #include <pcl/visualization/range_image_visualizer.h> //深度图可视化 #include <pcl/visualization/pcl_visualizer.h> #include <pcl/console/parse.h> //命令行参数解析 typedef pcl::PointXYZ PointType; //参数 全局 float angular_resolution_x = 0.5f, //角分辨率(单位弧度) angular_resolution_y = angular_resolution_x; pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME; //坐标帧(相机帧) bool live_update = true; //是否根据选择的视角更新深度图像 // 打印帮助信息 void printUsage (const char* progName) { std::cout << "\n\nUsage: "<<progName<<" [options] <scene.pcd>\n\n" << "Options:\n" << "-------------------------------------------\n" << "-rx <float> angular resolution in degrees (default "<<angular_resolution_x<<")\n" << "-ry <float> angular resolution in degrees (default "<<angular_resolution_y<<")\n" << "-c <int> coordinate frame (default "<< (int)coordinate_frame<<")\n" << "-l live update - update the range image according to the selected view in the 3D viewer.\n" << "-h this help\n" << "\n\n"; } /* void setViewerPose (pcl::visualization::PCLVisualizer& viewer, const Eigen::Affine3f& viewer_pose) { Eigen::Vector3f pos_vector = viewer_pose * Eigen::Vector3f(0, 0, 0); Eigen::Vector3f look_at_vector = viewer_pose.rotation () * Eigen::Vector3f(0, 0, 1) + pos_vector; Eigen::Vector3f up_vector = viewer_pose.rotation () * Eigen::Vector3f(0, -1, 0); viewer.setCameraPosition (pos_vector[0], pos_vector[1], pos_vector[2], look_at_vector[0], look_at_vector[1], look_at_vector[2], up_vector[0], up_vector[1], up_vector[2]); } */ // 主函数 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, "-l") >= 0) { live_update = true; std::cout << "Live update is on.\n"; } if (pcl::console::parse (argc, argv, "-rx", angular_resolution_x) >= 0) std::cout << "Setting angular resolution in x-direction to "<<angular_resolution_x<<"deg.\n"; if (pcl::console::parse (argc, argv, "-ry", angular_resolution_y) >= 0) std::cout << "Setting angular resolution in y-direction to "<<angular_resolution_y<<"deg.\n"; int tmp_coordinate_frame; if (pcl::console::parse (argc, argv, "-c", tmp_coordinate_frame) >= 0) { coordinate_frame = pcl::RangeImage::CoordinateFrame (tmp_coordinate_frame); std::cout << "Using coordinate frame "<< (int)coordinate_frame<<".\n"; } angular_resolution_x = pcl::deg2rad (angular_resolution_x); angular_resolution_y = pcl::deg2rad (angular_resolution_y); //读取pcd文件。如果没有指定文件,则创建样本云点 pcl::PointCloud<PointType>::Ptr point_cloud_ptr (new pcl::PointCloud<PointType>); pcl::PointCloud<PointType>& point_cloud = *point_cloud_ptr; 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) { std::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_); } else { std::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_x, angular_resolution_y, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f), scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size); //从点云创建出深度图 //打开一个3D图形窗口,并添加点云数据 pcl::visualization::PCLVisualizer viewer ("3D Viewer"); viewer.setBackgroundColor (1, 1, 1); //背景 pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> range_image_color_handler (range_image_ptr, 0, 0, 0); viewer.addPointCloud (range_image_ptr, range_image_color_handler, "range image"); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "range image"); //viewer.addCoordinateSystem (1.0f, "global"); //PointCloudColorHandlerCustom<PointType> point_cloud_color_handler (point_cloud_ptr, 150, 150, 150); //viewer.addPointCloud (point_cloud_ptr, point_cloud_color_handler, "original point cloud"); viewer.initCameraParameters (); //setViewerPose(viewer, range_image.getTransformationToWorldSystem ()); //PCL 1.6 出错 //以图像的形式显示深度图像,深度值作为颜色显示 pcl::visualization::RangeImageVisualizer range_image_widget ("Range image"); range_image_widget.showRangeImage (range_image); //主循环 while (!viewer.wasStopped ()) { range_image_widget.spinOnce (); viewer.spinOnce (); pcl_sleep (0.01); if (live_update) //根据3D显示,实时更新2D图像 { scene_sensor_pose = viewer.getViewerPose(); //获取观测姿势 range_image.createFromPointCloud (point_cloud, angular_resolution_x, angular_resolution_y, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f), scene_sensor_pose, pcl::RangeImage::LASER_FRAME, noise_level, min_range, border_size); //重新生成新的深度图 range_image_widget.showRangeImage (range_image); //重新显示 } } }
重新生成项目。
到改项目的Debug目录下,按住Shift,同时点击鼠标右键,在当前窗口打开CMD窗口。
在命令行中输入
range_image_visualization.exe,执行程序。结果如下图所示。
图1是命令行的显示,因为没有指定pcd文件,程序生成了点云数据。
图2是2D显示方式。
图3是3D显示方式。
2D显示方式会随3D显示的变化而自动变化。
参考
How to visualize a range image相关文章推荐
- photoshop学习笔记(一)2015-12-4【新浪云搬运】
- Shiro入门9:Shiro授权流程和三种授权方式和权限标识符规则
- 关于大型网站技术演进的思考(二)--存储的瓶颈(2)
- codeforces 636G
- java使用POI的导入导出
- 动态规划之DP中判断是否到达某一状态(最短时间是什么)?
- AndroidStudio项目交付(更新)到github最详细步骤
- 泛型的演化
- codeforces 489B
- EasyUI的load,reload,loadData
- CodeForces 366A- Dima and Guards
- 在centos上搭建svn服务器【新浪云搬运】
- 为设置最顶层LinearLayout的width和height会导致:运行时,程序无反应,并显示“已停止”
- 关于大型网站技术演进的思考(三)--存储的瓶颈(3)
- SharedPreferences
- C++作业2
- 20135202闫佳歆--week6 课本第三章学习笔记
- Linux学习之路:命令别名、历史记录和命令查找执行顺序
- js中的作用域链
- poj1611 并查集