码迷,mamicode.com
首页 > 其他好文 > 详细

基于SIFT的点云关键点提取

时间:2015-06-01 16:25:54      阅读:1322      评论:0      收藏:0      [点我收藏+]

标签:

      这篇博文主要介绍SIFT算法在提取点云图像关键点时的具体用法。

      尺度不变特征转换(Scale-invariant feature transform,SIFT)是David Lowe在1999年发表,2004年总结完善。其应用范围包括物体辨识,机器人地图感知与导航、3D模型建立、手势辨识、影像追踪和动作对比。此算法已经申请专利,专利拥有者属于英属哥伦比亚大学。SIFT算法在3D数据上的应用由Flint等在2007年实现。这里所讲的提取点云关键点的算法便是由Flint等人实现的SIFT3D算法。

      其实现代如下:  

技术分享
 1 // STL
 2 #include <iostream>
 3 
 4 // PCL
 5 #include <pcl/io/pcd_io.h>
 6 #include <pcl/point_types.h>
 7 #include <pcl/common/io.h>
 8 #include <pcl/keypoints/sift_keypoint.h>
 9 #include <pcl/features/normal_3d.h>
10 #include <pcl/visualization/pcl_visualizer.h>
11 #include <pcl/console/time.h>
12 
13 /* This examples shows how to estimate the SIFT points based on the 
14  * z gradient of the 3D points than using the Intensity gradient as
15  * usually used for SIFT keypoint estimation.
16  */
17 
18 namespace pcl
19 {
20   template<>
21     struct SIFTKeypointFieldSelector<PointXYZ>
22     {
23       inline float
24       operator () (const PointXYZ &p) const
25       {
26     return p.z;
27       }
28     };
29 }
30 
31 int
32 main(int, char** argv)
33 {
34   std::string filename = argv[1];
35   std::cout << "Reading " << filename << std::endl;
36   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
37   if(pcl::io::loadPCDFile<pcl::PointXYZ> (filename, *cloud_xyz) == -1) // load the file
38   {
39     PCL_ERROR ("Couldn‘t read file");
40     return -1;
41   }
42   std::cout << "points: " << cloud_xyz->points.size () <<std::endl;
43   
44   // Parameters for sift computation
45   const float min_scale = 0.005f; //the standard deviation of the smallest scale in the scale space
46   const int n_octaves = 6;//the number of octaves (i.e. doublings of scale) to compute
47   const int n_scales_per_octave = 4;//the number of scales to compute within each octave
48   const float min_contrast = 0.005f;//the minimum contrast required for detection
49   
50 
51   pcl::console::TicToc time;
52   time.tic();
53   // Estimate the sift interest points using z values from xyz as the Intensity variants
54   pcl::SIFTKeypoint<pcl::PointXYZ, pcl::PointWithScale> sift;
55   pcl::PointCloud<pcl::PointWithScale> result;
56   pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ> ());
57   sift.setSearchMethod(tree);
58   sift.setScales(min_scale, n_octaves, n_scales_per_octave);
59   sift.setMinimumContrast(min_contrast);
60   sift.setInputCloud(cloud_xyz);
61   sift.compute(result);
62   std::cout<<"Computing the SIFT points takes "<<time.toc()/1000<<"seconds"<<std::endl;
63   std::cout << "No of SIFT points in the result are " << result.points.size () << std::endl;
64 
65 
66   // Copying the pointwithscale to pointxyz so as visualize the cloud
67   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_temp (new pcl::PointCloud<pcl::PointXYZ>);
68   copyPointCloud(result, *cloud_temp);
69   std::cout << "SIFT points in the result are " << cloud_temp->points.size () << std::endl;
70   // Visualization of keypoints along with the original cloud
71   pcl::visualization::PCLVisualizer viewer("PCL Viewer");
72   pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> keypoints_color_handler (cloud_temp, 0, 255, 0);
73   pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> cloud_color_handler (cloud_xyz, 255, 0, 0);
74   viewer.setBackgroundColor( 0.0, 0.0, 0.0 );
75   viewer.addPointCloud(cloud_xyz, cloud_color_handler, "cloud");//add point cloud
76   viewer.addPointCloud(cloud_temp, keypoints_color_handler, "keypoints");//add the keypoints 
77   viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints");
78   
79   while(!viewer.wasStopped ())
80   {
81     viewer.spinOnce ();
82   }
83 
84 
85   return 0;
86   
87 }
View Code

      运行结果如下图所示:

技术分享

基于SIFT的点云关键点提取

标签:

原文地址:http://www.cnblogs.com/freshmen/p/4254573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!