123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- /**
- * @file GenericLFSelection.h
- * @brief This class provides a generic chooser function for different descriptors, which are derived from LocalFeatureRepresentation.
- * @date 26.10.2011
- */
- #ifndef _NICE_OBJREC_LF_SELECTION_INCLUDE
- #define _NICE_OBJREC_LF_SELECTION_INCLUDE
- #include "vislearning/features/localfeatures/LocalFeatureRepresentation.h"
- #include "vislearning/features/localfeatures/LFMikolajczyk.h"
- #include "vislearning/features/localfeatures/LFPatches.h"
- #include "vislearning/features/localfeatures/LFGenericLocal.h"
- #include "vislearning/features/localfeatures/LFSiftPP.h"
- // #include "vislearning/features/localfeatures/LFSegmentation.h" //located in objrec, please move this to ensure its functionality
- #include "vislearning/features/localfeatures/LFWriteCache.h"
- #include "vislearning/features/localfeatures/LFReadCache.h"
- // #include "vislearning/features/localfeatures/LFSegContour.h" //located in objrec, please move this to ensure its functionality
- #include "vislearning/features/localfeatures/LFColorSande.h"
- #include "vislearning/features/localfeatures/LFonHSG.h"
- namespace OBJREC {
- /** @class GenericLFSelection
- * @brief Select a specific LF-Type (local feature representation). LFs compute Descriptors, which DO NOT need given positions, but calculate them ON THEIR OWN!
- * All Descriptor-Methods calculate there own positions previously, and on DIFFERENT ways.
- */
- class GenericLFSelection
- {
- public:
-
- //! enum specifying for which step the feature extractor shall be used (this influences the config section which will be used)
- enum UsageForTrainOrTest { NOTSPECIFIED = 0,
- TRAINING,
- TESTING
- };
- /** LocalFeature Selector
- * @brief This methode switches between the different LocalFeature-Types. One has to set the "localfeature_type" on a valid value and the methode returns a LocalFeatureRepresentation derived Object.
- * @param[in] conf - A pointer to the given configfile, which must contain "section" - "localfeature_type"
- * @param[in] section - This string defines the value for "section" in the configfile.
- * @param[in] useForTrainOrTest - Specify whether we use the LFRep for Training, Testing, or for both - this influences the choice of the config section that is handed over to the LFRep-method
- * @return LocalFeatureRepresentation* - The LocalFeatureRepresentation which contains the selected LocalFeature-Type.
- */
- static
- LocalFeatureRepresentation *selectLocalFeatureRep ( const NICE::Config *conf, std::string section = "features", const UsageForTrainOrTest & useForTrainOrTest = NOTSPECIFIED )
- {
- // return Value
- LocalFeatureRepresentation *lfrep = NULL;
-
- // string which defines the localfeature_type (for Ex. Sande, ...)
- std::string localfeature_type = conf->gS(section, "localfeature_type", "");
-
- if ( localfeature_type == "mikolajczyk" )
- {
- lfrep = new LFMikolajczyk ( conf );
- }
- else if ( localfeature_type == "VANDESANDE" ) //previously: "color"
- {
- if ( useForTrainOrTest == TRAINING )
- {
- lfrep = new LFColorSande ( conf, "LFColorSandeTrain" );
- }
- else if ( useForTrainOrTest == TESTING )
- {
- lfrep = new LFColorSande ( conf, "LFColorSandeTest" );
- }
- else //not specified whether for training or testing, so we do not care about
- {
- lfrep = new LFColorSande ( conf );
- }
- }
- else if ( ( localfeature_type == "sift" ) || ( localfeature_type == "siftpp" ) )
- {
- lfrep = new LFSiftPP ( conf );
- }
- else if ( ( localfeature_type == "generic_local" ) || ( localfeature_type == "generic" ) )
- {
- int numFeatures = conf->gI(section, "localfeature_count");
- lfrep = new LFGenericLocal ( conf, numFeatures );
- }
- else if ( ( localfeature_type == "grey" ) || ( localfeature_type == "patches" ) )
- {
- int numFeatures = conf->gI(section, "localfeature_count");
- lfrep = new LFPatches ( conf, numFeatures );
- }
- else if( ( localfeature_type == "onHSG" ) )
- {
- if ( useForTrainOrTest == TRAINING )
- {
- lfrep = new OBJREC::LFonHSG ( conf, "HSGTrain" );
- }
- else if ( useForTrainOrTest == TESTING )
- {
- lfrep = new OBJREC::LFonHSG ( conf, "HSGTest" );
- }
- else //not specified whether for training or testing, so we do not care about
- {
- lfrep = new OBJREC::LFonHSG( conf);
- }
-
- }
- else
- {
- lfrep = NULL;
- }
- // if ( conf->gB(section, "localfeature_cache_read", false) )
- // {
- // int numFeatures = conf->gI(section, "localfeature_count", -1);
- // LocalFeatureRepresentation *lfrep_read = new LFReadCache ( conf, lfrep, numFeatures );
- // lfrep = lfrep_read;
- // }
- //
- // // no correct localfeature_type was given
- // if ( lfrep == NULL )
- // fthrow(NICE::Exception, "Local feature type not found: " << localfeature_type );
- //
- // if ( conf->gB(section, "localfeature_cache_write", false) )
- // {
- // LocalFeatureRepresentation *lfrep_write = new LFWriteCache ( conf, lfrep );
- // lfrep = lfrep_write;
- // }
- // read features?
- bool readfeat;
- readfeat = conf->gB ( section, "localfeature_cache_read", true );
- // write features?
- bool writefeat;
- writefeat = conf->gB ( section, "localfeature_cache_write", true );
- LocalFeatureRepresentation *writeFeats = NULL;
- LocalFeatureRepresentation *readFeats = NULL;
- if ( writefeat )
- {
- // write the features to a file, if there isn't any to read
-
- if ( useForTrainOrTest == TRAINING )
- {
- writeFeats = new LFWriteCache ( conf, lfrep, "cacheTrain" );
- lfrep = writeFeats;
- }
- else if ( useForTrainOrTest == TESTING )
- {
- writeFeats = new LFWriteCache ( conf, lfrep, "cacheTest" );
- lfrep = writeFeats;
- }
- else //not specified whether for training or testing, so we do not care about
- {
- writeFeats = new LFWriteCache ( conf, lfrep );
- lfrep = writeFeats;
- }
- }
- if ( readfeat )
- {
- int numFeatures = conf->gI(section, "localfeature_count", -1);
- // read the features from a file
- if ( writefeat )
- {
- if ( useForTrainOrTest == TRAINING )
- {
- readFeats = new LFReadCache ( conf, writeFeats, numFeatures, "cacheTrain" );
- }
- else if ( useForTrainOrTest == TESTING )
- {
- readFeats = new LFReadCache ( conf, writeFeats, numFeatures, "cacheTest" );
- }
- else //not specified whether for training or testing, so we do not care about
- {
- readFeats = new LFReadCache ( conf, writeFeats, numFeatures, "cache" );
- }
- }
- else
- {
- if ( useForTrainOrTest == TRAINING )
- {
- readFeats = new LFReadCache (conf, lfrep, numFeatures, "cacheTrain" );
- }
- else if ( useForTrainOrTest == TESTING )
- {
- readFeats = new LFReadCache (conf, lfrep, numFeatures, "cacheTest" );
- }
- else //not specified whether for training or testing, so we do not care about
- {
- readFeats = new LFReadCache (conf, lfrep, numFeatures, "cache" );
- }
- }
- lfrep = readFeats;
- }
-
- return lfrep;
- }
- };
- }
- #endif
|