• pcl--第三节 关键点


    简介

    关键点也称为兴趣点,它是 2D 图像或 3D 点云或曲面模型上,可以通过检测标准来获取的具有稳定性、区别性的点集。从技术上来说,关键点的数量比原始点云或图像的数据量少很多,其与局部特征描述子结合组成关键点描述子。常用来构成原始数据的紧凑表示 ,具有代表性与描述性,从而加快后续识别、追踪等对数据的处理速度 。

    固而,关键点提取就成为 2D 与 3D 信息处理中不可或缺的关键技术 。

    NARF(Normal Aligned Radial Feature)关键点是为了从深度图像中识别物体而提出的,关键点探测的重要一步是减少特征提取时的搜索空间,把重点放在重要的结构上,对 NARF 关键点提取过程有以下要求:

    1. 提取的过程必须考虑边缘以及物体表面变化信息在内;
    2. 关键点的位置必须稳定的可以被重复探测,即使换了不同的视角;
    3. 关键点所在的位置必须有稳定的支持区域,可以计算描述子和进行唯一的估计法向量。

    为了满足上述要求,提出以下探测步骤来进行关键点提取:

    1. 遍历每个深度图像点,通过寻找在近区域有深度突变的位置进行边缘检测。
    2. 遍历每个深度图像点,根据近邻区域的表面变化决定一测度表面变化的系数,以及变化的主方向。
    3. 根据第二步找到的主方向计算兴趣值,表征该方向与其他方向的不同以及该处表面的变化情况,即该点有多稳定。
    4. 对兴趣值进行平滑过滤。
    5. 进行无最大值压缩找到最终的关键点,即为 NARF关键点

    1. /* \author Bastian Steder */
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. #include // for getFilenameWithoutExtension
    11. typedef pcl::PointXYZ PointType;
    12. // --------------------
    13. // -----Parameters-----
    14. // --------------------
    15. float angular_resolution = 0.5f;
    16. float support_size = 0.2f;
    17. pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
    18. bool setUnseenToMaxRange = false;
    19. // --------------
    20. // -----Help-----
    21. // --------------
    22. void
    23. printUsage(const char* progName)
    24. {
    25. std::cout << "\n\nUsage: " << progName << " [options] \n\n"
    26. << "Options:\n"
    27. << "-------------------------------------------\n"
    28. << "-r angular resolution in degrees (default " << angular_resolution << ")\n"
    29. << "-c coordinate frame (default " << (int)coordinate_frame << ")\n"
    30. << "-m Treat all unseen points as maximum range readings\n"
    31. << "-s support size for the interest points (diameter of the used sphere - "
    32. << "default " << support_size << ")\n"
    33. << "-h this help\n"
    34. << "\n\n";
    35. }
    36. //void
    37. //setViewerPose (pcl::visualization::PCLVisualizer& viewer, const Eigen::Affine3f& viewer_pose)
    38. //{
    39. //Eigen::Vector3f pos_vector = viewer_pose * Eigen::Vector3f (0, 0, 0);
    40. //Eigen::Vector3f look_at_vector = viewer_pose.rotation () * Eigen::Vector3f (0, 0, 1) + pos_vector;
    41. //Eigen::Vector3f up_vector = viewer_pose.rotation () * Eigen::Vector3f (0, -1, 0);
    42. //viewer.setCameraPosition (pos_vector[0], pos_vector[1], pos_vector[2],
    43. //look_at_vector[0], look_at_vector[1], look_at_vector[2],
    44. //up_vector[0], up_vector[1], up_vector[2]);
    45. //}
    46. // --------------
    47. // -----Main-----
    48. // --------------
    49. int
    50. main(int argc, char** argv)
    51. {
    52. // --------------------------------------
    53. // -----Parse Command Line Arguments-----
    54. // --------------------------------------
    55. if (pcl::console::find_argument(argc, argv, "-h") >= 0)
    56. {
    57. printUsage(argv[0]);
    58. return 0;
    59. }
    60. if (pcl::console::find_argument(argc, argv, "-m") >= 0)
    61. {
    62. setUnseenToMaxRange = true;
    63. std::cout << "Setting unseen values in range image to maximum range readings.\n";
    64. }
    65. int tmp_coordinate_frame;
    66. if (pcl::console::parse(argc, argv, "-c", tmp_coordinate_frame) >= 0)
    67. {
    68. coordinate_frame = pcl::RangeImage::CoordinateFrame(tmp_coordinate_frame);
    69. std::cout << "Using coordinate frame " << (int)coordinate_frame << ".\n";
    70. }
    71. if (pcl::console::parse(argc, argv, "-s", support_size) >= 0)
    72. std::cout << "Setting support size to " << support_size << ".\n";
    73. if (pcl::console::parse(argc, argv, "-r", angular_resolution) >= 0)
    74. std::cout << "Setting angular resolution to " << angular_resolution << "deg.\n";
    75. angular_resolution = pcl::deg2rad(angular_resolution);
    76. // ------------------------------------------------------------------
    77. // -----Read pcd file or create example point cloud if not given-----
    78. // ------------------------------------------------------------------
    79. pcl::PointCloud::Ptr point_cloud_ptr(new pcl::PointCloud);
    80. pcl::PointCloud& point_cloud = *point_cloud_ptr;
    81. pcl::PointCloud far_ranges;
    82. Eigen::Affine3f scene_sensor_pose(Eigen::Affine3f::Identity());
    83. std::vector<int> pcd_filename_indices = pcl::console::parse_file_extension_argument(argc, argv, "pcd");
    84. if (!pcd_filename_indices.empty())
    85. {
    86. std::string filename = argv[pcd_filename_indices[0]];
    87. if (pcl::io::loadPCDFile(filename, point_cloud) == -1)
    88. {
    89. std::cerr << "Was not able to open file \"" << filename << "\".\n";
    90. printUsage(argv[0]);
    91. return 0;
    92. }
    93. scene_sensor_pose = Eigen::Affine3f(Eigen::Translation3f(point_cloud.sensor_origin_[0],
    94. point_cloud.sensor_origin_[1],
    95. point_cloud.sensor_origin_[2])) *
    96. Eigen::Affine3f(point_cloud.sensor_orientation_);
    97. std::string far_ranges_filename = pcl::getFilenameWithoutExtension(filename) + "_far_ranges.pcd";
    98. if (pcl::io::loadPCDFile(far_ranges_filename.c_str(), far_ranges) == -1)
    99. std::cout << "Far ranges file \"" << far_ranges_filename << "\" does not exists.\n";
    100. }
    101. else
    102. {
    103. setUnseenToMaxRange = true;
    104. std::cout << "\nNo *.pcd file given => Generating example point cloud.\n\n";
    105. for (float x = -0.5f; x <= 0.5f; x += 0.01f)
    106. {
    107. for (float y = -0.5f; y <= 0.5f; y += 0.01f)
    108. {
    109. PointType point; point.x = x; point.y = y; point.z = 2.0f - y;
    110. point_cloud.push_back(point);
    111. }
    112. }
    113. point_cloud.width = point_cloud.size(); point_cloud.height = 1;
    114. }
    115. // -----------------------------------------------
    116. // -----Create RangeImage from the PointCloud-----
    117. // -----------------------------------------------
    118. float noise_level = 0.0;
    119. float min_range = 0.0f;
    120. int border_size = 1;
    121. pcl::RangeImage::Ptr range_image_ptr(new pcl::RangeImage);
    122. pcl::RangeImage& range_image = *range_image_ptr;
    123. range_image.createFromPointCloud(point_cloud, angular_resolution, pcl::deg2rad(360.0f), pcl::deg2rad(180.0f),
    124. scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);
    125. range_image.integrateFarRanges(far_ranges);
    126. if (setUnseenToMaxRange)
    127. range_image.setUnseenToMaxRange();
    128. // --------------------------------------------
    129. // -----Open 3D viewer and add point cloud-----
    130. // --------------------------------------------
    131. pcl::visualization::PCLVisualizer viewer("3D Viewer");
    132. viewer.setBackgroundColor(1, 1, 1);
    133. pcl::visualization::PointCloudColorHandlerCustom range_image_color_handler(range_image_ptr, 0, 0, 0);
    134. viewer.addPointCloud(range_image_ptr, range_image_color_handler, "range image");
    135. viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "range image");
    136. //viewer.addCoordinateSystem (1.0f, "global");
    137. //PointCloudColorHandlerCustom point_cloud_color_handler (point_cloud_ptr, 150, 150, 150);
    138. //viewer.addPointCloud (point_cloud_ptr, point_cloud_color_handler, "original point cloud");
    139. viewer.initCameraParameters();
    140. //setViewerPose (viewer, range_image.getTransformationToWorldSystem ());
    141. // --------------------------
    142. // -----Show range image-----
    143. // --------------------------
    144. pcl::visualization::RangeImageVisualizer range_image_widget("Range image");
    145. range_image_widget.showRangeImage(range_image);
    146. // --------------------------------
    147. // -----Extract NARF keypoints-----
    148. // --------------------------------
    149. pcl::RangeImageBorderExtractor range_image_border_extractor;
    150. pcl::NarfKeypoint narf_keypoint_detector(&range_image_border_extractor);
    151. narf_keypoint_detector.setRangeImage(&range_image);
    152. narf_keypoint_detector.getParameters().support_size = support_size;
    153. //narf_keypoint_detector.getParameters ().add_points_on_straight_edges = true;
    154. //narf_keypoint_detector.getParameters ().distance_for_additional_points = 0.5;
    155. pcl::PointCloud<int> keypoint_indices;
    156. narf_keypoint_detector.compute(keypoint_indices);
    157. std::cout << "Found " << keypoint_indices.size() << " key points.\n";
    158. // ----------------------------------------------
    159. // -----Show keypoints in range image widget-----
    160. // ----------------------------------------------
    161. //for (std::size_t i=0; i
    162. //range_image_widget.markPoint (keypoint_indices[i]%range_image.width,
    163. //keypoint_indices[i]/range_image.width);
    164. // -------------------------------------
    165. // -----Show keypoints in 3D viewer-----
    166. // -------------------------------------
    167. pcl::PointCloud::Ptr keypoints_ptr(new pcl::PointCloud);
    168. pcl::PointCloud& keypoints = *keypoints_ptr;
    169. keypoints.resize(keypoint_indices.size());
    170. for (std::size_t i = 0; i < keypoint_indices.size(); ++i)
    171. keypoints[i].getVector3fMap() = range_image[keypoint_indices[i]].getVector3fMap();
    172. pcl::visualization::PointCloudColorHandlerCustom keypoints_color_handler(keypoints_ptr, 0, 255, 0);
    173. viewer.addPointCloud(keypoints_ptr, keypoints_color_handler, "keypoints");
    174. viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints");
    175. //--------------------
    176. // -----Main loop-----
    177. //--------------------
    178. while (!viewer.wasStopped())
    179. {
    180. range_image_widget.spinOnce(); // process GUI events
    181. viewer.spinOnce();
    182. pcl_sleep(0.01);
    183. }
    184. }

     找不到那个far文件,无法运行

  • 相关阅读:
    在python中我对包的理解,希望对你有帮助
    【NSFileManager的其他常用方法 创建文件等 Objective-C语言】
    STM32使用STM32CubeMX生成文件,并实现串口打印功能。
    取消github向邮箱推送邮件及修改密码
    振弦传感器计算公式推导及测量原理
    【字符串处理函数】sprintf与snprintf
    1459. 矩形面积
    Java线程池-异步任务编排
    java毕业设计——基于java+Spring+SSH的CRM客户关系管理系统设计与实现(毕业论文+程序源码)——CRM客户关系管理系统
    OS 二级页表
  • 原文地址:https://blog.csdn.net/weixin_42398658/article/details/132854713