LFReadCache.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file LFReadCache.cpp
  3. * @brief read local features from file
  4. * @author Erik Rodner
  5. * @date 02/14/2008
  6. */
  7. #include <iostream>
  8. #include <fstream>
  9. #include "vislearning/baselib/Globals.h"
  10. #include "core/basics/StringTools.h"
  11. #include "core/basics/FileMgt.h"
  12. #include "vislearning/features/localfeatures/LFReadCache.h"
  13. using namespace OBJREC;
  14. using namespace std;
  15. using namespace NICE;
  16. LFReadCache::LFReadCache ( const Config *conf,
  17. const LocalFeatureRepresentation *_lfrep,
  18. int _numFeatures ) : lfrep ( _lfrep )
  19. {
  20. //srand(time(NULL));
  21. numFeatures = _numFeatures;
  22. cachedir = conf->gS ( "cache", "root" );
  23. cachemode = Globals::getCacheMode ( conf->gS ( "cache", "mode", "cat" ) );
  24. std::string descFormat_s = conf->gS ( "cache", "descriptor_format", "binary_double" );
  25. if ( descFormat_s == "binary_double" )
  26. descFormat = VVector::FILEFORMAT_BINARY_DOUBLE;
  27. else if ( descFormat_s == "binary_uchar" )
  28. descFormat = VVector::FILEFORMAT_BINARY_CHAR;
  29. else if ( descFormat_s == "text_line" )
  30. descFormat = VVector::FILEFORMAT_LINE;
  31. else if ( ( descFormat_s == "text_nice" ) || ( descFormat_s == "text_ice" ) )
  32. descFormat = VVector::FILEFORMAT_NICE;
  33. else
  34. fthrow ( Exception, "Format " << descFormat_s << " is unknown." );
  35. }
  36. LFReadCache::~LFReadCache()
  37. {
  38. }
  39. int LFReadCache::getDescSize () const
  40. {
  41. if ( lfrep == NULL ) {
  42. fthrow ( Exception, "Unable to get descriptor size! (cache mode)" );
  43. return -1;
  44. } else {
  45. return lfrep->getDescSize();
  46. }
  47. }
  48. int LFReadCache::extractFeatures ( const NICE::ColorImage & img,
  49. VVector & features,
  50. VVector & positions ) const
  51. {
  52. return extractFeaturesTemplate<NICE::ColorImage> ( img, features, positions );
  53. }
  54. int LFReadCache::extractFeatures ( const NICE::Image & img,
  55. VVector & features,
  56. VVector & positions ) const
  57. {
  58. return extractFeaturesTemplate<NICE::Image> ( img, features, positions );
  59. }
  60. void LFReadCache::visualize ( NICE::Image & img,
  61. const NICE::Vector & feature ) const
  62. {
  63. lfrep->visualize ( img, feature );
  64. }
  65. void LFReadCache::visualizeFeatures ( NICE::Image & mark,
  66. const VVector & positions,
  67. size_t color ) const
  68. {
  69. lfrep->visualizeFeatures ( mark, positions, color );
  70. }