【译】PCL官网教程翻译(19):从深度图像中提取NARF特征 - How to extract NARF Features from a range image

本文主要是介绍【译】PCL官网教程翻译(19):从深度图像中提取NARF特征 - How to extract NARF Features from a range image,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

英文原文阅读

从深度图像中提取NARF特征

本教程演示如何从深度图像中提取位于NARF关键点位置的NARF描述符。可执行文件使我们能够从磁盘加载点云(如果没有提供,也可以创建点云),从中提取感兴趣的点,然后在这些位置计算描述符。然后,它在图像和3D查看器中可视化这些位置。

代码

首先,在您喜欢的编辑器中创建一个名为narf_feature_extract .cpp的文件,并在其中放置以下代码:

/* \作者Bastian Steder */#include <iostream>#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/keypoints/narf_keypoint.h>
#include <pcl/features/narf_descriptor.h>
#include <pcl/console/parse.h>typedef pcl::PointXYZ PointType;// --------------------
// -----参数-----
// --------------------
float angular_resolution = 0.5f;
float support_size = 0.2f;
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
bool setUnseenToMaxRange = false;
bool rotation_invariant = true;// --------------
// -----帮助-----
// --------------
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"<< "-s <float>   support size for the interest points (diameter of the used sphere - ""default "<<support_size<<")\n"<< "-o <0/1>     switch rotational invariant version of the feature on/off"<<               " (default "<< (int)rotation_invariant<<")\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, "-m") >= 0){setUnseenToMaxRange = true;std::cout << "Setting unseen values in range image to maximum range readings.\n";}if (pcl::console::parse (argc, argv, "-o", rotation_invariant) >= 0)std::cout << "Switching rotation invariant feature version "<< (rotation_invariant ? "on" : "off")<<".\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";}if (pcl::console::parse (argc, argv, "-s", support_size) >= 0)std::cout << "Setting support size to "<<support_size<<".\n";if (pcl::console::parse (argc, argv, "-r", angular_resolution) >= 0)std::cout << "Setting angular resolution to "<<angular_resolution<<"deg.\n";angular_resolution = pcl::deg2rad (angular_resolution);// ------------------------------------------------------------------// -----读取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){std::cerr << "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{setUnseenToMaxRange = true;std::cout << "\nNo *.pcd file given => Generating 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;pcl::RangeImage::Ptr 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 ();// --------------------------------------------// -----打开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::visualization::RangeImageVisualizer range_image_widget ("Range image");range_image_widget.showRangeImage (range_image);// --------------------------------// -----提取NARF关键点-----// --------------------------------pcl::RangeImageBorderExtractor range_image_border_extractor;pcl::NarfKeypoint narf_keypoint_detector;narf_keypoint_detector.setRangeImageBorderExtractor (&range_image_border_extractor);narf_keypoint_detector.setRangeImage (&range_image);narf_keypoint_detector.getParameters ().support_size = support_size;pcl::PointCloud<int> keypoint_indices;narf_keypoint_detector.compute (keypoint_indices);std::cout << "Found "<<keypoint_indices.points.size ()<<" key points.\n";// ----------------------------------------------// -----显示深度图像小部件中的关键点-----// ----------------------------------------------//for (size_t i=0; i<keypoint_indices.points.size (); ++i)//range_image_widget.markPoint (keypoint_indices.points[i]%range_image.width,//keypoint_indices.points[i]/range_image.width);// -------------------------------------// -----在3D查看器中显示关键点-----// -------------------------------------pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints_ptr (new pcl::PointCloud<pcl::PointXYZ>);pcl::PointCloud<pcl::PointXYZ>& keypoints = *keypoints_ptr;keypoints.points.resize (keypoint_indices.points.size ());for (size_t i=0; i<keypoint_indices.points.size (); ++i)keypoints.points[i].getVector3fMap () = range_image.points[keypoint_indices.points[i]].getVector3fMap ();pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> keypoints_color_handler (keypoints_ptr, 0, 255, 0);viewer.addPointCloud<pcl::PointXYZ> (keypoints_ptr, keypoints_color_handler, "keypoints");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints");// ------------------------------------------------------// -----提取感兴趣点的NARF描述符-----// ------------------------------------------------------std::vector<int> keypoint_indices2;keypoint_indices2.resize (keypoint_indices.points.size ());for (unsigned int i=0; i<keypoint_indices.size (); ++i) // This step is necessary to get the right vector typekeypoint_indices2[i]=keypoint_indices.points[i];pcl::NarfDescriptor narf_descriptor (&range_image, &keypoint_indices2);narf_descriptor.getParameters ().support_size = support_size;narf_descriptor.getParameters ().rotation_invariant = rotation_invariant;pcl::PointCloud<pcl::Narf36> narf_descriptors;narf_descriptor.compute (narf_descriptors);std::cout << "Extracted "<<narf_descriptors.size ()<<" descriptors for "<<keypoint_indices.points.size ()<< " keypoints.\n";//--------------------// -----主循环-----//--------------------while (!viewer.wasStopped ()){range_image_widget.spinOnce ();  // process GUI eventsviewer.spinOnce ();pcl_sleep(0.01);}
}

解释

在开始时,我们执行命令行解析,从磁盘读取点云(如果没有提供,也可以创建点云),创建一个深度图像并从中提取NARF关键点。所有这些步骤都已经在前面的教程NARF关键点提取中介绍过。
有趣的部分从这里开始:

...
std::vector<int> keypoint_indices2;
keypoint_indices2.resize(keypoint_indices.points.size());
for (unsigned int i=0; i<keypoint_indices.size(); ++i) // This step is necessary to get the right vector typekeypoint_indices2[i]=keypoint_indices.points[i];
...

这里我们将索引复制到作为特征输入的向量上。

...
pcl::NarfDescriptor narf_descriptor(&range_image, &keypoint_indices2);
narf_descriptor.getParameters().support_size = support_size;
narf_descriptor.getParameters().rotation_invariant = rotation_invariant;
pcl::PointCloud<pcl::Narf36> narf_descriptors;
narf_descriptor.compute(narf_descriptors);
std::cout << "Extracted "<<narf_descriptors.size()<<" descriptors for "<<keypoint_indices.points.size()<< " keypoints.\n";
...

这段代码实际计算描述符。它首先创建NarfDescriptor对象并给它输入数据(关键点索引和范围图像)。然后设置两个重要参数。支持大小,它决定计算描述符所在区域的大小,以及是否应该使用NARF描述符的旋转不变量(围绕正常旋转)版本。我们创建输出点云并执行实际计算。最后输出关键字个数和提取的描述符个数。这些数字可能不同。首先,描述符的计算可能会失败,因为深度图像中没有足够的点(分辨率太低)。或者可能在同一个地方有多个描述符,但是针对不同的主旋转。
得到的PointCloud包含类型Narf36(请参阅common/include/pcl/point_types.h),并将描述符存储为36个元素float和x、y、z、roll、pitch、yaw,以描述提取特征的本地坐标系。现在可以将描述符与曼哈顿距离(绝对差异的总和)进行比较。
剩下的代码只是在深度图像小部件和3D查看器中可视化关键点位置。

编译和运行程序

在CMakeLists.txt文件中添加以下行:

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)project(narf_feature_extraction)find_package(PCL 1.3 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable (narf_feature_extraction narf_feature_extraction.cpp)
target_link_libraries (narf_feature_extraction ${PCL_LIBRARIES})

完成可执行文件后,就可以运行它了。只需要:

$ ./narf_feature_extraction -m

这里使用一个存在空间中的矩形的自动生成点云。关键点在角落里。参数-m是必要的,因为矩形周围的区域是不可见的,因此系统无法将其检测为边框。选项-m将不可见区域更改为最大范围读数,从而使系统能够使用这些边界。
你也可以用硬盘上的点云文件试试:

$ ./narf_feature_extraction <point_cloud.pcd>

输出结果应该类似如下:
在这里插入图片描述

这篇关于【译】PCL官网教程翻译(19):从深度图像中提取NARF特征 - How to extract NARF Features from a range image的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1126981

相关文章

Python pandas库自学超详细教程

《Pythonpandas库自学超详细教程》文章介绍了Pandas库的基本功能、安装方法及核心操作,涵盖数据导入(CSV/Excel等)、数据结构(Series、DataFrame)、数据清洗、转换... 目录一、什么是Pandas库(1)、Pandas 应用(2)、Pandas 功能(3)、数据结构二、安

深度解析Spring Security 中的 SecurityFilterChain核心功能

《深度解析SpringSecurity中的SecurityFilterChain核心功能》SecurityFilterChain通过组件化配置、类型安全路径匹配、多链协同三大特性,重构了Spri... 目录Spring Security 中的SecurityFilterChain深度解析一、Security

深度解析Nginx日志分析与499状态码问题解决

《深度解析Nginx日志分析与499状态码问题解决》在Web服务器运维和性能优化过程中,Nginx日志是排查问题的重要依据,本文将围绕Nginx日志分析、499状态码的成因、排查方法及解决方案展开讨论... 目录前言1. Nginx日志基础1.1 Nginx日志存放位置1.2 Nginx日志格式2. 499

2025版mysql8.0.41 winx64 手动安装详细教程

《2025版mysql8.0.41winx64手动安装详细教程》本文指导Windows系统下MySQL安装配置,包含解压、设置环境变量、my.ini配置、初始化密码获取、服务安装与手动启动等步骤,... 目录一、下载安装包二、配置环境变量三、安装配置四、启动 mysql 服务,修改密码一、下载安装包安装地

电脑提示d3dx11_43.dll缺失怎么办? DLL文件丢失的多种修复教程

《电脑提示d3dx11_43.dll缺失怎么办?DLL文件丢失的多种修复教程》在使用电脑玩游戏或运行某些图形处理软件时,有时会遇到系统提示“d3dx11_43.dll缺失”的错误,下面我们就来分享超... 在计算机使用过程中,我们可能会遇到一些错误提示,其中之一就是缺失某个dll文件。其中,d3dx11_4

Python实现批量提取BLF文件时间戳

《Python实现批量提取BLF文件时间戳》BLF(BinaryLoggingFormat)作为Vector公司推出的CAN总线数据记录格式,被广泛用于存储车辆通信数据,本文将使用Python轻松提取... 目录一、为什么需要批量处理 BLF 文件二、核心代码解析:从文件遍历到数据导出1. 环境准备与依赖库

Linux下在线安装启动VNC教程

《Linux下在线安装启动VNC教程》本文指导在CentOS7上在线安装VNC,包含安装、配置密码、启动/停止、清理重启步骤及注意事项,强调需安装VNC桌面以避免黑屏,并解决端口冲突和目录权限问题... 目录描述安装VNC安装 VNC 桌面可能遇到的问题总结描js述linux中的VNC就类似于Window

Go语言编译环境设置教程

《Go语言编译环境设置教程》Go语言支持高并发(goroutine)、自动垃圾回收,编译为跨平台二进制文件,云原生兼容且社区活跃,开发便捷,内置测试与vet工具辅助检测错误,依赖模块化管理,提升开发效... 目录Go语言优势下载 Go  配置编译环境配置 GOPROXYIDE 设置(VS Code)一些基本

基于Python开发一个图像水印批量添加工具

《基于Python开发一个图像水印批量添加工具》在当今数字化内容爆炸式增长的时代,图像版权保护已成为创作者和企业的核心需求,本方案将详细介绍一个基于PythonPIL库的工业级图像水印解决方案,有需要... 目录一、系统架构设计1.1 整体处理流程1.2 类结构设计(扩展版本)二、核心算法深入解析2.1 自

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤