|
@@ -1,5 +1,5 @@
|
|
|
/**
|
|
|
-* @file GenericLocalFeatureSelection.h
|
|
|
+* @file GenericLFSelection.h
|
|
|
* @brief This class provides a generic chooser function for different descriptors, which are derived from LocalFeatureRepresentation.
|
|
|
* @date 26.10.2011
|
|
|
*/
|
|
@@ -19,80 +19,143 @@
|
|
|
#include "vislearning/features/localfeatures/LFColorSande.h"
|
|
|
#include "vislearning/features/localfeatures/LFonHSG.h"
|
|
|
|
|
|
-/** NOTE: This class only returns Descriptors, which NOT need any given positions. All Descriptors calculate there own positions, on DIFFERENT ways. **/
|
|
|
-
|
|
|
|
|
|
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] Config* - A pointer to the given configfile, which must contain "section" - "localfeature_type"
|
|
|
- * @param[in] string - This string defines the value for "section" in the configfile.
|
|
|
+ * @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" )
|
|
|
+ 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 == "color" )
|
|
|
- {
|
|
|
- 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" ) )
|
|
|
- {
|
|
|
- lfrep = new LFonHSG( conf);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- lfrep = NULL;
|
|
|
- }
|
|
|
+ // 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;
|
|
|
+// }
|
|
|
|
|
|
- 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;
|
|
|
- }
|
|
|
+ // read features?
|
|
|
+ bool readfeat;
|
|
|
+ readfeat = conf->gB ( section, "localfeature_cache_read", true );
|
|
|
+ // write features?
|
|
|
+ bool writefeat;
|
|
|
+ writefeat = conf->gB ( section, "localfeature_cache_write", true );
|
|
|
|
|
|
- // no correct localfeature_type was given
|
|
|
- if ( lfrep == NULL )
|
|
|
- fthrow(NICE::Exception, "Local feature type not found: " << localfeature_type );
|
|
|
+ LocalFeatureRepresentation *writeFeats = NULL;
|
|
|
+ LocalFeatureRepresentation *readFeats = NULL;
|
|
|
+ if ( writefeat )
|
|
|
+ {
|
|
|
+ // write the features to a file, if there isn't any to read
|
|
|
+ writeFeats = new LFWriteCache ( conf, lfrep );
|
|
|
+ lfrep = writeFeats;
|
|
|
+ }
|
|
|
|
|
|
- if ( conf->gB(section, "localfeature_cache_save", false) )
|
|
|
- {
|
|
|
- LocalFeatureRepresentation *lfrep_save = new LFWriteCache ( conf, lfrep );
|
|
|
- lfrep = lfrep_save;
|
|
|
- }
|
|
|
-
|
|
|
- return lfrep;
|
|
|
- }
|
|
|
+ if ( readfeat )
|
|
|
+ {
|
|
|
+ int numFeatures = conf->gI(section, "localfeature_count", -1);
|
|
|
+ // read the features from a file
|
|
|
+ if ( writefeat )
|
|
|
+ {
|
|
|
+ readFeats = new LFReadCache ( conf, writeFeats, numFeatures );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ readFeats = new LFReadCache (conf, lfrep, numFeatures );
|
|
|
+ }
|
|
|
+ lfrep = readFeats;
|
|
|
+ }
|
|
|
+
|
|
|
+ return lfrep;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
}
|