IDKLTSampling.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file IDKLTSampling.cpp
  3. * @brief random interest point sampling
  4. * @author Erik Rodner
  5. * @date 02/05/2008
  6. */
  7. #ifdef NOVISUAL
  8. #include <vislearning/nice_nonvis.h>
  9. #else
  10. #include <vislearning/nice.h>
  11. #endif
  12. #include <iostream>
  13. #include "vislearning/features/localfeatures/IDKLTSampling.h"
  14. #include "core/image/ImageTools.h"
  15. using namespace OBJREC;
  16. using namespace std;
  17. using namespace NICE;
  18. IDKLTSampling::IDKLTSampling(const Config *conf, int _numSamples) :
  19. numSamples(_numSamples)
  20. {
  21. minScale = conf->gD("IDKLTSampling", "min_scale", 1.0);
  22. fixedOrientation = conf->gB("IDKLTSampling", "fixed_orientation", true);
  23. srand(time(NULL));
  24. }
  25. IDKLTSampling::~IDKLTSampling()
  26. {
  27. }
  28. int IDKLTSampling::getInterests(const Image & img,
  29. std::vector<Vector> & positions) const
  30. {
  31. std::auto_ptr<Matrix> corners(KLTCornerDetector(img, numSamples, 100, 1,2));
  32. for (int j = 0; j < corners->rows(); j++)
  33. {
  34. int x, y;
  35. x = (*corners)(j, 0);
  36. y = (*corners)(j, 1);
  37. Vector pos(3);
  38. pos[0] = x;
  39. pos[1] = y;
  40. pos[2] = 0;
  41. positions.push_back(pos);
  42. }
  43. fprintf(stderr, "IDKLTSampling finished\n");
  44. return 0;
  45. }
  46. int IDKLTSampling::getInterests(const ImagePyramid & imp,
  47. std::vector<Vector> & positions) const
  48. {
  49. int numLevels = imp.getNumLevels();
  50. std::vector<Matrix *> cornersAtLevel;
  51. for (int level = 0; level < numLevels; level++)
  52. {
  53. const NICE::Image & img = imp.getLevel(level);
  54. cornersAtLevel.push_back(KLTCornerDetector(img, numSamples, 100, 1, 2));
  55. }
  56. for (int level = 0; level < numLevels; level++)
  57. {
  58. for (int j = 0; j < cornersAtLevel[level]->rows(); j++)
  59. {
  60. const NICE::Image & img = imp.getLevel(level);
  61. int x, y;
  62. x = (*cornersAtLevel[level])(j, 0);
  63. y = (*cornersAtLevel[level])(j, 1);
  64. double xo, yo;
  65. imp.getOriginalCoordinates(x, y, level, xo, yo);
  66. Vector pos(3);
  67. pos[0] = xo;
  68. pos[1] = yo;
  69. pos[2] = level;
  70. positions.push_back(pos);
  71. }
  72. }
  73. for (int level = 0; level < numLevels; level++)
  74. {
  75. delete cornersAtLevel[level];
  76. }
  77. fprintf(stderr, "IDKLTSampling finished\n");
  78. return 0;
  79. }