PCL的NARF关键点提取代码
时间: 2023-11-02 15:06:17 浏览: 106
以下是使用PCL库进行NARF关键点提取的示例代码:
```c++
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/features/narf_descriptor.h>
int main(int argc, char** argv)
{
if(argc != 2)
{
std::cerr << "Usage: " << argv[0] << " cloud.pcd" << std::endl;
return -1;
}
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile(argv[1], *cloud);
pcl::PointCloud<pcl::Narf36>::Ptr narfs(new pcl::PointCloud<pcl::Narf36>);
pcl::RangeImage range_image;
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
float angular_resolution = 0.5f;
float support_size = 0.2f;
Eigen::Affine3f scene_sensor_pose(Eigen::Affine3f::Identity());
range_image.createFromPointCloud(*cloud, angular_resolution, pcl::deg2rad(360.0f), pcl::deg2rad(180.0f), scene_sensor_pose, coordinate_frame, support_size, support_size/2.0f);
pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints(new pcl::PointCloud<pcl::PointXYZ>);
pcl::NarfKeypoint narf_keypoint_detector;
narf_keypoint_detector.setRangeImage(&range_image);
narf_keypoint_detector.getParameters().support_size = support_size;
narf_keypoint_detector.compute(*keypoints);
pcl::NarfDescriptor narf_descriptor(&range_image, &narf_keypoint_detector);
narf_descriptor.getParameters().support_size = support_size;
narf_descriptor.getParameters().rotation_invariant = true;
narf_descriptor.compute(*narfs);
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("NARF Keypoints"));
viewer->setBackgroundColor(0, 0, 0);
viewer->addPointCloud<pcl::PointXYZ>(cloud, "cloud");
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
viewer->addPointCloud<pcl::PointXYZ>(keypoints, "keypoints");
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "keypoints");
viewer->spin();
return 0;
}
```
该代码加载点云数据后,使用 `pcl::RangeImage` 对其进行预处理,然后使用 `pcl::NarfKeypoint` 进行关键点提取,最终使用 `pcl::NarfDescriptor` 计算NARF描述符。提取出的关键点和原始点云数据一起显示在可视化窗口中。
阅读全文