LocalFeatureSift.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /**
  2. * @file LocalFeatureSift.h
  3. * @brief local feature with sift
  4. * @author Erik Rodner, Alexander Freytag
  5. * @date 03/10/2012 (Eric Bach)
  6. * @note some notes to the use of siftGPU (added by Eric Bach)
  7. * - install cudaSift & siftGPU (see Makefile.config)
  8. * - add to libdepend.inc: $(call PKG_DEPEND_EXT, CUDASIFT) to specify: -DNICE_USELIB_CUDASIFT as compilerflag
  9. * - add to section [LFSiftPP] use_siftgpu=true (or 'false' to disable the gpu-support)
  10. *
  11. * If you use the gpu-support just one device is supported until now.
  12. * If your device do not support the siftGPU completly the class switch to "normal" sift.
  13. * It is possible to compile this class without siftGPU, but then you must not specify the flag: -DNICE_USELIB_CUDASIFT.
  14. */
  15. #ifndef LOCALFEATURESIFTINCLUDE
  16. #define LOCALFEATURESIFTINCLUDE
  17. // STL includes
  18. #include <iostream>
  19. #include <string>
  20. #include <stdexcept>
  21. // nice-core includes
  22. #include <core/basics/Config.h>
  23. #include <core/basics/StringTools.h>
  24. //
  25. #include <core/image/ImageT.h>
  26. #include <core/imagedisplay/ImageDisplay.h>
  27. //
  28. #include <core/vector/VectorT.h>
  29. #include <core/vector/MatrixT.h>
  30. // nice-vislearning includes
  31. #include "LocalFeature.h"
  32. // SiftGPU & GL
  33. #ifdef NICE_USELIB_CUDASIFT
  34. #include <src/SiftGPU.h>
  35. #include <GL/gl.h>
  36. #endif
  37. namespace OBJREC {
  38. /** local feature with sift */
  39. class LocalFeatureSift : public LocalFeature
  40. {
  41. protected:
  42. /////////////////////////
  43. /////////////////////////
  44. // PROTECTED VARIABLES //
  45. /////////////////////////
  46. /////////////////////////
  47. int octaves;
  48. int levels;
  49. bool normalizeFeature;
  50. int first_octave;
  51. double magnif;
  52. bool deletemode;
  53. bool integerValues;
  54. // for SiftGPU
  55. bool usegpu;
  56. float threshold;
  57. float edgeThreshold;
  58. /////////////////////////
  59. /////////////////////////
  60. // PROTECTED METHODS //
  61. /////////////////////////
  62. /////////////////////////
  63. void withPP ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
  64. #ifdef NICE_USELIB_CUDASIFT
  65. void withGPU ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
  66. #endif
  67. public:
  68. ///////////////////// ///////////////////// /////////////////////
  69. // CONSTRUCTORS / DESTRUCTORS
  70. ///////////////////// ///////////////////// /////////////////////
  71. /**
  72. * @brief default constructor
  73. * @date 09-02-2014 (dd-mm-yyyy )
  74. * @author Alexander Freytag
  75. */
  76. LocalFeatureSift ( );
  77. /**
  78. * @brief recommended constructor, calls initFromConfig
  79. * @date 09-02-2014 (dd-mm-yyyy )
  80. * @author Alexander Freytag
  81. */
  82. LocalFeatureSift ( const NICE::Config * _conf );
  83. /**
  84. * @brief simple destructor
  85. */
  86. virtual ~LocalFeatureSift();
  87. /**
  88. * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
  89. * @author Alexander Freytag
  90. * @date 09-02-2014 ( dd-mm-yyyy )
  91. */
  92. void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LocalFeatureSift");
  93. ///////////////////// ///////////////////// /////////////////////
  94. // FEATURE STUFF
  95. ///////////////////// ///////////////////// //////////////////
  96. /**
  97. * returns the size of each the SIFT-Feature
  98. * @return 128
  99. */
  100. int getDescSize() const {
  101. return 128;
  102. };
  103. //! returns true if gpu is used
  104. bool isGpuUsed() const {
  105. #ifdef NICE_USELIB_CUDASIFT
  106. return usegpu;
  107. #else
  108. return false;
  109. #endif
  110. };
  111. /**
  112. * get the descriptor
  113. * @param img input image
  114. * @param positions positions for the SIFT features
  115. * @param descriptors output
  116. * @return 0
  117. */
  118. virtual int getDescriptors ( const NICE::Image & img,
  119. NICE::VVector & positions,
  120. NICE::VVector & descriptors ) const;
  121. /**
  122. * computes the descriptor for a single image
  123. * @param img
  124. * @param positions
  125. * @param descriptors
  126. */
  127. void computeDesc ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
  128. /**
  129. * sort positions by scales for faster computing of the Keypoint orientation
  130. * @param positions
  131. */
  132. void sortPositions ( NICE::VVector & positions ) const;
  133. virtual void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
  134. ///////////////////// INTERFACE PERSISTENT /////////////////////
  135. // interface specific methods for store and restore
  136. ///////////////////// INTERFACE PERSISTENT /////////////////////
  137. /**
  138. * @brief Load object from external file (stream)
  139. * @author Alexander Freytag
  140. * @date 09-02-2014 ( dd-mmyyyy)
  141. */
  142. virtual void restore ( std::istream & is, int format = 0 );
  143. /**
  144. * @brief Save object to external file (stream)
  145. * @author Alexander Freytag
  146. * @date 09-02-2014 ( dd-mmyyyy)
  147. */
  148. virtual void store( std::ostream & os, int format = 0 ) const;
  149. /**
  150. * @brief Clear object
  151. * @author Alexander Freytag
  152. * @date 09-02-2014 ( dd-mmyyyy)
  153. */
  154. virtual void clear ();
  155. };
  156. } // namespace
  157. #endif