test_object_recognition.cpp
Go to the documentation of this file.
00001 #include "object_recognition.h"
00002 
00003 #include <string>
00004 #include <sstream>
00005 #include <iostream>
00006 #include <pcl/console/parse.h>
00007 #include <pcl/io/pcd_io.h>
00008 #include <pcl/visualization/pcl_visualizer.h>
00009 
00010 //./test_object_recognition /home/aitor/PCL_tutorial_iros/data/minnie/raw_4.pcd --objects_root_path /home/aitor/PCL_tutorial_iros/data --objects ../../data/objects.txt --filter ../../params/filter.txt --segment ../../params/segment.txt --feature ../../params/feature.txt --registration ../../params/registration.txt
00011 
00012 int 
00013 main (int argc, char ** argv)
00014 {
00015   if (argc < 3) 
00016   {
00017     pcl::console::print_info ("Syntax is: %s query.pcd <options>\n", argv[0]);
00018     pcl::console::print_info ("  where options are:\n");
00019     pcl::console::print_info ("    --objects_root_path root_path ......... Root path to append to files in object_files.txt \n");
00020     pcl::console::print_info ("    --objects object_files.txt ......... A list of the files to use as exemplars\n");
00021     pcl::console::print_info ("    --filter parameters.txt ............ Threshold, downsample, and denoise\n");
00022     pcl::console::print_info ("    --segment parameters.txt  .......... Remove dominant plane and cluster\n");
00023     pcl::console::print_info ("    --feature parameters.txt ........... Compute normals, keypoints, and descriptors\n");
00024     pcl::console::print_info ("    --registration parameters.txt ...... Align best fitting model to query\n");
00025     pcl::console::print_info ("  and where the parameters files must contain the following values (one per line):\n");
00026     pcl::console::print_info ("    filter parameters:\n");
00027     pcl::console::print_info ("      * min_depth\n");
00028     pcl::console::print_info ("      * max_depth\n");
00029     pcl::console::print_info ("      * downsample_leaf_size\n");
00030     pcl::console::print_info ("      * outlier_rejection_radius\n");
00031     pcl::console::print_info ("      * outlier_rejection_min_neighbors\n");
00032     pcl::console::print_info ("    segmentation parameters:\n");
00033     pcl::console::print_info ("      * plane_inlier_distance_threshold\n");
00034     pcl::console::print_info ("      * max_ransac_iterations\n");
00035     pcl::console::print_info ("      * cluster_tolerance\n");
00036     pcl::console::print_info ("      * min_cluster_size\n");
00037     pcl::console::print_info ("      * max_cluster_size\n");
00038     pcl::console::print_info ("    feature estimation parameters:\n");
00039     pcl::console::print_info ("      * surface_normal_radius\n");
00040     pcl::console::print_info ("      * keypoints_min_scale\n");
00041     pcl::console::print_info ("      * keypoints_nr_octaves\n");
00042     pcl::console::print_info ("      * keypoints_nr_scales_per_octave\n");
00043     pcl::console::print_info ("      * keypoints_min_contrast\n");
00044     pcl::console::print_info ("      * local_descriptor_radius\n");
00045     pcl::console::print_info ("    registration parameters:\n");
00046     pcl::console::print_info ("      * initial_alignment_min_sample_distance\n");
00047     pcl::console::print_info ("      * initial_alignment_max_correspondence_distance\n");
00048     pcl::console::print_info ("      * initial_alignment_nr_iterations\n");
00049     pcl::console::print_info ("      * icp_max_correspondence_distance\n");
00050     pcl::console::print_info ("      * icp_rejection_threshold\n");
00051     pcl::console::print_info ("      * icp_transformation_epsilon\n");
00052     pcl::console::print_info ("      * icp_max_iterations\n");
00053 
00054     return (1);
00055   }
00056 
00057   // Load input file
00058   PointCloudPtr query (new PointCloud);
00059   pcl::io::loadPCDFile (argv[1], *query);
00060   pcl::console::print_info ("Loaded %s (%zu points)\n", argv[1], query->size ());    
00061 
00062   ifstream input_stream;
00063   ObjectRecognitionParameters params;
00064 
00065   // Parse the exemplar files
00066   std::string objects_root_path;
00067   pcl::console::parse_argument (argc, argv, "--objects_root_path", objects_root_path);
00068 
00069   std::string objects_file;
00070   pcl::console::parse_argument (argc, argv, "--objects", objects_file);
00071   std::vector<std::string> exemplar_filenames (0);
00072   input_stream.open (objects_file.c_str ());
00073   if (input_stream.is_open ())
00074   {
00075     while (input_stream.good ())
00076     {
00077       std::string filename;
00078       input_stream >> filename;
00079       if (filename.size () > 0)
00080       {
00081         exemplar_filenames.push_back (objects_root_path + "/" + filename);
00082       }
00083     }
00084     input_stream.close ();
00085   }
00086   
00087   //Parse filter parameters
00088   std::string filter_parameters_file;
00089   pcl::console::parse_argument (argc, argv, "--filter", filter_parameters_file) > 0;    
00090   input_stream.open (filter_parameters_file.c_str ());
00091   if (input_stream.is_open())
00092   {
00093     input_stream >> params.min_depth;
00094     input_stream >> params.max_depth;
00095     input_stream >> params.downsample_leaf_size;
00096     input_stream >> params.outlier_rejection_radius;
00097     input_stream >> params.outlier_rejection_min_neighbors;
00098     input_stream.close ();
00099   }
00100   else
00101   {
00102     pcl::console::print_info ("Failed to open the filter parameters file (%s)\n", filter_parameters_file.c_str ());
00103     return (1);
00104   }  
00105   
00106   // Parse segmentation parameters
00107   std::string segmentation_parameters_file;
00108   pcl::console::parse_argument (argc, argv, "--segment", segmentation_parameters_file) > 0;    
00109   input_stream.open (segmentation_parameters_file.c_str ());
00110   if (input_stream.is_open())
00111   {
00112     input_stream >> params.plane_inlier_distance_threshold;
00113     input_stream >> params.max_ransac_iterations;
00114     input_stream >> params.cluster_tolerance;
00115     input_stream >> params.min_cluster_size;
00116     input_stream >> params.max_cluster_size;
00117     input_stream.close ();
00118   }
00119   else
00120   {
00121     pcl::console::print_info ("Failed to open the segmentation parameters file (%s)\n", 
00122                               segmentation_parameters_file.c_str ());
00123     return (1);
00124   }
00125 
00126   // Parse feature estimation parameters
00127   std::string feature_estimation_parameters_file;
00128   pcl::console::parse_argument (argc, argv, "--feature", feature_estimation_parameters_file) > 0;    
00129   input_stream.open (feature_estimation_parameters_file.c_str ());
00130   if (input_stream.is_open())
00131   {
00132     input_stream >> params.surface_normal_radius;
00133     input_stream >> params.keypoints_min_scale;
00134     input_stream >> params.keypoints_nr_octaves;
00135     input_stream >> params.keypoints_nr_scales_per_octave;
00136     input_stream >> params.keypoints_min_contrast;
00137     input_stream >> params.local_descriptor_radius;
00138     input_stream.close ();
00139   }
00140   else
00141   {
00142     pcl::console::print_info ("Failed to open the feature estimation parameters file (%s)\n", 
00143                               feature_estimation_parameters_file.c_str ());
00144     return (1);
00145   }
00146 
00147   // Parse the registration parameters
00148   std::string registration_parameters_file;
00149   pcl::console::parse_argument (argc, argv, "--registration", registration_parameters_file) > 0;    
00150   input_stream.open (registration_parameters_file.c_str ());
00151   if (input_stream.is_open())
00152   {
00153     input_stream >> params.initial_alignment_min_sample_distance;
00154     input_stream >> params.initial_alignment_max_correspondence_distance;
00155     input_stream >> params.initial_alignment_nr_iterations;
00156     input_stream >> params.icp_max_correspondence_distance;
00157     input_stream >> params.icp_outlier_rejection_threshold;
00158     input_stream >> params.icp_transformation_epsilon;
00159     input_stream >> params.icp_max_iterations;
00160     input_stream.close ();
00161   }
00162   else
00163   {
00164     pcl::console::print_info ("Failed to open the registration parameters file (%s)\n", 
00165                               registration_parameters_file.c_str ());
00166     return (1);
00167   }
00168 
00169   // Construct the ObjectDatabase
00170   ObjectRecognition obj_rec (params);
00171   obj_rec.populateDatabase (exemplar_filenames);
00172 
00173   // Find the object exemplar that best matches the query
00174   PointCloudPtr aligned_model_points = obj_rec.recognizeAndAlignPoints (query);
00175 
00176   // Visualize the results
00177   pcl::console::print_info ("Starting visualizer... Close window to exit\n");
00178   pcl::visualization::PCLVisualizer vis;
00179 
00180   pcl::visualization::PointCloudColorHandlerCustom<PointT> red (aligned_model_points, 255, 0, 0);
00181   vis.addPointCloud (aligned_model_points, red, "model");
00182   vis.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "model");
00183   vis.resetCamera ();
00184 
00185   vis.addPointCloud (query, "query");
00186   vis.spin ();
00187 
00188   return (0); 
00189 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:35:16