LocalFeatureSift.h 3.0 KB

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