FeatureFactory.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * @file FeatureFactory.cpp
  3. * @brief Abstract class for image classification
  4. * @author Erik Rodner
  5. * @date 07.09.2007
  6. */
  7. #include <iostream>
  8. #include "vislearning/features/fbase/FeatureFactory.h"
  9. #include "vislearning/baselib/ProgressBar.h"
  10. #include "vislearning/baselib/Preprocess.h"
  11. #include "vislearning/baselib/Globals.h"
  12. using namespace OBJREC;
  13. using namespace std;
  14. using namespace NICE;
  15. FeatureFactory::FeatureFactory( const Config *_conf )
  16. {
  17. Preprocess::Init ( _conf );
  18. }
  19. int FeatureFactory::convert ( const NICE::Image & img, NICE::Vector & vec )
  20. {
  21. fprintf (stderr, "FeatureFactory::convert: not yet implemented !\n");
  22. exit(-1);
  23. }
  24. int FeatureFactory::convertRGB ( const NICE::ColorImage & img, NICE::Vector & vec )
  25. {
  26. NICE::Vector tmp,vecr,vecg,vecb;
  27. NICE::Image *r = img.getChannel (0);
  28. NICE::Image *g = img.getChannel (1);
  29. NICE::Image *b = img.getChannel (2);
  30. //create feature vectors
  31. int ret;
  32. if(convert(*r,vecr)>=0 && convert(*g,vecg)>=0 && convert(*b,vecb)>=0)
  33. {
  34. vec.resize( vecr.size() + vecg.size() + vecb.size() );
  35. for ( unsigned int i = 0 ; i < vecr.size() ; i++ )
  36. vec[i] = vecr[i];
  37. for ( unsigned int i = 0 ; i < vecg.size() ; i++ )
  38. vec[i+vecr.size()] = vecg[i];
  39. for ( unsigned int i = 0 ; i < vecb.size() ; i++ )
  40. vec[i+vecr.size()+vecb.size()] = vecb[i];
  41. ret = 0;
  42. } else {
  43. ret = -1;
  44. }
  45. delete r;
  46. delete g;
  47. delete b;
  48. return ret;
  49. }
  50. FeatureFactory::~FeatureFactory()
  51. {
  52. }
  53. int FeatureFactory::convertSet ( const LabeledSet *filelist,
  54. LabeledSetVector & storage )
  55. {
  56. ProgressBar pb ("Feature Conversion");
  57. pb.show();
  58. LOOP_ALL_S(*filelist)
  59. {
  60. EACH_S(classno,fn);
  61. pb.update ( filelist->count() );
  62. NICE::Image img = Preprocess::ReadImgAdv ( fn );
  63. Globals::setCurrentImgFN(fn);
  64. NICE::Vector x;
  65. if ( convert ( img, x ) < 0 )
  66. {
  67. fprintf (stderr, "FeatureFactory: error building feature vector: %s !\n", fn.c_str() );
  68. continue;
  69. }
  70. storage.add (classno,x);
  71. }
  72. return 0;
  73. }
  74. int FeatureFactory::convertSetRGB ( const LabeledSet *filelist,
  75. LabeledSetVector & storage )
  76. {
  77. LOOP_ALL_S(*filelist)
  78. {
  79. EACH_S(classno,fn);
  80. NICE::ColorImage img = Preprocess::ReadImgAdvRGB ( fn );
  81. Globals::setCurrentImgFN(fn);
  82. NICE::Vector x;
  83. if ( convertRGB ( img, x ) < 0 )
  84. {
  85. fprintf (stderr, "FeatureFactoy: error building feature vector: %s !\n", fn.c_str() );
  86. continue;
  87. }
  88. storage.add (classno,x);
  89. }
  90. return 0;
  91. }