Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
descriptor.hpp
00001 /* $Id$ */
00002 
00003 #ifndef SAMS_DESCRIPTOR_HPP
00004 #define SAMS_DESCRIPTOR_HPP
00005 
00006 #include <string>
00007 #include "kernel/keyValueFile.hpp"
00008 #include "image/Image.hpp"
00009 
00010 #include <fstream>
00011 #include "boost/archive/xml_iarchive.hpp"
00012 #include "jmath/jblas.hpp"
00013 #include "jmath/pca.hpp"
00014 #include "sams/feature.hpp"
00015 
00016 namespace jafar {
00017   namespace sams {
00018 
00021     class DescriptorFactory {
00022     public:
00023       virtual ~DescriptorFactory() {};
00024       virtual bool generate(const jafar::image::Image& img_,
00025         std::vector<jafar::sams::Feature *>& fVec_) const {};
00026     }; // class DescriptorFactory
00027 
00031     class SIFTFactory : public DescriptorFactory {
00032     public:
00035       class Params : public jafar::kernel::KeyValueFileLoad {
00036       public:
00037         double magnif;
00038         double sigma0;
00039         int dim;
00040         int odim;
00041         double fvGradHicap;
00042 
00043         Params(double magnif_=3.0, double sigma0_=1.5, int dim_=4, int odim_=8, double fvGradHicap_=0.2) :
00044         magnif(magnif_), sigma0(sigma0_), dim(dim_), odim(odim_), fvGradHicap(fvGradHicap_) {};
00045 
00046       protected:
00047         void loadKeyValueFile(jafar::kernel::KeyValueFile const & keyValueFile) {
00048           JFR_TRACE_BEGIN;
00049           keyValueFile.getItem("magnif",magnif);
00050           keyValueFile.getItem("sigma0",sigma0);
00051           keyValueFile.getItem("dim",dim);
00052           keyValueFile.getItem("odim",odim);
00053           keyValueFile.getItem("fvGradHicap",fvGradHicap);
00054           JFR_TRACE_END("SIFTFactory::Params::loadKeyValueFile");
00055         };
00056       }; // class Params
00057 
00058       SIFTFactory() : params() {};
00059       SIFTFactory(Params params_) : params(params_) {};
00060       SIFTFactory(std::string const & fileName_) {
00061         params.load(fileName_);
00062       };
00063       virtual ~SIFTFactory() {};
00064       virtual bool generate(const jafar::image::Image& img_,
00065       std::vector<jafar::sams::Feature *>& fVec_) const {
00066         jblas::mat mag;
00067         jblas::mat dir;
00068         preproc(img_,mag,dir);
00069         computeOrientations(fVec_,mag,dir);
00070         computeDescriptors(fVec_,mag,dir);
00071         return true;
00072       };
00073 
00074     private:
00075       Params params;
00076       void preproc(const jafar::image::Image& img_,
00077         jblas::mat& mag_,
00078         jblas::mat& dir_) const;
00079       void computeOrientations(std::vector<jafar::sams::Feature *>& fVec_,
00080         const jblas::mat& mag_,
00081         const jblas::mat& dir_) const;
00082       void computeDescriptors(std::vector<jafar::sams::Feature *>& fVec_,
00083         const jblas::mat& mag_,
00084         const jblas::mat& dir_) const;
00085 
00086 
00087     }; // class SIFTFactory
00088 
00092     class GIFTFactory : public DescriptorFactory {
00093     public:
00094       class Params : public jafar::kernel::KeyValueFileLoad{
00095       public:
00096         int supportWidth;
00097         int dim;
00098         int odim;
00099         double fvGradHicap;
00100 
00101         Params(int sw_=45,int dim_=4, int odim_=8, double fvGradHicap_=0.2) :
00102           supportWidth(sw_), dim(dim_), odim(odim_), fvGradHicap(fvGradHicap_) {};
00103         
00104       protected:
00105         void loadKeyValueFile(jafar::kernel::KeyValueFile const & keyValueFile) {
00106           JFR_TRACE_BEGIN;
00107           keyValueFile.getItem("supportWidth", supportWidth);
00108           keyValueFile.getItem("dim", dim);
00109           keyValueFile.getItem("odim", odim);
00110           keyValueFile.getItem("fvGradHicap", fvGradHicap);
00111           JFR_TRACE_END("GIFTFactory::Params::loadKeyValueFile");
00112         };
00113       }; //class Params
00114 
00115       GIFTFactory() : params() {};
00116       GIFTFactory(Params params_) : params(params_) {};
00117       GIFTFactory(std::string const & fileName_) {
00118         params.load(fileName_);
00119       };
00120       virtual ~GIFTFactory() {};
00121       virtual bool generate(const jafar::image::Image& img_,
00122           std::vector<jafar::sams::Feature *>& fVec_) const;
00123     
00124     private:
00125       Params params;
00126     };
00127 
00130     class GreyDescFactory : public DescriptorFactory {
00131     public:
00132 
00135       class Params {
00136       public:
00137         int dim;
00138         bool usePCA;
00139         jafar::jmath::PCA pca;
00140 
00141         Params(int dim_=121, bool usePCA_=false, std::string const & fileName_="") : 
00142         dim(dim_), usePCA(usePCA_) {
00143     // if (usePCA) {
00144     //      JFR_PRECOND( fileName_ != "", "GreyDescFactory::Params: you must specify a filename for the PCA data");
00145     //      std::ifstream ifs(fileName_.c_str());
00146     //      boost::archive::xml_iarchive iar(ifs);
00147     //      iar >> BOOST_SERIALIZATION_NVP(pca);
00148     //    }
00149         };
00150 
00151       }; // class Params
00152 
00153       GreyDescFactory() : params() {};
00154       GreyDescFactory(Params params_) : params(params_) {};
00155       GreyDescFactory(std::string const & fileName_) : params(121,true,fileName_) {
00156       };
00157       virtual ~GreyDescFactory() {};
00158       virtual bool generate(const jafar::image::Image& img_,
00159         std::vector<jafar::sams::Feature *>& fVec_) const;
00160 
00161     private:
00162       Params params;
00163     }; // class GreyFactory
00164   }
00165 } // namespace jafar
00166 
00167 #endif // SAMS_DESCRIPTOR_HPP
00168 
00169 
00170 // AUTORIGHTS
00171 // Copyright (c) 2006 The Regents of the University of California
00172 // All Rights Reserved.
00173 // 
00174 // Created by Andrea Vedaldi (UCLA VisionLab)
00175 // 
00176 // Permission to use, copy, modify, and distribute this software and its
00177 // documentation for educational, research and non-profit purposes,
00178 // without fee, and without a written agreement is hereby granted,
00179 // provided that the above copyright notice, this paragraph and the
00180 // following three paragraphs appear in all copies.
00181 // 
00182 // This software program and documentation are copyrighted by The Regents
00183 // of the University of California. The software program and
00184 // documentation are supplied "as is", without any accompanying services
00185 // from The Regents. The Regents does not warrant that the operation of
00186 // the program will be uninterrupted or error-free. The end-user
00187 // understands that the program was developed for research purposes and
00188 // is advised not to rely exclusively on the program for any reason.
00189 // 
00190 // This software embodies a method for which the following patent has
00191 // been issued: "Method and apparatus for identifying scale invariant
00192 // features in an image and use of same for locating an object in an
00193 // image," David G. Lowe, US Patent 6,711,293 (March 23,
00194 // 2004). Provisional application filed March 8, 1999. Asignee: The
00195 // University of British Columbia.
00196 // 
00197 // IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
00198 // FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
00199 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND
00200 // ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN
00201 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF
00202 // CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
00203 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00204 // A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
00205 // BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE
00206 // MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:27 for Jafar by doxygen 1.7.6.1
LAAS-CNRS