资讯动态

【SLAM】PCL:从深度图(pcd文件)中提取NARF关键点

发布时间:2026/10/22 16:57:15 来源:尧图企业网站定制
NARF(Normal Aligned Radial Feature)关键点是为了从深度图像中识别物体而提出的对NARF关键点的提取过程有以下要求 a) 提取的过程考虑边缘以及物体表面变化信息在内b)在不同视角关键点可以被重复探测c)关键点所在位置有足够的支持区域可以计算描述子和进行唯一的估计法向量。 其对应的探测步骤如下 (1) 遍历每个深度图像点通过寻找在近邻区域有深度变化的位置进行边缘检测。 (2) 遍历每个深度图像点根据近邻区域的表面变化决定一测度表面变化的系数及变化的主方向。 (3) 根据step(2)找到的主方向计算兴趣点表征该方向和其他方向的不同以及该处表面的变化情况即该点有多稳定。 (4) 对兴趣值进行平滑滤波。 (5) 进行无最大值压缩找到的最终关键点即为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/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; 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 as maximum range readings\n -s float support size for the interest points (diameter of the used sphere - default support_size)\n -h this help\n \n\n; } 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; } 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_resolutiondeg.\n; angular_resolution pcl::deg2rad (angular_resolution); // ------------------------------------------------------------------ // -----Read pcd file or create example point cloud if not given----- // ------------------------------------------------------------------ pcl::PointCloudPointType::Ptr point_cloud_ptr (new pcl::PointCloudPointType); pcl::PointCloudPointType point_cloud *point_cloud_ptr; pcl::PointCloudpcl::PointWithViewpoint far_ranges; Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ()); std::vectorint 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; x0.5f; x0.01f) { for (float y-0.5f; y0.5f; y0.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_ptrpcl::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::PointCloudColorHandlerCustompcl::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); //PointCloudColorHandlerCustomPointType 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 (range_image_border_extractor); narf_keypoint_detector.setRangeImage (range_image); narf_keypoint_detector.getParameters ().support_size support_size; //narf_keypoint_detector.getParameters ().add_points_on_straight_edges true; //narf_keypoint_detector.getParameters ().distance_for_additional_points 0.5; pcl::PointCloudint 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 i0; ikeypoint_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::PointCloudpcl::PointXYZ::Ptr keypoints_ptr (new pcl::PointCloudpcl::PointXYZ); pcl::PointCloudpcl::PointXYZ keypoints *keypoints_ptr; keypoints.points.resize (keypoint_indices.points.size ()); for (size_t i0; ikeypoint_indices.points.size (); i) keypoints.points[i].getVector3fMap () range_image.points[keypoint_indices.points[i]].getVector3fMap (); pcl::visualization::PointCloudColorHandlerCustompcl::PointXYZ keypoints_color_handler (keypoints_ptr, 0, 255, 0); viewer.addPointCloudpcl::PointXYZ (keypoints_ptr, keypoints_color_handler, keypoints); viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, keypoints); //-------------------- // -----Main loop----- //-------------------- while (!viewer.wasStopped ()) { range_image_widget.spinOnce (); // process GUI events viewer.spinOnce (); pcl_sleep(0.01); } return 0; }结果如下小伙伴们可自行尝试

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑