GenericLocalFeatureSelection.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * @file GenericLocalFeatureSelection.h
  3. * @brief This class provides a generic chooser function for different descriptors, which are derived from LocalFeature.
  4. * @author Eric Bach, Alexander Freytag
  5. * @date 26.10.2011
  6. */
  7. #ifndef _NICE_OBJREC_LOCALFEATURESELECTION_INCLUDE
  8. #define _NICE_OBJREC_LOCALFEATURESELECTION_INCLUDE
  9. #include "vislearning/features/localfeatures/LocalFeatureRepresentation.h"
  10. // color-descriptor
  11. #include "vislearning/features/localfeatures/LocalFeatureRGBSift.h"
  12. #include "vislearning/features/localfeatures/LocalFeatureOpponnentSift.h"
  13. #include "vislearning/features/localfeatures/LocalFeatureColorWeijer.h"
  14. // non-color-descriptor
  15. #include "vislearning/features/localfeatures/LocalFeatureCentrist.h"
  16. #include "vislearning/features/localfeatures/LocalFeatureSift.h"
  17. /** NOTE: This class only returns Descriptors, which NEED given positions. NO Descriptors calculate there own positions. **/
  18. namespace OBJREC {
  19. /** @class GenericLocalFeatureSelection
  20. * @brief Select a specific LocalFeature-Type. LocalFeatures compute Descriptors, which DO need given positions (no internal position calculation)!
  21. *
  22. */
  23. class GenericLocalFeatureSelection
  24. {
  25. public:
  26. /** LocalFeature Selector
  27. * @brief This methode switches between the different LocalFeature-Types. One has to set the "localfeature_type" on a valid value and the methode returns a LocalFeatureRepresentation derived Object.
  28. * @param[in] Config* - A pointer to the given configfile, which must contain "section" - "localfeature_type"
  29. * @param[in] string - This string defines the value for "section" in the configfile.
  30. * @return LocalFeature* - The LocalFeature which contains the selected LocalFeature-Type.
  31. */
  32. static OBJREC::LocalFeature *selectLocalFeature ( const NICE::Config *conf, std::string section = "Features" )
  33. {
  34. // return Value
  35. LocalFeature *lf = NULL;
  36. // string which defines the localfeature_type (for Ex. RGB, OppSift, Sift...)
  37. std::string localfeature_type = conf->gS ( section, "localfeature_type", "not defined" );
  38. // The prefix NICE_* indicates that this implementation comes from a NICE-Developer.
  39. // Extern implementations can be added without NICE_* in this selection-class.
  40. if ( ( localfeature_type == "NICE_SIFT" ) || ( localfeature_type == "LocalFeatureSift" ) )
  41. {
  42. lf = new OBJREC::LocalFeatureSift ( conf );
  43. }
  44. else if ( ( localfeature_type == "NICE_RGBSIFT" ) || ( localfeature_type == "LocalFeatureRGBSift" ) )
  45. {
  46. lf = new OBJREC::LocalFeatureRGBSift ( conf );
  47. }
  48. else if ( ( localfeature_type == "NICE_OPPSIFT" ) || ( localfeature_type == "LocalFeatureOpponnentSift" ) )
  49. {
  50. lf = new OBJREC::LocalFeatureOpponnentSift ( conf );
  51. }
  52. else if ( ( localfeature_type == "colornames" ) || ( localfeature_type == "LocalFeatureColorWeijer" ) )
  53. {
  54. lf = new OBJREC::LocalFeatureColorWeijer ( conf );
  55. }
  56. else if ( ( localfeature_type == "centrist" ) || ( localfeature_type == "LocalFeatureCentrist" ) )
  57. {
  58. lf = new OBJREC::LocalFeatureCentrist ( conf );
  59. }
  60. // no correct localfeature_type was given
  61. if ( lf == NULL )
  62. fthrow ( NICE::Exception, "Local feature type not found: " << localfeature_type << " for section " << section);
  63. return lf;
  64. };
  65. static
  66. void restoreLocalFeature ( OBJREC::LocalFeature * _lf, std::istream & is, int format = 0 )
  67. {
  68. if ( is.good() )
  69. {
  70. if ( _lf != NULL )
  71. delete _lf;
  72. std::string className;
  73. is >> className; //class name
  74. if ( className == "<LocalFeatureSift>" )
  75. {
  76. _lf = new OBJREC::LocalFeatureSift();
  77. }
  78. else if ( className == "<LocalFeatureRGBSift>" )
  79. {
  80. _lf = new OBJREC::LocalFeatureRGBSift();
  81. }
  82. else if ( className == "<LocalFeatureOpponnentSift>" )
  83. {
  84. _lf = new OBJREC::LocalFeatureOpponnentSift();
  85. }
  86. else if ( className == "<LocalFeatureColorWeijer>" )
  87. {
  88. _lf = new OBJREC::LocalFeatureColorWeijer();
  89. }
  90. else if ( className == "<LocalFeatureCentrist>" )
  91. {
  92. _lf = new OBJREC::LocalFeatureCentrist();
  93. }
  94. else
  95. {
  96. fthrow ( NICE::Exception, "GenericLocalFeatureSelection::restoreLocalFeatureRep -- class name " << className << "unknown. Aborting." );
  97. }
  98. //undo reading of class name
  99. for ( uint i = 0; i < className.size(); i++)
  100. {
  101. is.unget();
  102. }
  103. //now, call the restore method of the underlying object
  104. //NOTE this could be also done externally, leaving only the actual instantiation of the derived objects here
  105. _lf->restore ( is );
  106. }
  107. else
  108. {
  109. fthrow ( NICE::Exception, "GenericLocalFeatureSelection::restoreLocalFeatureRep -- InStream not initialized - restoring not possible!" );
  110. }
  111. };
  112. };
  113. }
  114. #endif