feature_estimation.h
#ifndef FEATURE_ESTIMATION_H
#define FEATURE_ESTIMATION_H
#include "typedefs.h"
#include <pcl/io/io.h>
#include <pcl/features/normal_3d.h>
#include <pcl/keypoints/sift_keypoint.h>
#include <pcl/features/fpfh.h>
#include <pcl/features/vfh.h>
#include <pcl/search/kdtree.h>
/* Use NormalEstimation to estimate a cloud's surface normals
* Inputs:
* input
* The input point cloud
* radius
* The size of the local neighborhood used to estimate the surface
* Return: A pointer to a SurfaceNormals point cloud
*/
SurfaceNormalsPtr
estimateSurfaceNormals (const PointCloudPtr & input, float radius)
{
pcl::NormalEstimation<PointT, NormalT> normal_estimation;
normal_estimation.setSearchMethod (pcl::search::Search<PointT>::Ptr (new pcl::search::KdTree<PointT>));
normal_estimation.setRadiusSearch (radius);
normal_estimation.setInputCloud (input);
SurfaceNormalsPtr normals (new SurfaceNormals);
normal_estimation.compute (*normals);
return (normals);
}
/* Use SIFTKeypoint to detect a set of keypoints
* Inputs:
* points
* The input point cloud
* normals
* The input surface normals
* min_scale
* The smallest scale in the difference-of-Gaussians (DoG) scale-space
* nr_octaves
* The number of times the scale doubles in the DoG scale-space
* nr_scales_per_octave
* The number of scales computed for each doubling
* min_contrast
* The minimum local contrast that must be present for a keypoint to be detected
* Return: A pointer to a point cloud of keypoints
*/
PointCloudPtr
detectKeypoints (const PointCloudPtr & points, const SurfaceNormalsPtr & normals,
float min_scale, int nr_octaves, int nr_scales_per_octave, float min_contrast)
{
pcl::SIFTKeypoint<PointT, pcl::PointWithScale> sift_detect;
sift_detect.setSearchMethod (pcl::search::Search<PointT>::Ptr (new pcl::search::KdTree<PointT>));
sift_detect.setScales (min_scale, nr_octaves, nr_scales_per_octave);
sift_detect.setMinimumContrast (min_contrast);
sift_detect.setInputCloud (points);
pcl::PointCloud<pcl::PointWithScale> keypoints_temp;
sift_detect.compute (keypoints_temp);
PointCloudPtr keypoints (new PointCloud);
pcl::copyPointCloud (keypoints_temp, *keypoints);
return (keypoints);
}
/* Use FPFHEstimation to compute local feature descriptors around each keypoint
* Inputs:
* points
* The input point cloud
* normals
* The input surface normals
* keypoints
* A cloud of keypoints specifying the positions at which the descriptors should be computed
* feature_radius
* The size of the neighborhood from which the local descriptors will be computed
* Return: A pointer to a LocalDescriptors (a cloud of LocalDescriptorT points)
*/
LocalDescriptorsPtr
computeLocalDescriptors (const PointCloudPtr & points, const SurfaceNormalsPtr & normals,
const PointCloudPtr & keypoints, float feature_radius)
{
pcl::FPFHEstimation<PointT, NormalT, LocalDescriptorT> fpfh_estimation;
fpfh_estimation.setSearchMethod (pcl::search::Search<PointT>::Ptr (new pcl::search::KdTree<PointT>));
fpfh_estimation.setRadiusSearch (feature_radius);
fpfh_estimation.setSearchSurface (points);
fpfh_estimation.setInputNormals (normals);
fpfh_estimation.setInputCloud (keypoints);
LocalDescriptorsPtr local_descriptors (new LocalDescriptors);
fpfh_estimation.compute (*local_descriptors);
return (local_descriptors);
}
/* Use VFHEstimation to compute a single global descriptor for the entire input cloud
* Inputs:
* points
* The input point cloud
* normals
* The input surface normals
* Return: A pointer to a GlobalDescriptors point cloud (a cloud containing a single GlobalDescriptorT point)
*/
GlobalDescriptorsPtr
computeGlobalDescriptor (const PointCloudPtr & points, const SurfaceNormalsPtr & normals)
{
pcl::VFHEstimation<PointT, NormalT, GlobalDescriptorT> vfh_estimation;
vfh_estimation.setSearchMethod (pcl::search::Search<PointT>::Ptr (new pcl::search::KdTree<PointT>));
vfh_estimation.setInputCloud (points);
vfh_estimation.setInputNormals (normals);
GlobalDescriptorsPtr global_descriptor (new GlobalDescriptors);
vfh_estimation.compute (*global_descriptor);
return (global_descriptor);
}
/* A simple structure for storing all of a cloud's features */
struct ObjectFeatures
{
PointCloudPtr points;
SurfaceNormalsPtr normals;
PointCloudPtr keypoints;
LocalDescriptorsPtr local_descriptors;
GlobalDescriptorsPtr global_descriptor;
};
/* Estimate normals, detect keypoints, and compute local and global descriptors
* Return: An ObjectFeatures struct containing all the features
*/
ObjectFeatures
computeFeatures (const PointCloudPtr & input)
{
ObjectFeatures features;
features.points = input;
features.normals = estimateSurfaceNormals (input, 0.05);
features.keypoints = detectKeypoints (input, features.normals, 0.005, 10, 8, 1.5);
features.local_descriptors = computeLocalDescriptors (input, features.normals, features.keypoints, 0.1);
features.global_descriptor = computeGlobalDescriptor (input, features.normals);
return (features);
}
#endif
pcl::Feature::setSearchSurface
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
pcl::SIFTKeypoint
SIFTKeypoint detects the Scale Invariant Feature Transform keypoints for a given point cloud dataset ...
Definition: sift_keypoint.h:94
pcl::search::KdTree< PointT >
pcl::Keypoint::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: keypoint.h:105
ObjectFeatures::global_descriptor
GlobalDescriptorsPtr global_descriptor
Definition: feature_estimation.h:122
pcl::Keypoint::compute
void compute(PointCloudOut &output)
Base method for key point detection for all points given in <setInputCloud (), setIndices ()> using t...
Definition: keypoint.hpp:124
pcl::copyPointCloud
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.
ObjectFeatures::normals
SurfaceNormalsPtr normals
Definition: feature_estimation.h:119
pcl::Feature::setRadiusSearch
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
pcl::NormalEstimation
NormalEstimation estimates local surface properties (surface normals and curvatures)at each 3D point...
Definition: normal_3d.h:199
ObjectFeatures::keypoints
PointCloudPtr keypoints
Definition: feature_estimation.h:120
ObjectFeatures
Definition: feature_estimation.h:116
pcl::search::Search::Ptr
boost::shared_ptr< pcl::search::Search< PointT > > Ptr
Definition: search.h:81
pcl::SIFTKeypoint::setScales
void setScales(float min_scale, int nr_octaves, int nr_scales_per_octave)
Specify the range of scales over which to search for keypoints.
Definition: sift_keypoint.hpp:47
pcl::SIFTKeypoint::setMinimumContrast
void setMinimumContrast(float min_contrast)
Provide a threshold to limit detection of keypoints without sufficient contrast.
Definition: sift_keypoint.hpp:57
pcl::FPFHEstimation
FPFHEstimation estimates the Fast Point Feature Histogram (FPFH) descriptor for a given point cloud d...
Definition: fpfh.h:80
pcl::VFHEstimation
VFHEstimation estimates the Viewpoint Feature Histogram (VFH) descriptor for a given point cloud data...
Definition: vfh.h:71
pcl::NormalEstimation::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: normal_3d.h:290
pcl::PointCloud< NormalT >
pcl::VFHEstimation::compute
void compute(PointCloudOut &output)
Overloaded computed method from pcl::Feature.
Definition: vfh.hpp:65
pcl::Feature::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: feature.h:166
pcl::PCLBase< PointInT >::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: pcl_base.hpp:66
ObjectFeatures::points
PointCloudPtr points
Definition: feature_estimation.h:118
pcl::Feature::compute
void compute(PointCloudOut &output)
Base method for feature estimation for all points given in <setInputCloud (), setIndices ()> using th...
Definition: feature.hpp:189
pcl::FeatureFromNormals::setInputNormals
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
ObjectFeatures::local_descriptors
LocalDescriptorsPtr local_descriptors
Definition: feature_estimation.h:121