|
@@ -7,6 +7,8 @@
|
|
|
#ifndef _NICE_OBJREC_LF_SELECTION_INCLUDE
|
|
|
#define _NICE_OBJREC_LF_SELECTION_INCLUDE
|
|
|
|
|
|
+#include <core/basics/Exception.h>
|
|
|
+
|
|
|
#include "vislearning/features/localfeatures/LocalFeatureRepresentation.h"
|
|
|
#include "vislearning/features/localfeatures/LFMikolajczyk.h"
|
|
|
#include "vislearning/features/localfeatures/LFPatches.h"
|
|
@@ -47,45 +49,45 @@ class GenericLFSelection
|
|
|
LocalFeatureRepresentation *selectLocalFeatureRep ( const NICE::Config *conf, std::string section = "features", const UsageForTrainOrTest & useForTrainOrTest = GenericLFSelection::NOTSPECIFIED )
|
|
|
{
|
|
|
// return Value
|
|
|
- LocalFeatureRepresentation *lfrep = NULL;
|
|
|
+ OBJREC::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" )
|
|
|
+ if ( ( localfeature_type == "mikolajczyk" )|| ( localfeature_type == "LFMikolajczyk" ) )
|
|
|
{
|
|
|
- lfrep = new LFMikolajczyk ( conf );
|
|
|
+ lfrep = new OBJREC::LFMikolajczyk ( conf );
|
|
|
}
|
|
|
- else if ( localfeature_type == "VANDESANDE" ) //previously: "color"
|
|
|
+ else if ( ( localfeature_type == "VANDESANDE" ) || ( localfeature_type == "LFColorSande" ) )//previously: "color"
|
|
|
{
|
|
|
if ( useForTrainOrTest == TRAINING )
|
|
|
{
|
|
|
- lfrep = new LFColorSande ( conf, "LFColorSandeTrain" );
|
|
|
+ lfrep = new OBJREC::LFColorSande ( conf, "LFColorSandeTrain" );
|
|
|
}
|
|
|
else if ( useForTrainOrTest == TESTING )
|
|
|
{
|
|
|
- lfrep = new LFColorSande ( conf, "LFColorSandeTest" );
|
|
|
+ lfrep = new OBJREC::LFColorSande ( conf, "LFColorSandeTest" );
|
|
|
}
|
|
|
else //not specified whether for training or testing, so we do not care about
|
|
|
{
|
|
|
- lfrep = new LFColorSande ( conf );
|
|
|
+ lfrep = new OBJREC::LFColorSande ( conf );
|
|
|
}
|
|
|
}
|
|
|
- else if ( ( localfeature_type == "sift" ) || ( localfeature_type == "siftpp" ) )
|
|
|
+ else if ( ( localfeature_type == "sift" ) || ( localfeature_type == "siftpp" ) || ( localfeature_type == "LFSiftPP" ) )
|
|
|
{
|
|
|
- lfrep = new LFSiftPP ( conf );
|
|
|
+ lfrep = new OBJREC::LFSiftPP ( conf );
|
|
|
}
|
|
|
- else if ( ( localfeature_type == "generic_local" ) || ( localfeature_type == "generic" ) )
|
|
|
+ else if ( ( localfeature_type == "generic_local" ) || ( localfeature_type == "generic" ) || ( localfeature_type == "LFGenericLocal" ) )
|
|
|
{
|
|
|
- int numFeatures = conf->gI(section, "localfeature_count");
|
|
|
- lfrep = new LFGenericLocal ( conf, numFeatures );
|
|
|
+ int numFeatures = conf->gI(section, "localfeature_count");
|
|
|
+ lfrep = new OBJREC::LFGenericLocal ( conf, numFeatures );
|
|
|
}
|
|
|
- else if ( ( localfeature_type == "grey" ) || ( localfeature_type == "patches" ) )
|
|
|
+ else if ( ( localfeature_type == "grey" ) || ( localfeature_type == "patches" ) || ( localfeature_type == "LFPatches" ) )
|
|
|
{
|
|
|
int numFeatures = conf->gI(section, "localfeature_count");
|
|
|
- lfrep = new LFPatches ( conf, numFeatures );
|
|
|
+ lfrep = new OBJREC::LFPatches ( conf, numFeatures );
|
|
|
}
|
|
|
- else if( localfeature_type == "onHSG" )
|
|
|
+ else if ( ( localfeature_type == "onHSG" ) || ( localfeature_type == "LFonHSG" ) )
|
|
|
{
|
|
|
if ( useForTrainOrTest == TRAINING )
|
|
|
{
|
|
@@ -121,17 +123,17 @@ class GenericLFSelection
|
|
|
|
|
|
if ( useForTrainOrTest == TRAINING )
|
|
|
{
|
|
|
- writeFeats = new LFWriteCache ( conf, lfrep, "cacheTrain" );
|
|
|
+ writeFeats = new OBJREC::LFWriteCache ( conf, lfrep, "cacheTrain" );
|
|
|
lfrep = writeFeats;
|
|
|
}
|
|
|
else if ( useForTrainOrTest == TESTING )
|
|
|
{
|
|
|
- writeFeats = new LFWriteCache ( conf, lfrep, "cacheTest" );
|
|
|
+ writeFeats = new OBJREC::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 );
|
|
|
+ writeFeats = new OBJREC::LFWriteCache ( conf, lfrep );
|
|
|
lfrep = writeFeats;
|
|
|
}
|
|
|
|
|
@@ -145,37 +147,98 @@ class GenericLFSelection
|
|
|
{
|
|
|
if ( useForTrainOrTest == TRAINING )
|
|
|
{
|
|
|
- readFeats = new LFReadCache ( conf, writeFeats, numFeatures, "cacheTrain" );
|
|
|
+ readFeats = new OBJREC::LFReadCache ( conf, writeFeats, numFeatures, "cacheTrain" );
|
|
|
}
|
|
|
else if ( useForTrainOrTest == TESTING )
|
|
|
{
|
|
|
- readFeats = new LFReadCache ( conf, writeFeats, numFeatures, "cacheTest" );
|
|
|
+ readFeats = new OBJREC::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" );
|
|
|
+ readFeats = new OBJREC::LFReadCache ( conf, writeFeats, numFeatures, "cache" );
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if ( useForTrainOrTest == TRAINING )
|
|
|
{
|
|
|
- readFeats = new LFReadCache (conf, lfrep, numFeatures, "cacheTrain" );
|
|
|
+ readFeats = new OBJREC::LFReadCache (conf, lfrep, numFeatures, "cacheTrain" );
|
|
|
}
|
|
|
else if ( useForTrainOrTest == TESTING )
|
|
|
{
|
|
|
- readFeats = new LFReadCache (conf, lfrep, numFeatures, "cacheTest" );
|
|
|
+ readFeats = new OBJREC::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" );
|
|
|
+ readFeats = new OBJREC::LFReadCache (conf, lfrep, numFeatures, "cache" );
|
|
|
}
|
|
|
}
|
|
|
lfrep = readFeats;
|
|
|
}
|
|
|
|
|
|
return lfrep;
|
|
|
- }
|
|
|
+ };
|
|
|
+
|
|
|
+ static
|
|
|
+ void restoreLocalFeatureRep ( LocalFeatureRepresentation * _lfrep, std::istream & is, int format = 0 )
|
|
|
+ {
|
|
|
+
|
|
|
+ if ( is.good() )
|
|
|
+ {
|
|
|
+ if ( _lfrep != NULL )
|
|
|
+ delete _lfrep;
|
|
|
+
|
|
|
+
|
|
|
+ std::string className;
|
|
|
+ is >> className; //class name
|
|
|
+
|
|
|
+ if ( className == "<LFMikolajczyk>" )
|
|
|
+ {
|
|
|
+ _lfrep = new OBJREC::LFMikolajczyk();
|
|
|
+ }
|
|
|
+ else if ( className == "<LFColorSande>" )
|
|
|
+ {
|
|
|
+ _lfrep = new OBJREC::LFColorSande();
|
|
|
+ }
|
|
|
+ else if ( className == "<LFSiftPP>" )
|
|
|
+ {
|
|
|
+ _lfrep = new OBJREC::LFSiftPP();
|
|
|
+ }
|
|
|
+ else if ( className == "<LFGenericLocal>" )
|
|
|
+ {
|
|
|
+ _lfrep = new OBJREC::LFGenericLocal();
|
|
|
+ }
|
|
|
+ else if ( className == "<LFPatches>" )
|
|
|
+ {
|
|
|
+ _lfrep = new OBJREC::LFPatches();
|
|
|
+ }
|
|
|
+ else if ( className == "<LFonHSG>" )
|
|
|
+ {
|
|
|
+ _lfrep = new OBJREC::LFonHSG();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fthrow ( NICE::Exception, "GenericLFSelection::restoreLocalFeatureRep -- class name " << className << "unknown. Aborting." );
|
|
|
+ }
|
|
|
+
|
|
|
+ //undo reading of class name
|
|
|
+
|
|
|
+ for ( uint i = 0; i < className.size(); i++)
|
|
|
+ {
|
|
|
+ is.unget();
|
|
|
+ }
|
|
|
+
|
|
|
+ //now, call the restore method of the underlying object
|
|
|
+ //NOTE this could be also done externally, leaving only the actual instantiation of the derived objects here
|
|
|
+ _lfrep->restore ( is );
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fthrow ( NICE::Exception, "GenericLFSelection::restoreLocalFeatureRep -- InStream not initialized - restoring not possible!" );
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
};
|
|
|
|
|
|
}
|