LocalFeatureSift.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @file LocalFeatureSift.h
  3. * @brief local feature with sift
  4. * @author Erik Rodner
  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. // NICE includes
  18. #include "core/vector/VectorT.h"
  19. #include "core/vector/MatrixT.h"
  20. #include "core/image/ImageT.h"
  21. #include "core/imagedisplay/ImageDisplay.h"
  22. #include "core/basics/Config.h"
  23. #include "core/basics/StringTools.h"
  24. #include "LocalFeature.h"
  25. // std includes
  26. #include <iostream>
  27. #include <string>
  28. #include <stdexcept>
  29. // SiftGPU & GL
  30. #ifdef NICE_USELIB_CUDASIFT
  31. #include <src/SiftGPU.h>
  32. #include <GL/gl.h>
  33. #endif
  34. namespace OBJREC {
  35. /** local feature with sift */
  36. class LocalFeatureSift : public LocalFeature
  37. {
  38. private:
  39. const NICE::Config* conf;
  40. protected:
  41. int octaves;
  42. int levels;
  43. bool normalizeFeature;
  44. int first_octave;
  45. double magnif;
  46. bool deletemode;
  47. bool integerValues;
  48. // for SiftGPU
  49. bool usegpu;
  50. float threshold;
  51. float edgeThreshold;
  52. void withPP ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
  53. #ifdef NICE_USELIB_CUDASIFT
  54. void withGPU ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
  55. #endif
  56. public:
  57. /** simple constructor */
  58. LocalFeatureSift ( const NICE::Config *conf );
  59. /** simple destructor */
  60. virtual ~LocalFeatureSift();
  61. /**
  62. * returns the size of each the SIFT-Feature
  63. * @return 128
  64. */
  65. int getDescSize() const {
  66. return 128;
  67. };
  68. //! returns true if gpu is used
  69. bool isGpuUsed() const {
  70. #ifdef NICE_USELIB_CUDASIFT
  71. return usegpu;
  72. #else
  73. return false;
  74. #endif
  75. };
  76. /**
  77. * get the descriptor
  78. * @param img input image
  79. * @param positions positions for the SIFT features
  80. * @param descriptors output
  81. * @return 0
  82. */
  83. virtual int getDescriptors ( const NICE::Image & img,
  84. NICE::VVector & positions,
  85. NICE::VVector & descriptors ) const;
  86. /**
  87. * computes the descriptor for a single image
  88. * @param img
  89. * @param positions
  90. * @param descriptors
  91. */
  92. void computeDesc ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
  93. /**
  94. * sort positions by scales for faster computing of the Keypoint orientation
  95. * @param positions
  96. */
  97. void sortPositions ( NICE::VVector & positions ) const;
  98. void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
  99. };
  100. } // namespace
  101. #endif