ObjRecBOF.H

Go to the documentation of this file.
00001 /*!@file ObjRec/ObjRecBOF.H ObjRec using bag of features */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/ObjRec/ObjRecBOF.H $
00035 // $Id: ObjRecBOF.H 13716 2010-07-28 22:07:03Z itti $
00036 //
00037 
00038 #ifndef ObjRecBOF_H_DEFINED
00039 #define ObjRecBOF_H_DEFINED
00040 
00041 #include "Image/OpenCVUtil.H"
00042 #include "Component/ModelComponent.H"
00043 #include "Component/ModelParam.H"
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 #include "SIFT/Histogram.H"
00047 #include "SIFT/FeatureVector.H"
00048 
00049 class ObjRecBOF : public ModelComponent
00050 {
00051 public:
00052 
00053   struct Keypoint
00054   {
00055     double x;
00056     double y;
00057     double scale;
00058     double ori;
00059     std::vector<double> fv;
00060     int codeWord; //the code work of fv
00061   };
00062 
00063   struct Object
00064   {
00065     std::string name;
00066     std::vector<Keypoint> keypoints;
00067   };
00068 
00069 
00070   //Constructor
00071   ObjRecBOF(OptionManager& mgr,
00072           const std::string& descrName = "ObjRecBOF",
00073           const std::string& tagName = "ObjRecBOF");
00074   ~ObjRecBOF();
00075 
00076   //###########################################################
00077 
00078   void start2();
00079 
00080   void train(const Image<PixRGB<byte> > &img, const std::string label);
00081   void train(const std::string &name, int cls);
00082   std::string test(const Image<PixRGB<byte> > &img);
00083 
00084   Image<float> extractFeatures(const Image<PixRGB<byte> > &img);
00085 
00086   void finalizeTraining();
00087   void finalizeTesting();
00088 
00089   void extractCodeWords(const char* dirname);
00090   void getCodeWords(int numCodeWords);
00091   void readCodeWords(const char* filename);
00092   int assignCodeWord(const std::vector<double> &fv);
00093   void assignCodeWords();
00094 
00095   void getObjCodeWords(const std::string &name);
00096 
00097   void readSaliencyFeatures(const char* dirname);
00098   void getSaliencyKeypoints(const std::string &name);
00099   std::vector<Keypoint> readSaliencyKeypoints(const char *filename);
00100   std::vector<Keypoint> readSIFTKeypoints(const char *filename);
00101   void printCodeWords();
00102   void printAssignedCodeWords();
00103   void printFeatures();
00104 
00105   //Gabor features
00106   void extractGaborFeatures(const Image<PixRGB<byte> > &img);
00107 
00108   //Sift features
00109   void getSIFTKeypoints(const std::string &name);
00110   void extractSIFTFeatures(const Image<PixRGB<byte> > &img);
00111   std::vector<std::vector<byte> > getSiftDescriptor(const Image<float> &lum,
00112       const float x, const float y, const float s);
00113   void calculateOrientationVector(const float x, const float y, const float s,
00114       const Image<float>& gradmag, const Image<float>& gradorie, Histogram& OV);
00115   std::vector<std::vector<byte> > createVectorsAndKeypoints(const float x, const float y, const float s,
00116       const Image<float>& gradmag, const Image<float>& gradorie, Histogram& OV);
00117 
00118   //Ilab sift features
00119   void getIlabSIFTKeypoints(const std::string &name);
00120   std::vector<Keypoint> readIlabSIFTKeypoints(const char *filename);
00121 
00122 
00123 private:
00124   int itsNumOriArray;
00125   std::vector<Object> itsObjects;
00126   std::vector<std::vector<double> > itsCodeWords;
00127 
00128 
00129 };
00130 
00131 #endif
00132 
00133 // ######################################################################
00134 /* So things look consistent in everyone's emacs... */
00135 /* Local Variables: */
00136 /* indent-tabs-mode: nil */
00137 /* End: */
Generated on Sun May 8 08:05:30 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3