|
@@ -1,56 +1,120 @@
|
|
|
|
|
|
* @file LFReadCache.cpp
|
|
|
* @brief read local features from file
|
|
|
-* @author Erik Rodner
|
|
|
+* @author Erik Rodner, Alexander Freytag
|
|
|
* @date 02/14/2008
|
|
|
-
|
|
|
*/
|
|
|
+
|
|
|
+
|
|
|
#include <iostream>
|
|
|
#include <fstream>
|
|
|
|
|
|
-#include "vislearning/baselib/Globals.h"
|
|
|
-#include "core/basics/StringTools.h"
|
|
|
-#include "core/basics/FileMgt.h"
|
|
|
+
|
|
|
+#include <core/basics/StringTools.h>
|
|
|
+#include <core/basics/FileMgt.h>
|
|
|
|
|
|
+
|
|
|
+#include <vislearning/baselib/Globals.h>
|
|
|
+
|
|
|
+#include "vislearning/features/localfeatures/GenericLFSelection.h"
|
|
|
#include "vislearning/features/localfeatures/LFReadCache.h"
|
|
|
|
|
|
using namespace OBJREC;
|
|
|
using namespace std;
|
|
|
using namespace NICE;
|
|
|
|
|
|
-LFReadCache::LFReadCache ( const Config *conf,
|
|
|
- const LocalFeatureRepresentation *_lfrep,
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void LFReadCache::setDescFormat ( const std::string & _descFormat_s )
|
|
|
+{
|
|
|
+ if ( _descFormat_s == "binary_double" )
|
|
|
+ this->descFormat = VVector::FILEFORMAT_BINARY_DOUBLE;
|
|
|
+ else if ( _descFormat_s == "binary_uchar" )
|
|
|
+ this->descFormat = VVector::FILEFORMAT_BINARY_CHAR;
|
|
|
+ else if ( _descFormat_s == "text_line" )
|
|
|
+ this->descFormat = VVector::FILEFORMAT_LINE;
|
|
|
+ else if ( ( _descFormat_s == "text_nice" ) || ( _descFormat_s == "text_ice" ) )
|
|
|
+ this->descFormat = VVector::FILEFORMAT_NICE;
|
|
|
+ else
|
|
|
+ fthrow ( Exception, "Format " << _descFormat_s << " is unknown." );
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+LFReadCache::LFReadCache ()
|
|
|
+{
|
|
|
+ this->numFeatures = -1;
|
|
|
+ this->cachedir = "";
|
|
|
+ this->cachemode = Globals::getCacheMode ( "cat" );
|
|
|
+ std::string descFormat_s = "binary_double";
|
|
|
+ this->setDescFormat ( descFormat_s );
|
|
|
+}
|
|
|
+
|
|
|
+LFReadCache::LFReadCache ( const Config *_conf,
|
|
|
+ const std::string & _confSection
|
|
|
+ )
|
|
|
+{
|
|
|
+ this->initFromConfig( _conf, _confSection );
|
|
|
+}
|
|
|
+
|
|
|
+LFReadCache::LFReadCache ( const Config *_conf,
|
|
|
+ LocalFeatureRepresentation *_lfrep,
|
|
|
int _numFeatures,
|
|
|
- const std::string & _section ) : lfrep ( _lfrep )
|
|
|
+ const std::string & _confSection ) : lfrep ( _lfrep )
|
|
|
{
|
|
|
|
|
|
- numFeatures = _numFeatures;
|
|
|
- cachedir = conf->gS ( _section, "root" );
|
|
|
- cachemode = Globals::getCacheMode ( conf->gS ( _section, "mode", "cat" ) );
|
|
|
-
|
|
|
- std::string descFormat_s = conf->gS ( _section, "descriptor_format", "binary_double" );
|
|
|
- if ( descFormat_s == "binary_double" )
|
|
|
- descFormat = VVector::FILEFORMAT_BINARY_DOUBLE;
|
|
|
- else if ( descFormat_s == "binary_uchar" )
|
|
|
- descFormat = VVector::FILEFORMAT_BINARY_CHAR;
|
|
|
- else if ( descFormat_s == "text_line" )
|
|
|
- descFormat = VVector::FILEFORMAT_LINE;
|
|
|
- else if ( ( descFormat_s == "text_nice" ) || ( descFormat_s == "text_ice" ) )
|
|
|
- descFormat = VVector::FILEFORMAT_NICE;
|
|
|
- else
|
|
|
- fthrow ( Exception, "Format " << descFormat_s << " is unknown." );
|
|
|
+ this->numFeatures = _numFeatures;
|
|
|
+ this->cachedir = _conf->gS ( _confSection, "root" );
|
|
|
+ this->cachemode = Globals::getCacheMode ( _conf->gS ( _confSection, "mode", "cat" ) );
|
|
|
+
|
|
|
+ std::string descFormat_s = _conf->gS ( _confSection, "descriptor_format", "binary_double" );
|
|
|
+ this->setDescFormat ( descFormat_s );
|
|
|
}
|
|
|
|
|
|
LFReadCache::~LFReadCache()
|
|
|
{
|
|
|
+ if ( this->lfrep != NULL )
|
|
|
+ {
|
|
|
+ delete this->lfrep;
|
|
|
+ this->lfrep = NULL;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void LFReadCache::initFromConfig(const NICE::Config* _conf, const std::string& _confSection)
|
|
|
+{
|
|
|
+
|
|
|
+ this->numFeatures = _conf->gI ( _confSection, "numFeatures", -1 );
|
|
|
+ this->cachedir = _conf->gS ( _confSection, "root" );
|
|
|
+ this->cachemode = Globals::getCacheMode ( _conf->gS ( _confSection, "mode", "cat" ) );
|
|
|
+
|
|
|
+ std::string descFormat_s = _conf->gS ( _confSection, "descriptor_format", "binary_double" );
|
|
|
+ this->setDescFormat ( descFormat_s );
|
|
|
+
|
|
|
+ if ( this->lfrep != NULL )
|
|
|
+ {
|
|
|
+ delete this->lfrep;
|
|
|
+ this->lfrep = NULL;
|
|
|
+ }
|
|
|
+ this->lfrep = GenericLFSelection::selectLocalFeatureRep ( _conf, _confSection );
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
int LFReadCache::getDescSize () const
|
|
|
{
|
|
|
- if ( lfrep == NULL ) {
|
|
|
+ if ( this->lfrep == NULL )
|
|
|
+ {
|
|
|
fthrow ( Exception, "Unable to get descriptor size! (cache mode)" );
|
|
|
return -1;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return lfrep->getDescSize();
|
|
|
}
|
|
|
}
|
|
@@ -83,3 +147,130 @@ void LFReadCache::visualizeFeatures ( NICE::Image & mark,
|
|
|
lfrep->visualizeFeatures ( mark, positions, color );
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void LFReadCache::restore ( std::istream & is, int format )
|
|
|
+{
|
|
|
+
|
|
|
+ this->clear();
|
|
|
+
|
|
|
+
|
|
|
+ if ( is.good() )
|
|
|
+ {
|
|
|
+
|
|
|
+ std::string tmp;
|
|
|
+ is >> tmp;
|
|
|
+
|
|
|
+ if ( ! this->isStartTag( tmp, "LFReadCache" ) )
|
|
|
+ {
|
|
|
+ std::cerr << " WARNING - attempt to restore LFReadCache, but start flag " << tmp << " does not match! Aborting... " << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool b_endOfBlock ( false ) ;
|
|
|
+
|
|
|
+ while ( !b_endOfBlock )
|
|
|
+ {
|
|
|
+ is >> tmp;
|
|
|
+
|
|
|
+ if ( this->isEndTag( tmp, "LFReadCache" ) )
|
|
|
+ {
|
|
|
+ b_endOfBlock = true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ tmp = this->removeStartTag ( tmp );
|
|
|
+
|
|
|
+
|
|
|
+ if ( tmp.compare("numFeatures") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->numFeatures;
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("lfrep") == 0 )
|
|
|
+ {
|
|
|
+
|
|
|
+ this->lfrep->restore ( is );
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("cachedir") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->cachedir;
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("descFormat") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->descFormat;
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("cachemode") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->cachemode;
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "WARNING -- unexpected LFReadCache object -- " << tmp << " -- for restoration... aborting" << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "LFReadCache::restore -- InStream not initialized - restoring not possible!" << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void LFReadCache::store ( std::ostream & os, int format ) const
|
|
|
+{
|
|
|
+ if (os.good())
|
|
|
+ {
|
|
|
+
|
|
|
+ os << this->createStartTag( "LFReadCache" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "numFeatures" ) << std::endl;
|
|
|
+ os << this->numFeatures << std::endl;
|
|
|
+ os << this->createEndTag( "numFeatures" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "lfrep" ) << std::endl;
|
|
|
+ this->lfrep->store ( os );
|
|
|
+ os << this->createEndTag( "lfrep" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "cachedir" ) << std::endl;
|
|
|
+ os << this->cachedir << std::endl;
|
|
|
+ os << this->createEndTag( "cachedir" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "descFormat" ) << std::endl;
|
|
|
+ os << this->descFormat << std::endl;
|
|
|
+ os << this->createEndTag( "descFormat" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "cachemode" ) << std::endl;
|
|
|
+ os << this->cachemode << std::endl;
|
|
|
+ os << this->createEndTag( "cachemode" ) << std::endl;
|
|
|
+
|
|
|
+
|
|
|
+ os << this->createEndTag( "LFReadCache" ) << std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void LFReadCache::clear ()
|
|
|
+{
|
|
|
+ if ( this->lfrep != NULL )
|
|
|
+ {
|
|
|
+ delete this->lfrep;
|
|
|
+ this->lfrep = NULL;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|