build_object_model.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 int 
00011 main (int argc, char ** argv)
00012 {
00013   if (argc < 3) 
00014   {
00015     pcl::console::print_info ("Syntax is: %s input.pcd output <options>\n", argv[0]);
00016     pcl::console::print_info ("  where options are:\n");
00017     pcl::console::print_info ("    --filter parameters.txt ............ Threshold, downsample, and denoise\n");
00018     pcl::console::print_info ("    --segment parameters.txt  .......... Remove dominant plane and cluster\n");
00019     pcl::console::print_info ("    --feature parameters.txt ........... Compute normals, keypoints, and descriptors\n");
00020     pcl::console::print_info ("    --registration parameters.txt ...... Align best fitting model to query\n");
00021     pcl::console::print_info ("  and where the parameters files must contain the following values (one per line):\n");
00022     pcl::console::print_info ("    filter parameters:\n");
00023     pcl::console::print_info ("      * min_depth\n");
00024     pcl::console::print_info ("      * max_depth\n");
00025     pcl::console::print_info ("      * downsample_leaf_size\n");
00026     pcl::console::print_info ("      * outlier_rejection_radius\n");
00027     pcl::console::print_info ("      * outlier_rejection_min_neighbors\n");
00028     pcl::console::print_info ("    segmentation parameters:\n");
00029     pcl::console::print_info ("      * plane_inlier_distance_threshold\n");
00030     pcl::console::print_info ("      * max_ransac_iterations\n");
00031     pcl::console::print_info ("      * cluster_tolerance\n");
00032     pcl::console::print_info ("      * min_cluster_size\n");
00033     pcl::console::print_info ("      * max_cluster_size\n");
00034     pcl::console::print_info ("    feature estimation parameters:\n");
00035     pcl::console::print_info ("      * surface_normal_radius\n");
00036     pcl::console::print_info ("      * keypoints_min_scale\n");
00037     pcl::console::print_info ("      * keypoints_nr_octaves\n");
00038     pcl::console::print_info ("      * keypoints_nr_scales_per_octave\n");
00039     pcl::console::print_info ("      * keypoints_min_contrast\n");
00040     pcl::console::print_info ("      * local_descriptor_radius\n");
00041     pcl::console::print_info ("    registration parameters:\n");
00042     pcl::console::print_info ("      * initial_alignment_min_sample_distance\n");
00043     pcl::console::print_info ("      * initial_alignment_max_correspondence_distance\n");
00044     pcl::console::print_info ("      * initial_alignment_nr_iterations\n");
00045     pcl::console::print_info ("      * icp_max_correspondence_distance\n");
00046     pcl::console::print_info ("      * icp_rejection_threshold\n");
00047     pcl::console::print_info ("      * icp_transformation_epsilon\n");
00048     pcl::console::print_info ("      * icp_max_iterations\n");
00049     pcl::console::print_info ("Note: The output's base filename must be specified without the .pcd extension\n");
00050     pcl::console::print_info ("      Four output files will be created with the following suffixes:\n");
00051     pcl::console::print_info ("        * '_points.pcd'\n");
00052     pcl::console::print_info ("        * '_keypoints.pcd'\n");
00053     pcl::console::print_info ("        * '_localdesc.pcd'\n");
00054     pcl::console::print_info ("        * '_globaldesc.pcd'\n");
00055 
00056     return (1);
00057   }
00058 
00059   // Load input file
00060   PointCloudPtr input (new PointCloud);
00061   pcl::io::loadPCDFile (argv[1], *input);
00062   pcl::console::print_info ("Loaded %s (%zu points)\n", argv[1], input->size ());    
00063   
00064   ObjectRecognitionParameters params;
00065   ifstream params_stream;
00066 
00067   //Parse filter parameters
00068   std::string filter_parameters_file;
00069   pcl::console::parse_argument (argc, argv, "--filter", filter_parameters_file) > 0;    
00070   params_stream.open (filter_parameters_file.c_str ());
00071   if (params_stream.is_open())
00072   {
00073     params_stream >> params.min_depth;
00074     params_stream >> params.max_depth;
00075     params_stream >> params.downsample_leaf_size;
00076     params_stream >> params.outlier_rejection_radius;
00077     params_stream >> params.outlier_rejection_min_neighbors;
00078     params_stream.close ();
00079   }
00080   else
00081   {
00082     pcl::console::print_info ("Failed to open the filter parameters file (%s)\n", filter_parameters_file.c_str ());
00083     return (1);
00084   }  
00085   
00086   // Parse segmentation parameters
00087   std::string segmentation_parameters_file;
00088   pcl::console::parse_argument (argc, argv, "--segment", segmentation_parameters_file) > 0;    
00089   params_stream.open (segmentation_parameters_file.c_str ());
00090   if (params_stream.is_open())
00091   {
00092     params_stream >> params.plane_inlier_distance_threshold;
00093     params_stream >> params.max_ransac_iterations;
00094     params_stream >> params.cluster_tolerance;
00095     params_stream >> params.min_cluster_size;
00096     params_stream >> params.max_cluster_size;
00097     params_stream.close ();
00098   }
00099   else
00100   {
00101     pcl::console::print_info ("Failed to open the segmentation parameters file (%s)\n", 
00102                               segmentation_parameters_file.c_str ());
00103     return (1);
00104   }
00105 
00106   // Parse feature estimation parameters
00107   std::string feature_estimation_parameters_file;
00108   pcl::console::parse_argument (argc, argv, "--feature", feature_estimation_parameters_file) > 0;    
00109   params_stream.open (feature_estimation_parameters_file.c_str ());
00110   if (params_stream.is_open())
00111   {
00112     params_stream >> params.surface_normal_radius;
00113     params_stream >> params.keypoints_min_scale;
00114     params_stream >> params.keypoints_nr_octaves;
00115     params_stream >> params.keypoints_nr_scales_per_octave;
00116     params_stream >> params.keypoints_min_contrast;
00117     params_stream >> params.local_descriptor_radius;
00118     params_stream.close ();
00119   }
00120   else
00121   {
00122     pcl::console::print_info ("Failed to open the feature estimation parameters file (%s)\n", 
00123                               feature_estimation_parameters_file.c_str ());
00124     return (1);
00125   }
00126 
00127   // Parse the registration parameters
00128   std::string registration_parameters_file;
00129   pcl::console::parse_argument (argc, argv, "--registration", registration_parameters_file) > 0;    
00130   params_stream.open (registration_parameters_file.c_str ());
00131   if (params_stream.is_open())
00132   {
00133     params_stream >> params.initial_alignment_min_sample_distance;
00134     params_stream >> params.initial_alignment_max_correspondence_distance;
00135     params_stream >> params.initial_alignment_nr_iterations;
00136     params_stream >> params.icp_max_correspondence_distance;
00137     params_stream >> params.icp_outlier_rejection_threshold;
00138     params_stream >> params.icp_transformation_epsilon;
00139     params_stream >> params.icp_max_iterations;
00140     params_stream.close ();
00141   }
00142   else
00143   {
00144     pcl::console::print_info ("Failed to open the registration parameters file (%s)\n", 
00145                               registration_parameters_file.c_str ());
00146     return (1);
00147   }
00148 
00149   // Construct the object model
00150   ObjectRecognition obj_rec (params);
00151   ObjectModel model;
00152   obj_rec.constructObjectModel (input, model);
00153 
00154   // Save the model files
00155   std::string base_filename (argv[2]), output_filename;
00156 
00157   output_filename = base_filename;
00158   output_filename.append ("_points.pcd");
00159   pcl::io::savePCDFile (output_filename, *(model.points));
00160   pcl::console::print_info ("Saved points as %s\n", output_filename.c_str ());
00161 
00162   output_filename = base_filename;
00163   output_filename.append ("_keypoints.pcd");
00164   pcl::io::savePCDFile (output_filename, *(model.keypoints));
00165   pcl::console::print_info ("Saved keypoints as %s\n", output_filename.c_str ());
00166   
00167   output_filename = base_filename;
00168   output_filename.append ("_localdesc.pcd");
00169   pcl::io::savePCDFile (output_filename, *(model.local_descriptors));
00170   pcl::console::print_info ("Saved local descriptors as %s\n", output_filename.c_str ());
00171   
00172   output_filename = base_filename;
00173   output_filename.append ("_globaldesc.pcd");
00174   pcl::io::savePCDFile (output_filename, *(model.global_descriptor));
00175   pcl::console::print_info ("Saved global descriptor as %s\n", output_filename.c_str ());
00176 
00177   return (0); 
00178 }


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