本节将显示如何提取出NARF关键点通过NARF描述器从一个深度图里面。

以下是一段代码

#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/keypoints/narf_keypoint.h>
#include <pcl/features/narf_descriptor.h>
#include <pcl/console/parse.h>typedef pcl::PointXYZ PointType;// --------------------
// -----Parameters-----
// --------------------
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;// --------------
// -----Help-----
// --------------
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]);
}// --------------
// -----Main-----
// --------------
int
main (int argc, char** argv)
{// --------------------------------------// -----Parse Command Line Arguments-----// --------------------------------------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";}if (pcl::console::parse (argc, argv, "-o", rotation_invariant) >= 0)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);cout << "Using coordinate frame "<< (int)coordinate_frame<<".\n";}if (pcl::console::parse (argc, argv, "-s", support_size) >= 0)cout << "Setting support size to "<<support_size<<".\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);// ------------------------------------------------------------------// -----Read pcd file or create example point cloud if not given-----// ------------------------------------------------------------------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){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;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;}// -----------------------------------------------// -----Create RangeImage from the PointCloud-----// -----------------------------------------------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 ();// --------------------------------------------// -----Open 3D viewer and add point cloud-----// --------------------------------------------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 ());// --------------------------// -----Show range image-----// --------------------------pcl::visualization::RangeImageVisualizer range_image_widget ("Range image");range_image_widget.showRangeImage (range_image);// --------------------------------// -----Extract NARF keypoints-----// --------------------------------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";// ----------------------------------------------// -----Show keypoints in range image widget-----// ----------------------------------------------//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);// -------------------------------------// -----Show keypoints in 3D viewer-----// -------------------------------------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");// ------------------------------------------------------// -----Extract NARF descriptors for interest points-----// ------------------------------------------------------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);cout << "Extracted "<<narf_descriptors.size ()<<" descriptors for "<<keypoint_indices.points.size ()<< " keypoints.\n";//--------------------// -----Main loop-----//--------------------while (!viewer.wasStopped ()){range_image_widget.spinOnce ();  // process GUI eventsviewer.spinOnce ();pcl_sleep(0.01);}
}

一开始我们做的是命令行解析,从磁盘中读取点云文件,创建一个深度图,把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);
cout << "Extracted "<<narf_descriptors.size()<<" descriptors for "<<keypoint_indices.points.size()<< " keypoints.\n";

这个代码是描述器里面的计算部分。它先第一步创造了NarfDescriptor这个对象,然后把它作为输入值,然后有两个很重要的参数被设置了。支持的尺寸,决定了描述器计算的面积,如果NARF描述器里面的旋转不变量会被使用的话。接下去我们创造了输出点云然后做实际的计算。最后,我们输出了关键点的数量和导出描述器的数量。这个数量将会改变。有可能,它会发生计算失败的情况,因为没有足够的点在深度图像里面。或者可能会有多重描述器在同一个地方,虽然属于不同的方向域。

最终结果的点云包含了Narf26的类型。下面的代码把关键点的位置在深度图控件里面可视化出来,还有一个是在3D viewer里面可视化出来。

然后我们运行

./narf_feature_extraction -m

这将自动生成矩形浮动的点云。关键点会在角上被察觉。参数-m是必要的,因为矩形周围的区域是看不到的因此系统是不会把它看做是一个角。-m的选项改变不可见的区域扩大深度的读取范围,从而使系统可以用到那些角

你也可以让这个程序读取一个点云文件

./narf_feature_extraction <point_cloud.pcd>


从一个深度图里面导出NARF特征相关推荐

  1. 从深度图里面导出边界

    这次我们将学着怎么从一个深度图里面导出边界.我们对3种不同种类的点很感兴趣:物体的边框的点,阴影边框点,和面纱点(在障碍物边界和阴影边界),这是一个很典型的现象在通过雷达获取的3D深度. 下面是代码 ...

  2. 假设一个计算机系统有如下性能特征,2009级计算机科学与技术本科班中期试题...

    操作系统中期试题 1.设内存有三道程序A.B.C,并按A.B.C的优先次序执行,其CPU计算和I/O操作的时间如表1所示.试画出多道程序运行的时间关系图(调度程序执行的时间忽略不计),完成这三道程序共 ...

  3. KDD 2022 | 深度图神经网络中的特征过相关:一个新的视角

    目录 前言 1 引言 2 背景和相关工作 2.1 GNN 2.2 相关工作 3 Preliminary Study 3.1 过相关和过平滑 3.2 过相关分析 3.2.1 传播导致更高的相关性 3.2 ...

  4. NARF 特征点提取

    参考博客:https://www.cnblogs.com/ironstark/p/5051533.html 关键点检测本质上来说,并不是一个独立的部分,它往往和特征描述联系在一起,再将特征描述和识别. ...

  5. AI企业下一个使命:让生物特征数据使用走向阳光透明

    来源:亿欧网 摘要:时隔一年,生物特征识别技术不断被完善,公众的生物特征数据仍然每天被传感器收集汇总,但是对于生物特征数据的收集.储存.使用和流通仍然是半遮半掩的灰色区域,各方好像都等着导火索的出现. ...

  6. 强烈推荐!分享一个持续连载的《特征工程小锦囊》项目,代码已开源!

    随着我们在机器学习.数据建模.数据挖掘分析这条发展路上越走越远,其实越会感觉到特征工程的重要性,平时我们在很多地方都会看到一些很好的特征工程技巧,但是都会是一个完整项目去阅读,虽然说这样子也可以学习挖 ...

  7. 从一个点云里面创建一个深度图

    这次,我们将显示如何从一个点云和一个给定的传感器来创造深度图.下面的代码,创建了一个在观察者前面的矩形. #include <pcl/range_image/range_image.h> ...

  8. oracle表中一个字段内容导出到磁盘上

    有没有遇到过这样的问题, 系统设计的时候,会把一些内容比较大的文本内容存入到表中(oracle longe类型最大可以存放2G的文本) 刚开始也许不会有什么问题,但是时间长了,数据量大了,经常频繁的i ...

  9. 使用PHPExcel类库编写一个快捷的导出函数

    工作需要,也因为之前编写的一个导出CSV文件,竟然不支持生僻字(可能是编码问题),算是一个升级版吧. 函数优点: 参数简洁明了,基本一看就懂: 支持无限列,看了一些别人的代码没看到支持的: 满足基本导 ...

最新文章

  1. 拖链电缆 机器人电缆_尼龙拖链在机器中起着电缆的作用
  2. php7 根据日期算星座,php根据日期判断星座的函数分享
  3. 看见到洞见之引子(二)机器学习算法
  4. 【openjudge】【字符串+模拟】1777:文件结构“图”
  5. 伯努利分布方差_学计量经济学,你应该知道的六种6个概率分布
  6. FPGA入门的必经之路(一)
  7. matlab 模态,用matlab做模态分析
  8. 福禄克FLUKE 9142/9143/9144/9170/9771/9173-A-P-256计量干井炉技术指标
  9. 中国八横八纵大容量光纤通信网——世界级光纤通信网
  10. zic - 时区编辑器
  11. 【社区图书馆】《网络工程师的Python之路:网络运维自动化实战(第2版)》
  12. 电子计算机的加减乘除叫做什么,计算机中加减乘除叫什么键
  13. caj双击没反应的解决方法
  14. C++ 头文件的引用
  15. 2019 年终回顾:不忘初心,负重前行
  16. GPS卫星坐标用计算机计算,GPS卫星位置的计算
  17. 关于vscode安装包下载太慢解决方法(详解)
  18. 如何把电脑的文件同步到云盘
  19. 几个好用Maven 镜像仓库地址
  20. 从中关村到纳斯达克,龚宇的奇异8年与爱奇艺的全新时代

热门文章

  1. SrpingMVC 映射方法中参数之value,param,同时使用出现的问题
  2. String、StringBuilder、StringBuffer的区别
  3. 无法删除所有指定的值_AutoCAD所有系统变量大全
  4. php 编写mysql_php编写数据写入mysql问题
  5. python django图书管理系统_Python框架:Django写图书管理系统(LMS)
  6. 字符串去重_文件数据去重示例
  7. python树莓派编程_python树莓派编程
  8. python圆面积函数_Python基础函数必学
  9. FFmpeg在Ubuntu的安装以及教程~~~
  10. java时间聚类_mongodb 按照时间聚类 java