LFReadCache.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @file LFReadCache.cpp
  3. * @brief read local features from file
  4. * @author Erik Rodner
  5. * @date 02/14/2008
  6. */
  7. #include <vislearning/nice.h>
  8. #include <iostream>
  9. #include <fstream>
  10. #include "vislearning/baselib/Globals.h"
  11. #include "core/basics/StringTools.h"
  12. #include "core/basics/FileMgt.h"
  13. #include "vislearning/features/localfeatures/LFReadCache.h"
  14. using namespace OBJREC;
  15. using namespace std;
  16. using namespace NICE;
  17. LFReadCache::LFReadCache( const Config *conf,
  18. const LocalFeatureRepresentation *_lfrep,
  19. int _numFeatures ) : lfrep(_lfrep)
  20. {
  21. //srand(time(NULL));
  22. numFeatures = _numFeatures;
  23. cachedir = conf->gS("cache", "root");
  24. cachemode = Globals::getCacheMode ( conf->gS("cache", "mode", "cat") );
  25. std::string descFormat_s = conf->gS("cache", "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. }