LFReadCache.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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,
  19. const std::string & _section ) : lfrep ( _lfrep )
  20. {
  21. //srand(time(NULL));
  22. numFeatures = _numFeatures;
  23. cachedir = conf->gS ( _section, "root" );
  24. cachemode = Globals::getCacheMode ( conf->gS ( _section, "mode", "cat" ) );
  25. std::string descFormat_s = conf->gS ( _section, "descriptor_format", "binary_double" );
  26. if ( descFormat_s == "binary_double" )
  27. descFormat = VVector::FILEFORMAT_BINARY_DOUBLE;
  28. else if ( descFormat_s == "binary_uchar" )
  29. descFormat = VVector::FILEFORMAT_BINARY_CHAR;
  30. else if ( descFormat_s == "text_line" )
  31. descFormat = VVector::FILEFORMAT_LINE;
  32. else if ( ( descFormat_s == "text_nice" ) || ( descFormat_s == "text_ice" ) )
  33. descFormat = VVector::FILEFORMAT_NICE;
  34. else
  35. fthrow ( Exception, "Format " << descFormat_s << " is unknown." );
  36. }
  37. LFReadCache::~LFReadCache()
  38. {
  39. }
  40. int LFReadCache::getDescSize () const
  41. {
  42. if ( lfrep == NULL ) {
  43. fthrow ( Exception, "Unable to get descriptor size! (cache mode)" );
  44. return -1;
  45. } else {
  46. return lfrep->getDescSize();
  47. }
  48. }
  49. int LFReadCache::extractFeatures ( const NICE::ColorImage & img,
  50. VVector & features,
  51. VVector & positions ) const
  52. {
  53. return extractFeaturesTemplate<NICE::ColorImage> ( img, features, positions );
  54. }
  55. int LFReadCache::extractFeatures ( const NICE::Image & img,
  56. VVector & features,
  57. VVector & positions ) const
  58. {
  59. return extractFeaturesTemplate<NICE::Image> ( img, features, positions );
  60. }
  61. void LFReadCache::visualize ( NICE::Image & img,
  62. const NICE::Vector & feature ) const
  63. {
  64. lfrep->visualize ( img, feature );
  65. }
  66. void LFReadCache::visualizeFeatures ( NICE::Image & mark,
  67. const VVector & positions,
  68. size_t color ) const
  69. {
  70. lfrep->visualizeFeatures ( mark, positions, color );
  71. }