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: example_sift_z_keypoint_estimation.cpp 6062 2012-06-29 08:53:59Z svn $ 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 examples shows how to estimate the SIFT points based on the 00053 * z gradient of the 3D points than using the Intensity gradient as 00054 * usually used for SIFT keypoint estimation. 00055 */ 00056 00057 namespace pcl 00058 { 00059 template<> 00060 struct SIFTKeypointFieldSelector<PointXYZ> 00061 { 00062 inline float 00063 operator () (const PointXYZ &p) const 00064 { 00065 return p.z; 00066 } 00067 }; 00068 } 00069 00070 int 00071 main(int, char** argv) 00072 { 00073 std::string filename = argv[1]; 00074 std::cout << "Reading " << filename << std::endl; 00075 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>); 00076 if(pcl::io::loadPCDFile<pcl::PointXYZ> (filename, *cloud_xyz) == -1) // load the file 00077 { 00078 PCL_ERROR ("Couldn't read file"); 00079 return -1; 00080 } 00081 std::cout << "points: " << cloud_xyz->points.size () <<std::endl; 00082 00083 // Parameters for sift computation 00084 const float min_scale = 0.005f; 00085 const int n_octaves = 6; 00086 const int n_scales_per_octave = 4; 00087 const float min_contrast = 0.005f; 00088 00089 // Estimate the sift interest points using z values from xyz as the Intensity variants 00090 pcl::SIFTKeypoint<pcl::PointXYZ, pcl::PointWithScale> sift; 00091 pcl::PointCloud<pcl::PointWithScale> result; 00092 pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ> ()); 00093 sift.setSearchMethod(tree); 00094 sift.setScales(min_scale, n_octaves, n_scales_per_octave); 00095 sift.setMinimumContrast(min_contrast); 00096 sift.setInputCloud(cloud_xyz); 00097 sift.compute(result); 00098 00099 std::cout << "No of SIFT points in the result are " << result.points.size () << std::endl; 00100 00101 /* 00102 // Copying the pointwithscale to pointxyz so as visualize the cloud 00103 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_temp (new pcl::PointCloud<pcl::PointXYZ>); 00104 copyPointCloud(result, *cloud_temp); 00105 std::cout << "SIFT points in the result are " << cloud_temp->points.size () << std::endl; 00106 // Visualization of keypoints along with the original cloud 00107 pcl::visualization::PCLVisualizer viewer("PCL Viewer"); 00108 pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> keypoints_color_handler (cloud_temp, 0, 255, 0); 00109 pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> cloud_color_handler (cloud_xyz, 255, 0, 0); 00110 viewer.setBackgroundColor( 0.0, 0.0, 0.0 ); 00111 viewer.addPointCloud(cloud_xyz, cloud_color_handler, "cloud"); 00112 viewer.addPointCloud(cloud_temp, keypoints_color_handler, "keypoints"); 00113 viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints"); 00114 00115 while(!viewer.wasStopped ()) 00116 { 00117 viewer.spinOnce (); 00118 } 00119 */ 00120 00121 return 0; 00122 00123 }