Point Cloud Library (PCL)  1.7.2
feature_estimation.h
1 #ifndef FEATURE_ESTIMATION_H
2 #define FEATURE_ESTIMATION_H
3 
4 #include "typedefs.h"
5 
6 #include <pcl/io/io.h>
7 #include <pcl/features/normal_3d.h>
8 #include <pcl/keypoints/sift_keypoint.h>
9 #include <pcl/features/fpfh.h>
10 #include <pcl/features/vfh.h>
11 #include <pcl/search/kdtree.h>
12 
13 /* Use NormalEstimation to estimate a cloud's surface normals
14  * Inputs:
15  * input
16  * The input point cloud
17  * radius
18  * The size of the local neighborhood used to estimate the surface
19  * Return: A pointer to a SurfaceNormals point cloud
20  */
21 SurfaceNormalsPtr
22 estimateSurfaceNormals (const PointCloudPtr & input, float radius)
23 {
26  normal_estimation.setRadiusSearch (radius);
27  normal_estimation.setInputCloud (input);
28  SurfaceNormalsPtr normals (new SurfaceNormals);
29  normal_estimation.compute (*normals);
30 
31  return (normals);
32 }
33 
34 /* Use SIFTKeypoint to detect a set of keypoints
35  * Inputs:
36  * points
37  * The input point cloud
38  * normals
39  * The input surface normals
40  * min_scale
41  * The smallest scale in the difference-of-Gaussians (DoG) scale-space
42  * nr_octaves
43  * The number of times the scale doubles in the DoG scale-space
44  * nr_scales_per_octave
45  * The number of scales computed for each doubling
46  * min_contrast
47  * The minimum local contrast that must be present for a keypoint to be detected
48  * Return: A pointer to a point cloud of keypoints
49  */
50 PointCloudPtr
51 detectKeypoints (const PointCloudPtr & points, const SurfaceNormalsPtr & normals,
52  float min_scale, int nr_octaves, int nr_scales_per_octave, float min_contrast)
53 {
56  sift_detect.setScales (min_scale, nr_octaves, nr_scales_per_octave);
57  sift_detect.setMinimumContrast (min_contrast);
58  sift_detect.setInputCloud (points);
60  sift_detect.compute (keypoints_temp);
61  PointCloudPtr keypoints (new PointCloud);
62  pcl::copyPointCloud (keypoints_temp, *keypoints);
63 
64  return (keypoints);
65 }
66 
67 /* Use FPFHEstimation to compute local feature descriptors around each keypoint
68  * Inputs:
69  * points
70  * The input point cloud
71  * normals
72  * The input surface normals
73  * keypoints
74  * A cloud of keypoints specifying the positions at which the descriptors should be computed
75  * feature_radius
76  * The size of the neighborhood from which the local descriptors will be computed
77  * Return: A pointer to a LocalDescriptors (a cloud of LocalDescriptorT points)
78  */
79 LocalDescriptorsPtr
80 computeLocalDescriptors (const PointCloudPtr & points, const SurfaceNormalsPtr & normals,
81  const PointCloudPtr & keypoints, float feature_radius)
82 {
85  fpfh_estimation.setRadiusSearch (feature_radius);
86  fpfh_estimation.setSearchSurface (points);
87  fpfh_estimation.setInputNormals (normals);
88  fpfh_estimation.setInputCloud (keypoints);
89  LocalDescriptorsPtr local_descriptors (new LocalDescriptors);
90  fpfh_estimation.compute (*local_descriptors);
91 
92  return (local_descriptors);
93 }
94 
95 /* Use VFHEstimation to compute a single global descriptor for the entire input cloud
96  * Inputs:
97  * points
98  * The input point cloud
99  * normals
100  * The input surface normals
101  * Return: A pointer to a GlobalDescriptors point cloud (a cloud containing a single GlobalDescriptorT point)
102  */
103 GlobalDescriptorsPtr
104 computeGlobalDescriptor (const PointCloudPtr & points, const SurfaceNormalsPtr & normals)
105 {
108  vfh_estimation.setInputCloud (points);
109  vfh_estimation.setInputNormals (normals);
110  GlobalDescriptorsPtr global_descriptor (new GlobalDescriptors);
111  vfh_estimation.compute (*global_descriptor);
112 
113  return (global_descriptor);
114 }
115 
116 /* A simple structure for storing all of a cloud's features */
117 struct ObjectFeatures
118 {
119  PointCloudPtr points;
120  SurfaceNormalsPtr normals;
121  PointCloudPtr keypoints;
122  LocalDescriptorsPtr local_descriptors;
123  GlobalDescriptorsPtr global_descriptor;
124 };
125 
126 /* Estimate normals, detect keypoints, and compute local and global descriptors
127  * Return: An ObjectFeatures struct containing all the features
128  */
130 computeFeatures (const PointCloudPtr & input)
131 {
132  ObjectFeatures features;
133  features.points = input;
134  features.normals = estimateSurfaceNormals (input, 0.05);
135  features.keypoints = detectKeypoints (input, features.normals, 0.005, 10, 8, 1.5);
136  features.local_descriptors = computeLocalDescriptors (input, features.normals, features.keypoints, 0.1);
137  features.global_descriptor = computeGlobalDescriptor (input, features.normals);
138 
139  return (features);
140 }
141 
142 #endif
void setSearchSurface(const PointCloudInConstPtr &cloud)
Provide a pointer to a dataset to add additional information to estimate the features for every point...
Definition: feature.h:148
SIFTKeypoint detects the Scale Invariant Feature Transform keypoints for a given point cloud dataset ...
Definition: sift_keypoint.h:94
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: keypoint.h:105
GlobalDescriptorsPtr global_descriptor
void compute(PointCloudOut &output)
Base method for key point detection for all points given in using t...
Definition: keypoint.hpp:124
PCL_EXPORTS void copyPointCloud(const pcl::PCLPointCloud2 &cloud_in, const std::vector< int > &indices, pcl::PCLPointCloud2 &cloud_out)
Extract the indices of a given point cloud as a new point cloud.
SurfaceNormalsPtr normals
void setRadiusSearch(double radius)
Set the sphere radius that is to be used for determining the nearest neighbors used for the feature e...
Definition: feature.h:200
NormalEstimation estimates local surface properties (surface normals and curvatures)at each 3D point...
Definition: normal_3d.h:197
PointCloudPtr keypoints
boost::shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:79
void setScales(float min_scale, int nr_octaves, int nr_scales_per_octave)
Specify the range of scales over which to search for keypoints.
void setMinimumContrast(float min_contrast)
Provide a threshold to limit detection of keypoints without sufficient contrast.
FPFHEstimation estimates the Fast Point Feature Histogram (FPFH) descriptor for a given point cloud d...
Definition: fpfh.h:80
VFHEstimation estimates the Viewpoint Feature Histogram (VFH) descriptor for a given point cloud data...
Definition: vfh.h:71
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: normal_3d.h:286
void compute(PointCloudOut &output)
Overloaded computed method from pcl::Feature.
Definition: vfh.hpp:65
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: feature.h:166
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
PointCloudPtr points
void compute(PointCloudOut &output)
Base method for feature estimation for all points given in using th...
Definition: feature.hpp:189
void setInputNormals(const PointCloudNConstPtr &normals)
Provide a pointer to the input dataset that contains the point normals of the XYZ dataset...
Definition: feature.h:344
LocalDescriptorsPtr local_descriptors