train_textons.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Georgia Institute of Technology
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Georgia Institute of Technology nor the names of
00018  *     its contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
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   // Parameters to read from the command line
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   // lfb.visualizeKernels();
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 }


cpl_visual_features
Author(s): Tucker Hermans
autogenerated on Wed Nov 27 2013 11:52:36