example_sift_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/keypoints/impl/sift_keypoint.hpp>
00050 #include <pcl/features/normal_3d.h>
00051 // #include <pcl/visualization/pcl_visualizer.h>
00052         
00053 int
00054 main(int, char** argv)
00055 {
00056   std::string filename = argv[1];
00057   std::cout << "Reading " << filename << std::endl;
00058   pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
00059   if(pcl::io::loadPCDFile<pcl::PointXYZRGB> (filename, *cloud) == -1) // load the file
00060   {
00061   PCL_ERROR ("Couldn't read file");
00062   return -1;
00063   }
00064   std::cout << "points: " << cloud->points.size () <<std::endl;
00065   
00066   // Parameters for sift computation
00067   const float min_scale = 0.1f;
00068   const int n_octaves = 6;
00069   const int n_scales_per_octave = 10;
00070   const float min_contrast = 0.5f;
00071   
00072   
00073   // Estimate the sift interest points using Intensity values from RGB values
00074   pcl::SIFTKeypoint<pcl::PointXYZRGB, pcl::PointWithScale> sift;
00075   pcl::PointCloud<pcl::PointWithScale> result;
00076   pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZRGB> ());
00077   sift.setSearchMethod(tree);
00078   sift.setScales(min_scale, n_octaves, n_scales_per_octave);
00079   sift.setMinimumContrast(min_contrast);
00080   sift.setInputCloud(cloud);
00081   sift.compute(result);
00082   
00083   // Copying the pointwithscale to pointxyz so as visualize the cloud
00084   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_temp (new pcl::PointCloud<pcl::PointXYZ>);
00085   copyPointCloud(result, *cloud_temp);
00086 
00087   // Saving the resultant cloud 
00088   std::cout << "Resulting sift points are of size: " << cloud_temp->points.size () <<std::endl;
00089   pcl::io::savePCDFileASCII("sift_points.pcd", *cloud_temp);
00090 
00091   
00092 /*  
00093   // Visualization of keypoints along with the original cloud
00094   pcl::visualization::PCLVisualizer viewer("PCL Viewer");
00095   pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> keypoints_color_handler (cloud_temp, 0, 255, 0);
00096   pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> cloud_color_handler (cloud, 255, 255, 0);
00097   viewer.setBackgroundColor( 0.0, 0.0, 0.0 );
00098   viewer.addPointCloud(cloud, "cloud");
00099   viewer.addPointCloud(cloud_temp, keypoints_color_handler, "keypoints");
00100   viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints");
00101   
00102   while(!viewer.wasStopped ())
00103   {
00104   viewer.spinOnce ();
00105   }
00106 */  
00107 
00108   
00109   return 0;
00110   
00111 }


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