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