3d激光雷达开发(narf关键点)
程序开发
2023-09-23 23:59:37
【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】
所谓关键点,其实就是那些梯度信息特征比较明显的点。至于是多明显,这部分需要用数学公式来进行标识。第一次学的时候,可以先有一个感性的认识。pcl库给出的例子是从RangeImage中提取narf关键点,原代码地址在这,https://pcl.readthedocs.io/projects/tutorials/en/latest/narf_keypoint_extraction.html#narf-keypoint-extraction
1、准备narf.cpp文件
/* author Bastian Steder */#include #include
#include
#include
#include
#include
#include
#include
#include // for getFilenameWithoutExtensiontypedef 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;// --------------
// -----Help-----
// --------------
void
printUsage (const char* progName)
{std::cout << "nnUsage: "<nn"<< "Options:n"<< "-------------------------------------------n"<< "-r angular resolution in degrees (default "< coordinate frame (default "<< (int)coordinate_frame<<")n"<< "-m Treat all unseen points as maximum range readingsn"<< "-s support size for the interest points (diameter of the used sphere - "<< "default "<= 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";}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 "<= 0)std::cout << "Setting angular resolution to "<::Ptr point_cloud_ptr (new pcl::PointCloud);pcl::PointCloud& point_cloud = *point_cloud_ptr;pcl::PointCloud far_ranges;Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ());std::vector 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 ""< Generating example point cloud.nn";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.push_back (point);}}point_cloud.width = point_cloud.size (); point_cloud.height = 1;}// -----------------------------------------------// -----Create RangeImage from the PointCloud-----// -----------------------------------------------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 ();// --------------------------------------------// -----Open 3D viewer and add point cloud-----// --------------------------------------------pcl::visualization::PCLVisualizer viewer ("3D Viewer");viewer.setBackgroundColor (1, 1, 1);pcl::visualization::PointCloudColorHandlerCustom 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 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::PointCloud keypoint_indices;narf_keypoint_detector.compute (keypoint_indices);std::cout << "Found "<::Ptr keypoints_ptr (new pcl::PointCloud);pcl::PointCloud& keypoints = *keypoints_ptr;keypoints.resize (keypoint_indices.size ());for (std::size_t i=0; i keypoints_color_handler (keypoints_ptr, 0, 255, 0);viewer.addPointCloud (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 eventsviewer.spinOnce ();pcl_sleep(0.01);}
}
2、准备CMakeLists.txt
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(narf)find_package(PCL 1.2 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable (narf narf.cpp)
target_link_libraries (narf ${PCL_LIBRARIES})
3、生成sln工程,准备编译,
4、准备执行narf.exe文件,不用添加参数
过一会,可以发现有6个关键点,
也就是上面图形中绿色的部分,当然RangeImage还是少不了的。
标签:
上一篇:
后端对前端参数校验(包括自定义注解)
下一篇:
相关文章
-
无相关信息