Point Cloud Library (PCL) 1.12.0
Loading...
Searching...
No Matches
feature_estimation.h
1#pragma once
2
3#include "typedefs.h"
4
5#include <pcl/io/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 */
19SurfaceNormalsPtr
20estimateSurfaceNormals (const PointCloudPtr & input, float radius)
21{
23 normal_estimation.setSearchMethod (pcl::search::Search<PointT>::Ptr (new pcl::search::KdTree<PointT>));
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 */
48PointCloudPtr
49detectKeypoints (const PointCloudPtr & points, const SurfaceNormalsPtr & /*normals*/,
50 float min_scale, int nr_octaves, int nr_scales_per_octave, float min_contrast)
51{
53 sift_detect.setSearchMethod (pcl::search::Search<PointT>::Ptr (new pcl::search::KdTree<PointT>));
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 */
77LocalDescriptorsPtr
78computeLocalDescriptors (const PointCloudPtr & points, const SurfaceNormalsPtr & normals,
79 const PointCloudPtr & keypoints, float feature_radius)
80{
82 fpfh_estimation.setSearchMethod (pcl::search::Search<PointT>::Ptr (new pcl::search::KdTree<PointT>));
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 */
101GlobalDescriptorsPtr
102computeGlobalDescriptor (const PointCloudPtr & points, const SurfaceNormalsPtr & normals)
103{
105 vfh_estimation.setSearchMethod (pcl::search::Search<PointT>::Ptr (new pcl::search::KdTree<PointT>));
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 */
128computeFeatures (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}
Iterator class for point clouds with or without given indices.
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:144
PointCloudPtr points
LocalDescriptorsPtr local_descriptors
GlobalDescriptorsPtr global_descriptor
PointCloudPtr keypoints
SurfaceNormalsPtr normals