Go to the documentation of this file.00001 #ifndef FEATURE_ESTIMATION_H
00002 #define FEATURE_ESTIMATION_H
00003
00004 #include "typedefs.h"
00005
00006 #include <pcl/io/io.h>
00007 #include <pcl/features/normal_3d.h>
00008 #include <pcl/keypoints/sift_keypoint.h>
00009 #include <pcl/features/fpfh.h>
00010 #include <pcl/features/vfh.h>
00011 #include <pcl/search/kdtree.h>
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 SurfaceNormalsPtr
00022 estimateSurfaceNormals (const PointCloudPtr & input, float radius)
00023 {
00024 pcl::NormalEstimation<PointT, NormalT> normal_estimation;
00025 normal_estimation.setSearchMethod (pcl::search::KdTree<PointT>::Ptr (new pcl::search::KdTree<PointT>));
00026 normal_estimation.setRadiusSearch (radius);
00027 normal_estimation.setInputCloud (input);
00028 SurfaceNormalsPtr normals (new SurfaceNormals);
00029 normal_estimation.compute (*normals);
00030
00031 return (normals);
00032 }
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 PointCloudPtr
00051 detectKeypoints (const PointCloudPtr & points, const SurfaceNormalsPtr & normals,
00052 float min_scale, int nr_octaves, int nr_scales_per_octave, float min_contrast)
00053 {
00054 pcl::SIFTKeypoint<PointT, pcl::PointWithScale> sift_detect;
00055 sift_detect.setSearchMethod (pcl::search::KdTree<PointT>::Ptr (new pcl::search::KdTree<PointT>));
00056 sift_detect.setScales (min_scale, nr_octaves, nr_scales_per_octave);
00057 sift_detect.setMinimumContrast (min_contrast);
00058 sift_detect.setInputCloud (points);
00059 pcl::PointCloud<pcl::PointWithScale> keypoints_temp;
00060 sift_detect.compute (keypoints_temp);
00061 PointCloudPtr keypoints (new PointCloud);
00062 pcl::copyPointCloud (keypoints_temp, *keypoints);
00063
00064 return (keypoints);
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 LocalDescriptorsPtr
00080 computeLocalDescriptors (const PointCloudPtr & points, const SurfaceNormalsPtr & normals,
00081 const PointCloudPtr & keypoints, float feature_radius)
00082 {
00083 pcl::FPFHEstimation<PointT, NormalT, LocalDescriptorT> fpfh_estimation;
00084 fpfh_estimation.setSearchMethod (pcl::search::KdTree<PointT>::Ptr (new pcl::search::KdTree<PointT>));
00085 fpfh_estimation.setRadiusSearch (feature_radius);
00086 fpfh_estimation.setSearchSurface (points);
00087 fpfh_estimation.setInputNormals (normals);
00088 fpfh_estimation.setInputCloud (keypoints);
00089 LocalDescriptorsPtr local_descriptors (new LocalDescriptors);
00090 fpfh_estimation.compute (*local_descriptors);
00091
00092 return (local_descriptors);
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 GlobalDescriptorsPtr
00104 computeGlobalDescriptor (const PointCloudPtr & points, const SurfaceNormalsPtr & normals)
00105 {
00106 pcl::VFHEstimation<PointT, NormalT, GlobalDescriptorT> vfh_estimation;
00107 vfh_estimation.setSearchMethod (pcl::search::KdTree<PointT>::Ptr (new pcl::search::KdTree<PointT>));
00108 vfh_estimation.setInputCloud (points);
00109 vfh_estimation.setInputNormals (normals);
00110 GlobalDescriptorsPtr global_descriptor (new GlobalDescriptors);
00111 vfh_estimation.compute (*global_descriptor);
00112
00113 return (global_descriptor);
00114 }
00115
00116
00117 struct ObjectFeatures
00118 {
00119 PointCloudPtr points;
00120 SurfaceNormalsPtr normals;
00121 PointCloudPtr keypoints;
00122 LocalDescriptorsPtr local_descriptors;
00123 GlobalDescriptorsPtr global_descriptor;
00124 };
00125
00126
00127
00128
00129 ObjectFeatures
00130 computeFeatures (const PointCloudPtr & input)
00131 {
00132 ObjectFeatures features;
00133 features.points = input;
00134 features.normals = estimateSurfaceNormals (input, 0.05);
00135 features.keypoints = detectKeypoints (input, features.normals, 0.005, 10, 8, 1.5);
00136 features.local_descriptors = computeLocalDescriptors (input, features.normals, features.keypoints, 0.1);
00137 features.global_descriptor = computeGlobalDescriptor (input, features.normals);
00138
00139 return (features);
00140 }
00141
00142 #endif