IDKLTSampling.cpp 1.9 KB

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