ImageFeatures.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * @file ImageFeatures.cpp
  3. * @brief create feature pool and additional information for ImageFeatures
  4. * @author Erik Rodner
  5. * @date 07/24/2008
  6. */
  7. #ifdef NOVISUAL
  8. #include <vislearning/nice_nonvis.h>
  9. #else
  10. #include <vislearning/nice.h>
  11. #endif
  12. #include <iostream>
  13. #include "EOHFeature.h"
  14. #include "HOGFeature.h"
  15. #include "PixelPairFeature.h"
  16. #include "HaarFeature.h"
  17. #include "ColorHistogramFeature.h"
  18. #include "HistFeature.h"
  19. #include "FIGradients.h"
  20. #include "FIHistograms.h"
  21. #include "ImageFeatures.h"
  22. using namespace OBJREC;
  23. using namespace std;
  24. // refactor-nice.pl: check this substitution
  25. // old: using namespace ice;
  26. using namespace NICE;
  27. // refactor-nice.pl: check this substitution
  28. // old: ImageFeatures::ImageFeatures( const Config *_conf, const string & section ) : conf(_conf)
  29. ImageFeatures::ImageFeatures( const Config *_conf, const std::string & section ) : conf(_conf)
  30. {
  31. use_eoh_features = conf->gB(section, "use_eoh_features", false);
  32. use_pixelpair_features = conf->gB(section, "use_pixelpair_features", false);
  33. use_hog_features = conf->gB(section, "use_hog_features", false);
  34. use_haar_features = conf->gB(section, "use_haar_features", false);
  35. use_colorhistogram_features = conf->gB(section, "use_colorhistogram_features", false);
  36. fprintf (stderr, "ImageFeatures: section = %s\n", section.c_str() );
  37. if ( use_eoh_features )
  38. features.push_back ( new EOHFeature ( conf ) );
  39. if ( use_pixelpair_features )
  40. features.push_back ( new PixelPairFeature ( conf ) );
  41. if ( use_hog_features )
  42. features.push_back ( new HOGFeature ( conf ) );
  43. if ( use_haar_features )
  44. features.push_back ( new HaarFeature ( conf ) );
  45. if ( use_colorhistogram_features )
  46. features.push_back ( new ColorHistogramFeature ( conf ) );
  47. // features.push_back ( new HistFeature ( conf, "ColorHistogramFeature", CachedExample::D_INTEGRALCOLOR ) );
  48. }
  49. ImageFeatures::~ImageFeatures()
  50. {
  51. for ( vector<Feature *>::iterator i = features.begin();
  52. i != features.end();
  53. i++ )
  54. {
  55. Feature *f = *i;
  56. delete f;
  57. }
  58. }
  59. void ImageFeatures::fillFeaturePool ( FeaturePool & fp, bool variableWindow )
  60. {
  61. for ( vector<Feature *>::const_iterator i = features.begin();
  62. i != features.end();
  63. i++ )
  64. (*i)->explode ( fp, variableWindow );
  65. if ( fp.empty() )
  66. {
  67. fprintf (stderr, "ImageFeatures::fillFeaturePool: No features selected !!\n");
  68. exit(-1);
  69. }
  70. }
  71. void ImageFeatures::fillExample ( CachedExample *ce )
  72. {
  73. int xsize, ysize;
  74. ce->getImageSize( xsize, ysize );
  75. if ( use_eoh_features || use_hog_features )
  76. {
  77. // refactor-nice.pl: check this substitution
  78. // old: string subsection;
  79. std::string subsection;
  80. if ( use_eoh_features )
  81. subsection = "EOHFeature";
  82. if ( use_hog_features )
  83. subsection = "HOGFeature";
  84. int subsamplex = conf->gI(subsection, "subsamplex", 1);
  85. int subsampley = conf->gI(subsection, "subsampley", 1);
  86. int numBins = conf->gI(subsection, "num_bins", 9);
  87. bool usesigned = conf->gB(subsection, "use_signed", true);
  88. FIGradients::buildEOHMap ( ce, subsamplex, subsampley, numBins, usesigned );
  89. }
  90. if ( use_colorhistogram_features )
  91. {
  92. // refactor-nice.pl: check this substitution
  93. // old: string subsection = "ColorHistogramFeature";
  94. std::string subsection = "ColorHistogramFeature";
  95. int numBinsH = conf->gI(subsection, "num_bins_h", 4);
  96. int numBinsS = conf->gI(subsection, "num_bins_s", 2);
  97. int numBinsV = conf->gI(subsection, "num_bins_v", 2);
  98. int subsamplex = conf->gI(subsection, "subsamplex", 1);
  99. int subsampley = conf->gI(subsection, "subsampley", 1);
  100. FIHistograms::buildHSVMap ( ce, subsamplex, subsampley,
  101. numBinsH, numBinsS, numBinsV );
  102. }
  103. }