createFeatures.cpp 2.0 KB

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