Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 #include <opencv2/highgui/highgui.hpp>
00036 #include <sstream>
00037 
00038 #include <cpl_visual_features/features/lm_filter_bank.h>
00039 
00040 using cv::Mat;
00041 using std::vector;
00042 using namespace cpl_visual_features;
00043 
00044 void usage(std::string exec_name)
00045 {
00046   ROS_ERROR_STREAM("usage: "
00047                    << exec_name
00048                    << " image_path"
00049                    << " image_count"
00050                    << " image_type"
00051                    << " save_path"
00052                    << " [num_centers] [attempts]");
00053 }
00054 
00055 int main(int argc, char** argv)
00056 {
00057   
00058   int img_count = 1;
00059   int num_centers = 20;
00060   int attempts = 1;
00061   std::string img_path = "";
00062   std::string img_sfx = "";
00063   std::string centers_path = "";
00064 
00065   static const int min_args = 5;
00066   static const int max_args = 7;
00067   if (argc < min_args || argc > max_args)
00068     usage(argv[0]);
00069 
00070   img_path = argv[1];
00071   img_count = atoi(argv[2]);
00072   img_sfx = argv[3];
00073   centers_path = argv[4];
00074   if (argc > 5)
00075     num_centers = atoi(argv[5]);
00076   if (argc > 6)
00077     attempts = atoi(argv[6]);
00078 
00079   LMFilterBank lfb;
00080   
00081   vector<vector<TextonFeature> > training_features;
00082 
00083   for (int i = 0; i < img_count; i++)
00084   {
00085     std::stringstream filepath;
00086     filepath << img_path << i << "." << img_sfx;
00087 
00088     ROS_INFO_STREAM("Extracting from image " << i );
00089 
00090     Mat frame;
00091     frame = cv::imread(filepath.str());
00092     try
00093     {
00094       training_features.push_back(lfb.extractRawFeature(frame));
00095     }
00096     catch(cv::Exception e)
00097     {
00098       ROS_ERROR_STREAM(e.err);
00099     }
00100   }
00101 
00102   vector<TextonFeature> tf = lfb.clusterTextons(training_features, num_centers,
00103                                                 attempts);
00104   lfb.saveTextonCenters(tf, centers_path);
00105   return 0;
00106 }