00001
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 };
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 };
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 };
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 };
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
00144
00145
00146
00147
00148
00149 };
00150
00151 };
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 };
00164 }
00165 }
00166
00167 #endif // SAMS_DESCRIPTOR_HPP
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206