narf_kp.hpp
Go to the documentation of this file.
00001 
00065 template<typename Point>
00066 void Keypoints_Narf<Point>::extractFeatures(const pcl::PointCloud<Point>& point_cloud, pcl::PointCloud<NarfKPoint> &narf_descriptors) {
00067   float angular_resolution = 0.002f;
00068   float support_size = 0.3f;
00069   pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
00070   bool setUnseenToMaxRange = false;
00071 
00072   // ------------------------------
00073   // -----Setting viewpoint up-----
00074   // ------------------------------
00075   pcl::PointCloud<pcl::PointWithViewpoint> far_ranges;
00076   Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ());
00077 
00078   scene_sensor_pose = Eigen::Affine3f (Eigen::Translation3f (point_cloud.sensor_origin_[0],
00079                                                              point_cloud.sensor_origin_[1],
00080                                                              point_cloud.sensor_origin_[2])) *
00081                       Eigen::Affine3f (point_cloud.sensor_orientation_);
00082 
00083   scene_sensor_pose = scene_sensor_pose.Identity();
00084 
00085   // -----------------------------------------------
00086   // -----Create RangeImage from the PointCloud-----
00087   // -----------------------------------------------
00088   float noise_level = 0.0;
00089   float min_range = 0.0f;
00090   int border_size = 1;
00091   boost::shared_ptr<pcl::RangeImage> range_image_ptr (new pcl::RangeImage);
00092   pcl::RangeImage& range_image = *range_image_ptr;
00093   range_image.createFromPointCloud (point_cloud, angular_resolution, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f),
00094                                    scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);
00095   range_image.integrateFarRanges (far_ranges);
00096   if (setUnseenToMaxRange)
00097     range_image.setUnseenToMaxRange ();
00098 
00099   ROS_INFO("range image %d %d", range_image.height, range_image.width);
00100 
00101   // --------------------------------
00102   // -----Extract NARF keypoints-----
00103   // --------------------------------
00104   pcl::RangeImageBorderExtractor range_image_border_extractor;
00105   pcl::NarfKeypoint narf_keypoint_detector;
00106   narf_keypoint_detector.setRangeImageBorderExtractor (&range_image_border_extractor);
00107   narf_keypoint_detector.setRangeImage (&range_image);
00108   narf_keypoint_detector.getParameters ().support_size = support_size;
00109   narf_keypoint_detector.getParameters ().min_interest_value/=2;
00110   narf_keypoint_detector.getParameters ().do_non_maximum_suppression=true;
00111 
00112   pcl::PointCloud<int> keypoint_indices;
00113   narf_keypoint_detector.compute (keypoint_indices);
00114   std::cout << "Found "<<keypoint_indices.points.size ()<<" key points.\n";
00115 
00116   {
00117 #ifdef GICP_ENABLE
00118       boost::shared_ptr<pcl::search::KdTree<Point> > tree (new pcl::search::KdTree<Point>);
00119 #else
00120   #ifdef PCL_VERSION_COMPARE
00121       boost::shared_ptr<pcl::search::KdTree<Point> > tree (new pcl::search::KdTree<Point>);
00122   #else
00123       boost::shared_ptr<pcl::KdTree<Point> > tree (new pcl::KdTreeFLANN<Point>);
00124   #endif
00125 #endif
00126       pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal> ());
00127 
00128       pcl::NormalEstimation<Point, pcl::Normal> ne;
00129       ne.setSearchMethod (tree);
00130       ne.setInputCloud (point_cloud.makeShared());
00131       // Use all neighbors in a sphere of radius 3cm
00132       ne.setRadiusSearch (0.05);
00133 
00134       std::vector<int> kp_indices;
00135       for(int i=0; i<(int)keypoint_indices.size(); i++)
00136         kp_indices.push_back(keypoint_indices.points[i]);
00137 
00138       ROS_INFO("normal...");
00139       // Compute the features
00140       ne.compute (*normals);
00141 
00142       // Create the FPFH estimation class, and pass the input dataset+normals to it
00143       pcl::FPFHEstimation<Point, pcl::Normal, pcl::FPFHSignature33> fpfh;
00144       fpfh.setInputCloud (point_cloud.makeShared());
00145       fpfh.setInputNormals (normals);
00146 
00147       fpfh.setSearchMethod (tree);
00148       fpfh.setRadiusSearch (radius_);
00149 
00150       pcl::PointCloud<pcl::FPFHSignature33> pc_fpfh;
00151 
00152       ROS_INFO("fpfh...");
00153       // Compute the features
00154       fpfh.compute (pc_fpfh);
00155 
00156       ROS_INFO("finishing...");
00157 
00158 #ifdef PCL_VERSION_COMPARE
00159       tree.reset(new pcl::search::KdTree<Point>);
00160 #else
00161       tree.reset(new pcl::KdTreeFLANN<Point>);
00162 #endif
00163       tree->setInputCloud(point_cloud.makeShared());
00164 
00165       narf_descriptors.clear();
00166       for(int i=0; i<(int)keypoint_indices.size(); i++) {
00167         int ind=keypoint_indices.points[i];
00168 
00169         Point pp;
00170         NarfKPoint p;
00171         pp.x = p.x = range_image.points[ind].x;
00172         pp.y = p.y = range_image.points[ind].y;
00173         pp.z = p.z = range_image.points[ind].z;
00174 
00175         std::vector<int> k_indices; std::vector<float> k_sqr_distances;
00176         if(!tree->nearestKSearch(pp, 1, k_indices,k_sqr_distances))
00177           continue;
00178 
00179         int ind2 = k_indices[0];
00180         memcpy(p.histogram,pc_fpfh[ind2].histogram, 33*sizeof(float));
00181         narf_descriptors.push_back(p);
00182       }
00183 
00184   }
00185 }


cob_3d_registration
Author(s): Joshua Hampp
autogenerated on Wed Aug 26 2015 11:02:36