123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /**
- * @file LFWriteCache.cpp
- * @brief read local features from file
- * @author Erik Rodner
- * @date 02/14/2008
- */
- #include "core/vector/VectorT.h"
- #include "core/vector/MatrixT.h"
- #include "core/image/ImageT.h"
- #include <iostream>
- #include <fstream>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include "vislearning/baselib/Globals.h"
- #include "core/basics/StringTools.h"
- #include "vislearning/features/localfeatures/LFWriteCache.h"
- using namespace OBJREC;
- using namespace std;
- using namespace NICE;
- LFWriteCache::LFWriteCache ( const Config *conf,
- const LocalFeatureRepresentation *_lfrep ) : lfrep ( _lfrep )
- {
- cachedir = conf->gS ( "cache", "root" );
- cachemode = Globals::getCacheMode ( conf->gS ( "cache", "mode", "cat" ) );
- std::string descFormat_s = conf->gS ( "cache", "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_ice" )
- descFormat = VVector::FILEFORMAT_NICE;
- }
- LFWriteCache::~LFWriteCache()
- {
- }
- int LFWriteCache::getDescSize () const
- {
- return lfrep->getDescSize();
- }
- int LFWriteCache::extractFeatures ( const NICE::Image & img,
- VVector & features,
- VVector & positions ) const
- {
- std::string filename = Globals::getCacheFilename ( cachedir, cachemode );
- int ret = lfrep->extractFeatures ( img, features, positions );
- std::string filename_desc = filename + ".desc";
- std::string filename_pos = filename + ".key";
- struct stat dummy;
- if ( stat ( filename_desc.c_str(), &dummy ) < 0 )
- {
- fprintf ( stderr, "features: %d, positions: %d\n", ( int ) features.size(),
- ( int ) positions.size() );
- if ( features.size() > 0 )
- fprintf ( stderr, "feature dimension: %d %d\n", features[0].size(), lfrep->getDescSize() );
- features.save ( filename_desc, descFormat );
- positions.save ( filename_pos, VVector::FILEFORMAT_LINE );
- } else {
- fprintf ( stderr, "description file %s exists !\n", filename_desc.c_str() );
- }
- return ret;
- }
- int LFWriteCache::extractFeatures ( const NICE::ColorImage & img,
- VVector & features,
- VVector & positions ) const
- {
- std::string filename = Globals::getCacheFilename ( cachedir, cachemode );
- int ret = lfrep->extractFeatures ( img, features, positions );
- std::string filename_desc = filename + ".desc";
- std::string filename_pos = filename + ".key";
- struct stat dummy;
- if ( stat ( filename_desc.c_str(), &dummy ) < 0 )
- {
- fprintf ( stderr, "features: %d, positions: %d\n", ( int ) features.size(),
- ( int ) positions.size() );
- if ( features.size() > 0 )
- fprintf ( stderr, "feature dimension: %d %d\n", features[0].size(), lfrep->getDescSize() );
- features.save ( filename_desc, descFormat );
- positions.save ( filename_pos, VVector::FILEFORMAT_LINE );
- }
- else
- {
- fprintf ( stderr, "description file %s exists !\n", filename_desc.c_str() );
- }
- return ret;
- }
- void LFWriteCache::visualize ( NICE::Image & img,
- const NICE::Vector & feature ) const
- {
- lfrep->visualize ( img, feature );
- }
- void LFWriteCache::visualizeFeatures ( NICE::Image & mark,
- const VVector & positions,
- size_t color ) const
- {
- lfrep->visualizeFeatures ( mark, positions, color );
- }
|