Point Cloud Library (PCL)  1.14.1-dev
feature_estimation.h
1 #pragma once
2 
3 #include "typedefs.h"
4 
5 #include <pcl/common/io.h>
6 #include <pcl/features/normal_3d.h>
7 #include <pcl/keypoints/sift_keypoint.h>
8 #include <pcl/features/fpfh.h>
9 #include <pcl/features/vfh.h>
10 #include <pcl/search/kdtree.h>
11 
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 */
116 struct ObjectFeatures
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 }
FPFHEstimation estimates the Fast Point Feature Histogram (FPFH) descriptor for a given point cloud d...
Definition: fpfh.h:79
void setInputNormals(const PointCloudNConstPtr &normals)
Provide a pointer to the input dataset that contains the point normals of the XYZ dataset.
Definition: feature.h:339
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:146
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:198
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: feature.h:164
void compute(PointCloudOut &output)
Base method for feature estimation for all points given in <setInputCloud (), setIndices ()> using th...
Definition: feature.hpp:194
void compute(PointCloudOut &output)
Base method for key point detection for all points given in <setInputCloud (), setIndices ()> using t...
Definition: keypoint.hpp:137
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: keypoint.h:100
NormalEstimation estimates local surface properties (surface normals and curvatures)at each 3D point.
Definition: normal_3d.h:244
void setInputCloud(const PointCloudConstPtr &cloud) override
Provide a pointer to the input dataset.
Definition: normal_3d.h:328
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: pcl_base.hpp:65
SIFTKeypoint detects the Scale Invariant Feature Transform keypoints for a given point cloud dataset ...
Definition: sift_keypoint.h:94
void setMinimumContrast(float min_contrast)
Provide a threshold to limit detection of keypoints without sufficient contrast.
void setScales(float min_scale, int nr_octaves, int nr_scales_per_octave)
Specify the range of scales over which to search for keypoints.
VFHEstimation estimates the Viewpoint Feature Histogram (VFH) descriptor for a given point cloud data...
Definition: vfh.h:73
void compute(PointCloudOut &output)
Overloaded computed method from pcl::Feature.
Definition: vfh.hpp:65
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:62
shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:75
void copyPointCloud(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
Copy all the fields from a given point cloud into a new point cloud.
Definition: io.hpp:142
PointCloudPtr points
LocalDescriptorsPtr local_descriptors
GlobalDescriptorsPtr global_descriptor
PointCloudPtr keypoints
SurfaceNormalsPtr normals