statistical_multiscale_interest_region_extraction_example.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-2012, 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  */
00037 
00038 #include <pcl/features/statistical_multiscale_interest_region_extraction.h>
00039 #include <pcl/io/pcd_io.h>
00040 #include <pcl/filters/voxel_grid.h>
00041 #include <pcl/filters/extract_indices.h>
00042 
00043 
00044 using namespace pcl;
00045 using namespace std;
00046 
00047 const float subsampling_leaf_size = 0.003f;
00048 const float base_scale = 0.005f;
00049 
00050 
00051 int
00052 main (int, char **argv)
00053 {
00054   PointCloud<PointXYZ>::Ptr cloud (new PointCloud<PointXYZ> ());
00055 
00056   PCDReader reader;
00057   reader.read (argv[1], *cloud);
00058   PCL_INFO ("Cloud read: %s\n", argv[1]);
00059   cerr << "cloud has #points: " << cloud->points.size () << endl;
00060 
00061   PointCloud<PointXYZ>::Ptr cloud_subsampled (new PointCloud<PointXYZ> ());
00062   VoxelGrid<PointXYZ> subsampling_filter;
00063   subsampling_filter.setInputCloud (cloud);
00064   subsampling_filter.setLeafSize (subsampling_leaf_size, subsampling_leaf_size, subsampling_leaf_size);
00065   subsampling_filter.filter (*cloud_subsampled);
00066   cerr << "subsampled cloud has #points: " << cloud_subsampled->points.size () << endl;
00067 
00068   StatisticalMultiscaleInterestRegionExtraction<PointXYZ> region_extraction;
00069   std::vector<float> scale_vector;
00070   PCL_INFO ("Scale values that will be used: ");
00071   float base_scale_aux = base_scale;
00072   for (size_t scales = 0; scales < 7; ++scales)
00073   {
00074     PCL_INFO ("%f ", base_scale_aux);
00075     scale_vector.push_back (base_scale_aux);
00076     base_scale_aux *= 1.6f;
00077   }
00078   PCL_INFO ("\n");
00079   region_extraction.setInputCloud (cloud_subsampled);
00080   region_extraction.setScalesVector (scale_vector);
00081   std::list<IndicesPtr> rois;
00082   region_extraction.computeRegionsOfInterest (rois);
00083 
00084   PCL_INFO ("Regions of interest found: %d\n", rois.size ());
00085   pcl::ExtractIndices<PointXYZ> extract_indices_filter;
00086   unsigned int roi_count = 0;
00087   for (std::list<IndicesPtr>::iterator l_it = rois.begin (); l_it != rois.end (); ++l_it)
00088   {
00089     PointCloud<PointXYZ> roi_points;
00090     extract_indices_filter.setInputCloud (cloud_subsampled);
00091     extract_indices_filter.setIndices (*l_it);
00092     extract_indices_filter.filter (roi_points);
00093 
00094     char filename[512];
00095     sprintf (filename, "roi_%03d.pcd", ++roi_count);
00096     io::savePCDFileASCII (filename, roi_points);
00097   }
00098 
00099   io::savePCDFileASCII ("subsampled_input.pcd", *cloud_subsampled);
00100 
00101   return 0;
00102 }


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:18:02