|
@@ -1,70 +1,101 @@
|
|
|
/**
|
|
|
* @file LFSiftPP.cpp
|
|
|
* @brief Sift++ interface
|
|
|
-* @author Erik Rodner
|
|
|
+* @author Erik Rodner, Alexander Freytag
|
|
|
* @date 11/19/2007
|
|
|
-
|
|
|
*/
|
|
|
+
|
|
|
+// STL includes
|
|
|
#include <iostream>
|
|
|
#include <sstream>
|
|
|
|
|
|
+// nice-core includes
|
|
|
+#include <core/basics/Exception.h>
|
|
|
+
|
|
|
// #ifdef NICE_USELIB_ICE
|
|
|
// #include <image_nonvis.h>
|
|
|
// #endif
|
|
|
+
|
|
|
+// nice-vislearning includes
|
|
|
#include "vislearning/features/localfeatures/LFSiftPP.h"
|
|
|
|
|
|
-#include "core/basics/Exception.h"
|
|
|
+//TODO move this to separate input or source folder
|
|
|
+#include "vislearning/features/localfeatures/sift.h"
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
-
|
|
|
using namespace NICE;
|
|
|
+using namespace OBJREC;
|
|
|
|
|
|
+///////////////////// ///////////////////// /////////////////////
|
|
|
+// CONSTRUCTORS / DESTRUCTORS
|
|
|
+///////////////////// ///////////////////// /////////////////
|
|
|
|
|
|
+LFSiftPP::LFSiftPP() : LocalFeatureRepresentation ()
|
|
|
+{
|
|
|
+ this->threshold = 0.0;
|
|
|
+ this->edgeThreshold = 10.0;
|
|
|
+ this->octaves = 6;
|
|
|
+ this->first_octave = -1;
|
|
|
+ this->levels = 3;
|
|
|
+
|
|
|
+ this->minScale = 1;
|
|
|
+ this->maxScale = 4;
|
|
|
+ this->numScales = 10;
|
|
|
+ this->numAngles = 6;
|
|
|
+
|
|
|
+ this->descriptorAlignment = DALGIN_DETECTOR;
|
|
|
+ this->normalizeFeature = false;
|
|
|
+}
|
|
|
|
|
|
-#include "vislearning/features/localfeatures/sift.h"
|
|
|
-
|
|
|
-using namespace OBJREC;
|
|
|
+LFSiftPP::LFSiftPP( const Config * _conf )
|
|
|
+{
|
|
|
+ this->initFromConfig( _conf );
|
|
|
+}
|
|
|
|
|
|
+LFSiftPP::~LFSiftPP()
|
|
|
+{
|
|
|
+}
|
|
|
|
|
|
-LFSiftPP::LFSiftPP( const Config *conf )
|
|
|
+void LFSiftPP::initFromConfig(const NICE::Config * _conf, const std::string & _confSection)
|
|
|
{
|
|
|
- threshold = conf->gD("LFSiftPP", "threshold", 0.0);
|
|
|
- edgeThreshold = conf->gD("LFSiftPP", "edge_threshold", 10.0);
|
|
|
- octaves = conf->gI("LFSiftPP", "octaves", 6);
|
|
|
- first_octave = conf->gI("LFSiftPP", "first_octave", -1);
|
|
|
- levels = conf->gI("LFSiftPP", "levels", 3);
|
|
|
+ this->threshold = _conf->gD(_confSection, "threshold", 0.0);
|
|
|
+ this->edgeThreshold = _conf->gD(_confSection, "edge_threshold", 10.0);
|
|
|
+ this->octaves = _conf->gI(_confSection, "octaves", 6);
|
|
|
+ this->first_octave = _conf->gI(_confSection, "first_octave", -1);
|
|
|
+ this->levels = _conf->gI(_confSection, "levels", 3);
|
|
|
|
|
|
- minScale = conf->gD("LFSiftPP", "min_scale", 1);
|
|
|
- maxScale = conf->gD("LFSiftPP", "max_scale", 4);
|
|
|
- numScales = conf->gI("LFSiftPP", "num_scales", 10);
|
|
|
- numAngles = conf->gI("LFSiftPP", "num_angles", 6 );
|
|
|
+ this->minScale = _conf->gD(_confSection, "min_scale", 1);
|
|
|
+ this->maxScale = _conf->gD(_confSection, "max_scale", 4);
|
|
|
+ this->numScales = _conf->gI(_confSection, "num_scales", 10);
|
|
|
+ this->numAngles = _conf->gI(_confSection, "num_angles", 6 );
|
|
|
|
|
|
- std::string descriptorAlignment_s = conf->gS("LFSiftPP", "descriptor_alignment", "detector" );
|
|
|
+ std::string descriptorAlignment_s = _conf->gS(_confSection, "descriptor_alignment", "detector" );
|
|
|
|
|
|
if ( descriptorAlignment_s == "detector" )
|
|
|
- descriptorAlignment = DALGIN_DETECTOR;
|
|
|
+ this->descriptorAlignment = DALGIN_DETECTOR;
|
|
|
else if ( descriptorAlignment_s == "multiple" )
|
|
|
- descriptorAlignment = DALIGN_MULTIPLE;
|
|
|
+ this->descriptorAlignment = DALIGN_MULTIPLE;
|
|
|
else {
|
|
|
- fprintf (stderr, "LFSiftPP: descriptor alignment method unknown !\n");
|
|
|
- exit(-1);
|
|
|
+ fprintf (stderr, "LFSiftPP: descriptor alignment method unknown !\n");
|
|
|
+ exit(-1);
|
|
|
}
|
|
|
|
|
|
- normalizeFeature = conf->gB("LFSiftPP", "normalize_feature", false );
|
|
|
+ this->normalizeFeature = _conf->gB(_confSection, "normalize_feature", false );
|
|
|
|
|
|
+ //TODO check whether this os is still needed here.
|
|
|
std::ostringstream os;
|
|
|
os << "siftpp_" << "l" << levels << "_o"
|
|
|
<< octaves << "_m" << minScale << "_t"
|
|
|
<< threshold << "_e" << edgeThreshold;
|
|
|
|
|
|
if ( ! normalizeFeature )
|
|
|
- os << "_nd";
|
|
|
+ os << "_nd";
|
|
|
}
|
|
|
|
|
|
-LFSiftPP::~LFSiftPP()
|
|
|
-{
|
|
|
-}
|
|
|
+///////////////////// ///////////////////// /////////////////////
|
|
|
+// FEATURE STUFF
|
|
|
+///////////////////// ///////////////////// /////////////////
|
|
|
|
|
|
int LFSiftPP::getDescSize () const
|
|
|
{
|
|
@@ -245,3 +276,187 @@ void LFSiftPP::visualizeFeatures ( NICE::Image & mark,
|
|
|
}
|
|
|
|
|
|
|
|
|
+///////////////////// INTERFACE PERSISTENT /////////////////////
|
|
|
+// interface specific methods for store and restore
|
|
|
+///////////////////// INTERFACE PERSISTENT /////////////////////
|
|
|
+
|
|
|
+void LFSiftPP::restore ( std::istream & is, int format )
|
|
|
+{
|
|
|
+ //delete everything we knew so far...
|
|
|
+ this->clear();
|
|
|
+
|
|
|
+
|
|
|
+ if ( is.good() )
|
|
|
+ {
|
|
|
+
|
|
|
+ std::string tmp;
|
|
|
+ is >> tmp; //class name
|
|
|
+
|
|
|
+ if ( ! this->isStartTag( tmp, "LFSiftPP" ) )
|
|
|
+ {
|
|
|
+ std::cerr << " WARNING - attempt to restore LFSiftPP, but start flag " << tmp << " does not match! Aborting... " << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool b_endOfBlock ( false ) ;
|
|
|
+
|
|
|
+ while ( !b_endOfBlock )
|
|
|
+ {
|
|
|
+ is >> tmp; // start of block
|
|
|
+
|
|
|
+ if ( this->isEndTag( tmp, "LFSiftPP" ) )
|
|
|
+ {
|
|
|
+ b_endOfBlock = true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ tmp = this->removeStartTag ( tmp );
|
|
|
+
|
|
|
+
|
|
|
+ if ( tmp.compare("threshold") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->threshold;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("edgeThreshold") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->edgeThreshold;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("octaves") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->octaves;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("first_octave") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->first_octave;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("levels") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->levels;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("minScale") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->minScale;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("maxScale") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->maxScale;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("numScales") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->numScales;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("numAngles") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->numAngles;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("descriptorAlignment") == 0 )
|
|
|
+ {
|
|
|
+ unsigned int ui_descriptorAlignment;
|
|
|
+ is >> ui_descriptorAlignment;
|
|
|
+ this->descriptorAlignment = static_cast<DESCRIPTORALIGNMENT> ( ui_descriptorAlignment ) ;
|
|
|
+
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("normalizeFeature") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->normalizeFeature;
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "WARNING -- unexpected LFSiftPP object -- " << tmp << " -- for restoration... aborting" << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "LFSiftPP::restore -- InStream not initialized - restoring not possible!" << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void LFSiftPP::store ( std::ostream & os, int format ) const
|
|
|
+{
|
|
|
+ if (os.good())
|
|
|
+ {
|
|
|
+ // show starting point
|
|
|
+ os << this->createStartTag( "LFSiftPP" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "threshold" ) << std::endl;
|
|
|
+ os << this->threshold << std::endl;
|
|
|
+ os << this->createEndTag( "threshold" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "edgeThreshold" ) << std::endl;
|
|
|
+ os << this->edgeThreshold << std::endl;
|
|
|
+ os << this->createEndTag( "edgeThreshold" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "octaves" ) << std::endl;
|
|
|
+ os << this->octaves << std::endl;
|
|
|
+ os << this->createEndTag( "octaves" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "first_octave" ) << std::endl;
|
|
|
+ os << this->first_octave << std::endl;
|
|
|
+ os << this->createEndTag( "first_octave" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "levels" ) << std::endl;
|
|
|
+ os << this->levels << std::endl;
|
|
|
+ os << this->createEndTag( "levels" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "minScale" ) << std::endl;
|
|
|
+ os << this->minScale << std::endl;
|
|
|
+ os << this->createEndTag( "minScale" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "maxScale" ) << std::endl;
|
|
|
+ os << this->maxScale << std::endl;
|
|
|
+ os << this->createEndTag( "maxScale" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "numScales" ) << std::endl;
|
|
|
+ os << this->numScales << std::endl;
|
|
|
+ os << this->createEndTag( "numScales" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "numAngles" ) << std::endl;
|
|
|
+ os << this->numAngles << std::endl;
|
|
|
+ os << this->createEndTag( "numAngles" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "descriptorAlignment" ) << std::endl;
|
|
|
+ os << this->descriptorAlignment << std::endl;
|
|
|
+ os << this->createEndTag( "descriptorAlignment" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "normalizeFeature" ) << std::endl;
|
|
|
+ os << this->normalizeFeature << std::endl;
|
|
|
+ os << this->createEndTag( "normalizeFeature" ) << std::endl;
|
|
|
+
|
|
|
+
|
|
|
+ // done
|
|
|
+ os << this->createEndTag( "LFSiftPP" ) << std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void LFSiftPP::clear ()
|
|
|
+{
|
|
|
+}
|