GenericLFSelection.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @file GenericLocalFeatureSelection.h
  3. * @brief This class provides a generic chooser function for different descriptors, which are derived from LocalFeatureRepresentation.
  4. * @date 26.10.2011
  5. */
  6. #ifndef _NICE_OBJREC_LF_SELECTION_INCLUDE
  7. #define _NICE_OBJREC_LF_SELECTION_INCLUDE
  8. #include "vislearning/features/localfeatures/LocalFeatureRepresentation.h"
  9. #include "vislearning/features/localfeatures/LFMikolajczyk.h"
  10. #include "vislearning/features/localfeatures/LFPatches.h"
  11. #include "vislearning/features/localfeatures/LFGenericLocal.h"
  12. #include "vislearning/features/localfeatures/LFSiftPP.h"
  13. // #include "vislearning/features/localfeatures/LFSegmentation.h" //located in objrec, please move this to ensure its functionality
  14. #include "vislearning/features/localfeatures/LFWriteCache.h"
  15. #include "vislearning/features/localfeatures/LFReadCache.h"
  16. // #include "vislearning/features/localfeatures/LFSegContour.h" //located in objrec, please move this to ensure its functionality
  17. #include "vislearning/features/localfeatures/LFColorSande.h"
  18. #include "vislearning/features/localfeatures/LFonHSG.h"
  19. /** NOTE: This class only returns Descriptors, which NOT need any given positions. All Descriptors calculate there own positions, on DIFFERENT ways. **/
  20. namespace OBJREC {
  21. class GenericLFSelection
  22. {
  23. public:
  24. /** LocalFeature Selector
  25. * @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.
  26. * @param[in] Config* - A pointer to the given configfile, which must contain "section" - "localfeature_type"
  27. * @param[in] string - This string defines the value for "section" in the configfile.
  28. * @return LocalFeatureRepresentation* - The LocalFeatureRepresentation which contains the selected LocalFeature-Type.
  29. */
  30. static
  31. LocalFeatureRepresentation *selectLocalFeatureRep ( const NICE::Config *conf, std::string section = "features" )
  32. {
  33. // return Value
  34. LocalFeatureRepresentation *lfrep = NULL;
  35. // string which defines the localfeature_type (for Ex. Sande, ...)
  36. std::string localfeature_type = conf->gS(section, "localfeature_type", "");
  37. if ( localfeature_type == "mikolajczyk" )
  38. {
  39. lfrep = new LFMikolajczyk ( conf );
  40. }
  41. else if ( localfeature_type == "color" )
  42. {
  43. lfrep = new LFColorSande ( conf );
  44. }
  45. else if ( ( localfeature_type == "sift" ) || ( localfeature_type == "siftpp" ) )
  46. {
  47. lfrep = new LFSiftPP ( conf );
  48. }
  49. else if ( ( localfeature_type == "generic_local" ) || ( localfeature_type == "generic" ) )
  50. {
  51. int numFeatures = conf->gI(section, "localfeature_count");
  52. lfrep = new LFGenericLocal ( conf, numFeatures );
  53. }
  54. else if ( ( localfeature_type == "grey" ) || ( localfeature_type == "patches" ) )
  55. {
  56. int numFeatures = conf->gI(section, "localfeature_count");
  57. lfrep = new LFPatches ( conf, numFeatures );
  58. }
  59. else if( ( localfeature_type == "onHSG" ) )
  60. {
  61. lfrep = new LFonHSG( conf);
  62. }
  63. else
  64. {
  65. lfrep = NULL;
  66. }
  67. if ( conf->gB(section, "localfeature_cache_read", false) )
  68. {
  69. int numFeatures = conf->gI(section, "localfeature_count", -1);
  70. LocalFeatureRepresentation *lfrep_read = new LFReadCache ( conf, lfrep, numFeatures );
  71. lfrep = lfrep_read;
  72. }
  73. // no correct localfeature_type was given
  74. if ( lfrep == NULL )
  75. fthrow(NICE::Exception, "Local feature type not found: " << localfeature_type );
  76. if ( conf->gB(section, "localfeature_cache_save", false) )
  77. {
  78. LocalFeatureRepresentation *lfrep_save = new LFWriteCache ( conf, lfrep );
  79. lfrep = lfrep_save;
  80. }
  81. return lfrep;
  82. }
  83. };
  84. }
  85. #endif