1 #ifndef OBJECT_RECOGNITION_H_ 2 #define OBJECT_RECOGNITION_H_ 5 #include "load_clouds.h" 6 #include "solution/filters.h" 7 #include "solution/segmentation.h" 8 #include "solution/feature_estimation.h" 9 #include "solution/registration.h" 11 #include <pcl/io/pcd_io.h> 12 #include <pcl/kdtree/kdtree_flann.h> 52 PointCloudPtr keypoints;
53 LocalDescriptorsPtr local_descriptors;
54 GlobalDescriptorsPtr global_descriptor;
66 size_t n = filenames.size ();
69 for (
size_t i = 0; i < n; ++i)
71 const std::string & filename = filenames[i];
72 if (filename.compare (filename.size ()-4, 4,
".pcd") == 0)
78 constructObjectModel (raw_input, models_[i]);
83 models_[i].points = loadPointCloud<PointT> (filename,
"_points.pcd");
84 models_[i].keypoints = loadPointCloud<PointT> (filename,
"_keypoints.pcd");
85 models_[i].local_descriptors = loadPointCloud<LocalDescriptorT> (filename,
"_localdesc.pcd");
86 models_[i].global_descriptor = loadPointCloud<GlobalDescriptorT> (filename,
"_globaldesc.pcd");
88 *descriptors_ += *(models_[i].global_descriptor);
91 kdtree_->setInputCloud (descriptors_);
98 constructObjectModel (query_cloud, query_object);
101 std::vector<int> nn_index (1);
102 std::vector<float> nn_sqr_distance (1);
103 kdtree_->nearestKSearch (query_descriptor, 1, nn_index, nn_sqr_distance);
104 const int & best_match = nn_index[0];
106 return (models_[best_match]);
113 constructObjectModel (query_cloud, query_object);
116 std::vector<int> nn_index (1);
117 std::vector<float> nn_sqr_distance (1);
118 kdtree_->nearestKSearch (query_descriptor, 1, nn_index, nn_sqr_distance);
119 const int & best_match = nn_index[0];
121 PointCloudPtr output = alignModelPoints (models_[best_match], query_object, params_);
129 output.
points = applyFiltersAndSegment (points, params_);
131 SurfaceNormalsPtr normals;
147 std::vector<pcl::PointIndices> cluster_indices;
151 PointCloudPtr largest_cluster (
new PointCloud);
154 return (largest_cluster);
160 SurfaceNormalsPtr & normals_out, PointCloudPtr & keypoints_out,
161 LocalDescriptorsPtr & local_descriptors_out, GlobalDescriptorsPtr & global_descriptor_out)
const 168 local_descriptors_out = computeLocalDescriptors (points, normals_out, keypoints_out,
171 global_descriptor_out = computeGlobalDescriptor (points, normals_out);
179 Eigen::Matrix4f tform;
186 tform = refineAlignment (source.
points, target.
points, tform,
197 std::vector<ObjectModel> models_;
198 GlobalDescriptorsPtr descriptors_;
float local_descriptor_radius
float plane_inlier_distance_threshold
float initial_alignment_min_sample_distance
KdTreeFLANN is a generic type of 3D spatial locator using kD-tree structures.
int outlier_rejection_min_neighbors
float keypoints_nr_scales_per_octave
void estimateFeatures(const PointCloudPtr &points, const ObjectRecognitionParameters ¶ms, SurfaceNormalsPtr &normals_out, PointCloudPtr &keypoints_out, LocalDescriptorsPtr &local_descriptors_out, GlobalDescriptorsPtr &global_descriptor_out) const
float icp_max_correspondence_distance
float surface_normal_radius
GlobalDescriptorsPtr global_descriptor
float initial_alignment_max_correspondence_distance
void populateDatabase(const std::vector< std::string > &filenames)
PointCloudPtr alignModelPoints(const ObjectModel &source, const ObjectModel &target, const ObjectRecognitionParameters ¶ms) const
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.
float outlier_rejection_radius
float downsample_leaf_size
boost::shared_ptr< KdTreeFLANN< PointT, Dist > > Ptr
float icp_outlier_rejection_threshold
ObjectRecognition(const ObjectRecognitionParameters ¶ms)
int max_ransac_iterations
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Transform< Scalar, 3, Eigen::Affine > &transform, bool copy_all_fields=true)
Apply an affine transform defined by an Eigen Transform.
PointCloudPtr applyFiltersAndSegment(const PointCloudPtr &input, const ObjectRecognitionParameters ¶ms) const
LocalDescriptorsPtr local_descriptors
float icp_transformation_epsilon
int loadPCDFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud)
Load a PCD v.6 file into a templated PointCloud type.
float keypoints_min_scale
A point structure representing the Viewpoint Feature Histogram (VFH).
float keypoints_nr_octaves
PointCloudPtr recognizeAndAlignPoints(const PointCloudPtr &query_cloud)
int initial_alignment_nr_iterations
float keypoints_min_contrast
const ObjectModel & recognizeObject(const PointCloudPtr &query_cloud)
void constructObjectModel(const PointCloudPtr &points, ObjectModel &output) const