example_sift_normal_keypoint_estimation.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Point Cloud Library (PCL) - www.pointclouds.org
00005  * Copyright (c) 2009-2011, Willow Garage, Inc.
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * * Redistributions of source code must retain the above copyright
00014  *   notice, this list of conditions and the following disclaimer.
00015  * * Redistributions in binary form must reproduce the above
00016  *   copyright notice, this list of conditions and the following
00017  *   disclaimer in the documentation and/or other materials provided
00018  *   with the distribution.
00019  * * Neither the name of Willow Garage, Inc. nor the names of its
00020  *   contributors may be used to endorse or promote products derived
00021  *   from this software without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  * POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id$
00037  *
00038  *
00039  */
00040 
00041 // STL
00042 #include <iostream>
00043 
00044 // PCL
00045 #include <pcl/io/pcd_io.h>
00046 #include <pcl/point_types.h>
00047 #include <pcl/common/io.h>
00048 #include <pcl/keypoints/sift_keypoint.h>
00049 #include <pcl/features/normal_3d.h>
00050 // #include <pcl/visualization/pcl_visualizer.h>
00051 
00052 /* This example shows how to estimate the SIFT points based on the
00053  * Normal gradients i.e. curvature than using the Intensity gradient
00054  * as usually used for SIFT keypoint estimation.
00055  */
00056 
00057 int
00058 main(int, char** argv)
00059 {
00060   std::string filename = argv[1];
00061   std::cout << "Reading " << filename << std::endl;
00062   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
00063   if(pcl::io::loadPCDFile<pcl::PointXYZ> (filename, *cloud_xyz) == -1) // load the file
00064   {
00065     PCL_ERROR ("Couldn't read file");
00066     return -1;
00067   }
00068   std::cout << "points: " << cloud_xyz->points.size () <<std::endl;
00069   
00070   // Parameters for sift computation
00071   const float min_scale = 0.01f;
00072   const int n_octaves = 3;
00073   const int n_scales_per_octave = 4;
00074   const float min_contrast = 0.001f;
00075   
00076   // Estimate the normals of the cloud_xyz
00077   pcl::NormalEstimation<pcl::PointXYZ, pcl::PointNormal> ne;
00078   pcl::PointCloud<pcl::PointNormal>::Ptr cloud_normals (new pcl::PointCloud<pcl::PointNormal>);
00079   pcl::search::KdTree<pcl::PointXYZ>::Ptr tree_n(new pcl::search::KdTree<pcl::PointXYZ>());
00080 
00081   ne.setInputCloud(cloud_xyz);
00082   ne.setSearchMethod(tree_n);
00083   ne.setRadiusSearch(0.2);
00084   ne.compute(*cloud_normals);
00085 
00086   // Copy the xyz info from cloud_xyz and add it to cloud_normals as the xyz field in PointNormals estimation is zero
00087   for(size_t i = 0; i<cloud_normals->points.size(); ++i)
00088   {
00089     cloud_normals->points[i].x = cloud_xyz->points[i].x;
00090     cloud_normals->points[i].y = cloud_xyz->points[i].y;
00091     cloud_normals->points[i].z = cloud_xyz->points[i].z;
00092   }
00093 
00094   // Estimate the sift interest points using normals values from xyz as the Intensity variants
00095   pcl::SIFTKeypoint<pcl::PointNormal, pcl::PointWithScale> sift;
00096   pcl::PointCloud<pcl::PointWithScale> result;
00097   pcl::search::KdTree<pcl::PointNormal>::Ptr tree(new pcl::search::KdTree<pcl::PointNormal> ());
00098   sift.setSearchMethod(tree);
00099   sift.setScales(min_scale, n_octaves, n_scales_per_octave);
00100   sift.setMinimumContrast(min_contrast);
00101   sift.setInputCloud(cloud_normals);
00102   sift.compute(result);
00103 
00104   std::cout << "No of SIFT points in the result are " << result.points.size () << std::endl;
00105 
00106 /*
00107   // Copying the pointwithscale to pointxyz so as visualize the cloud
00108   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_temp (new pcl::PointCloud<pcl::PointXYZ>);
00109   copyPointCloud(result, *cloud_temp);
00110   std::cout << "SIFT points in the cloud_temp are " << cloud_temp->points.size () << std::endl;
00111   
00112   
00113   // Visualization of keypoints along with the original cloud
00114   pcl::visualization::PCLVisualizer viewer("PCL Viewer");
00115   pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> keypoints_color_handler (cloud_temp, 0, 255, 0);
00116   pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> cloud_color_handler (cloud_xyz, 255, 0, 0);
00117   viewer.setBackgroundColor( 0.0, 0.0, 0.0 );
00118   viewer.addPointCloud(cloud_xyz, cloud_color_handler, "cloud");
00119   viewer.addPointCloud(cloud_temp, keypoints_color_handler, "keypoints");
00120   viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints");
00121   
00122   while(!viewer.wasStopped ())
00123   {
00124   viewer.spinOnce ();
00125   }
00126   
00127 */
00128 
00129   return 0;
00130   
00131 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:23:36