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 /* Use NormalEstimation to estimate a cloud's surface normals
13  * Inputs:
14  * input
15  * The input point cloud
16  * radius
17  * The size of the local neighborhood used to estimate the surface
18  * Return: A pointer to a SurfaceNormals point cloud
19  */
20 SurfaceNormalsPtr
21 estimateSurfaceNormals (const PointCloudPtr & input, float radius)
22 {
25  normal_estimation.setRadiusSearch (radius);
26  normal_estimation.setInputCloud (input);
27  SurfaceNormalsPtr normals (new SurfaceNormals);
28  normal_estimation.compute (*normals);
29 
30  return (normals);
31 }
32 
33 /* Use SIFTKeypoint to detect a set of keypoints
34  * Inputs:
35  * points
36  * The input point cloud
37  * normals
38  * The input surface normals
39  * min_scale
40  * The smallest scale in the difference-of-Gaussians (DoG) scale-space
41  * nr_octaves
42  * The number of times the scale doubles in the DoG scale-space
43  * nr_scales_per_octave
44  * The number of scales computed for each doubling
45  * min_contrast
46  * The minimum local contrast that must be present for a keypoint to be detected
47  * Return: A pointer to a point cloud of keypoints
48  */
49 PointCloudPtr
50 detectKeypoints (const PointCloudPtr & points, const SurfaceNormalsPtr & normals,
51  float min_scale, int nr_octaves, int nr_scales_per_octave, float min_contrast)
52 {
55  sift_detect.setScales (min_scale, nr_octaves, nr_scales_per_octave);
56  sift_detect.setMinimumContrast (min_contrast);
57  sift_detect.setInputCloud (points);
59  sift_detect.compute (keypoints_temp);
60  PointCloudPtr keypoints (new PointCloud);
61  pcl::copyPointCloud (keypoints_temp, *keypoints);
62 
63  return (keypoints);
64 }
65 
66 /* Use FPFHEstimation to compute local feature descriptors around each keypoint
67  * Inputs:
68  * points
69  * The input point cloud
70  * normals
71  * The input surface normals
72  * keypoints
73  * A cloud of keypoints specifying the positions at which the descriptors should be computed
74  * feature_radius
75  * The size of the neighborhood from which the local descriptors will be computed
76  * Return: A pointer to a LocalDescriptors (a cloud of LocalDescriptorT points)
77  */
78 LocalDescriptorsPtr
79 computeLocalDescriptors (const PointCloudPtr & points, const SurfaceNormalsPtr & normals,
80  const PointCloudPtr & keypoints, float feature_radius)
81 {
84  fpfh_estimation.setRadiusSearch (feature_radius);
85  fpfh_estimation.setSearchSurface (points);
86  fpfh_estimation.setInputNormals (normals);
87  fpfh_estimation.setInputCloud (keypoints);
88  LocalDescriptorsPtr local_descriptors (new LocalDescriptors);
89  fpfh_estimation.compute (*local_descriptors);
90 
91  return (local_descriptors);
92 }
93 
94 /* Use VFHEstimation to compute a single global descriptor for the entire input cloud
95  * Inputs:
96  * points
97  * The input point cloud
98  * normals
99  * The input surface normals
100  * Return: A pointer to a GlobalDescriptors point cloud (a cloud containing a single GlobalDescriptorT point)
101  */
102 GlobalDescriptorsPtr
103 computeGlobalDescriptor (const PointCloudPtr & points, const SurfaceNormalsPtr & normals)
104 {
107  vfh_estimation.setInputCloud (points);
108  vfh_estimation.setInputNormals (normals);
109  GlobalDescriptorsPtr global_descriptor (new GlobalDescriptors);
110  vfh_estimation.compute (*global_descriptor);
111 
112  return (global_descriptor);
113 }
114 
115 /* A simple structure for storing all of a cloud's features */
117 {
118  PointCloudPtr points;
119  SurfaceNormalsPtr normals;
120  PointCloudPtr keypoints;
121  LocalDescriptorsPtr local_descriptors;
122  GlobalDescriptorsPtr global_descriptor;
123 };
124 
125 /* Estimate normals, detect keypoints, and compute local and global descriptors
126  * Return: An ObjectFeatures struct containing all the features
127  */
129 computeFeatures (const PointCloudPtr & input)
130 {
131  ObjectFeatures features;
132  features.points = input;
133  features.normals = estimateSurfaceNormals (input, 0.05);
134  features.keypoints = detectKeypoints (input, features.normals, 0.005, 10, 8, 1.5);
135  features.local_descriptors = computeLocalDescriptors (input, features.normals, features.keypoints, 0.1);
136  features.global_descriptor = computeGlobalDescriptor (input, features.normals);
137 
138  return (features);
139 }
140 
141 #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 &lt;setInputCloud (), setIndices ()&gt; 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< pcl::search::Search< PointT > > Ptr
Definition: search.h:81
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 &lt;setInputCloud (), setIndices ()&gt; 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