ImageFeatures.cpp 3.5 KB

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