createFeatures.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "VectorFeature.h"
  2. #include "HaarFeature.h"
  3. #include "PixelPairFeature.h"
  4. #include "SemanticFeature.h"
  5. #include "HOGFeature.h"
  6. #include "EOHFeature.h"
  7. #include "SparseVectorFeature.h"
  8. #include "ColorHistogramFeature.h"
  9. #include "ConvolutionFeature.h"
  10. #include "createFeatures.h"
  11. using namespace OBJREC;
  12. using namespace NICE;
  13. using namespace std;
  14. Feature *OBJREC::createFeatureFromTag ( const Config *conf, const std::string & tag )
  15. {
  16. if ( tag == "HAARFEATURE" ) {
  17. return new HaarFeature ( conf );
  18. } else if ( tag == "PIXELPAIRFEATURE" ) {
  19. return new PixelPairFeature ( conf );
  20. } else if ( ( tag == "HOGFEATURE" )
  21. || ( tag == "HOGFeature" ) ) {
  22. return new HOGFeature ( conf );
  23. } else if ( ( tag == "EOHFEATURE" )
  24. || ( tag == "EOHFeature" ) ){
  25. return new EOHFeature ( conf );
  26. // } else if ( tag == "TEXTONFEATURE" ) {
  27. // return new TextonFeature ( conf );
  28. } else if ( ( tag == "SEMANTICFEATURE" )
  29. || ( tag == "SemanticFeature" ) ){
  30. return new SemanticFeature ( conf );
  31. } else if ( ( tag == "ColorHistogramFeature" )
  32. || ( tag == "COLORHISTOGRAMFEATURE" ) ){
  33. return new ColorHistogramFeature ( conf );
  34. } else if ( ( tag == "VECTORFEATURE" )
  35. || ( tag == "VectorFeature" ) ){
  36. return new VectorFeature ( 4711 ); // bogus dimension value only needed for explode
  37. } else if ( ( tag == "SVECTORFEATURE" )
  38. || ( tag == "SparseVectorFeature" ) ){
  39. return new SparseVectorFeature ( 4711 ); // bogus dimension value only needed for explode
  40. } else if ( ( tag == "CONVOLUTIONFEATURE")
  41. || ( tag == "ConvolutionFeature" ) ) {
  42. return new ConvolutionFeature ( conf );
  43. } else {
  44. return NULL;
  45. }
  46. }
  47. void OBJREC::restoreFeaturePool ( FeaturePool & pool, const Config *conf, istream & is, int format)
  48. {
  49. assert ( conf != NULL );
  50. while ( !is.eof() )
  51. {
  52. double weight = 1.0;
  53. if ( !(is >> weight) ) break;
  54. std::string feature_tag;
  55. if ( !(is >> feature_tag) ) break;
  56. Feature *f = createFeatureFromTag ( conf, feature_tag );
  57. if ( f == NULL ) {
  58. fprintf (stderr, "Unknown feature description: %s\n", feature_tag.c_str() );
  59. exit(-1);
  60. }
  61. f->restore ( is, format );
  62. pool.push_back ( pair<double, Feature *> ( weight, f ) );
  63. }
  64. }