LocalFeatureRGBSift.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifdef NICE_USELIB_OPENMP
  2. #include <omp.h>
  3. #endif
  4. #include <iostream>
  5. #include "vislearning/features/localfeatures/sift.h"
  6. #include "vislearning/features/localfeatures/LocalFeatureRGBSift.h"
  7. using namespace OBJREC;
  8. using namespace std;
  9. using namespace NICE;
  10. #undef DEBUG_show_one_picture_per_channel
  11. LocalFeatureRGBSift::LocalFeatureRGBSift( const Config *conf ):LocalFeatureSift(conf)
  12. {
  13. deletemode = false;
  14. }
  15. LocalFeatureRGBSift::~LocalFeatureRGBSift()
  16. {
  17. }
  18. int LocalFeatureRGBSift::getDescriptors ( const NICE::ColorImage & img,
  19. VVector & positions,
  20. VVector & descriptors ) const
  21. {
  22. sortPositions(positions);
  23. descriptors.clear();
  24. // Fuer jede Position wird ein leerer NICE::Vector in descriptors eingefuegt
  25. for(int i = 0; i < (int) positions.size(); i++)
  26. {
  27. NICE::Vector v;
  28. descriptors.push_back(v);
  29. }
  30. vector<VVector> desc( 3 );
  31. #ifndef DEBUG_show_one_picture_per_channel
  32. #pragma omp parallel for
  33. #endif
  34. // Descriptor fuer jeden der 3 Kanaele berechnen
  35. for(int i = 0; i < 3; i++)
  36. {
  37. NICE::Image tmp(img.width(), img.height());
  38. for(int y = 0; y < img.height(); y++)
  39. {
  40. for(int x = 0; x < img.width(); x++)
  41. {
  42. tmp.setPixel(x,y,img.getPixel(x,y,i));
  43. }
  44. }
  45. #ifdef DEBUG_show_one_picture_per_channel
  46. showImage( tmp );
  47. #endif
  48. VVector pos = positions;
  49. computeDesc(tmp, pos, desc[i]);
  50. }
  51. // ?
  52. //desc[0] = desc[2];
  53. for(int i = 0; i < 3; i++)
  54. {
  55. assert(desc[i].size() == descriptors.size());
  56. if(i == 0)
  57. {
  58. #ifndef DEBUG_show_one_picture_per_channel
  59. #pragma omp parallel for
  60. #endif
  61. for(int j = 0; j < (int)desc[i].size(); j++)
  62. {
  63. // kopiere den roten (1.)-Kanal in den Descriptorsvektor
  64. descriptors[j] = desc[i][j];
  65. }
  66. }
  67. else
  68. {
  69. #ifndef DEBUG_show_one_picture_per_channel
  70. #pragma omp parallel for
  71. #endif
  72. for(int j = 0; j < (int)desc[i].size(); j++)
  73. {
  74. descriptors[j].append(desc[i][j]);
  75. }
  76. }
  77. }
  78. return positions.size();
  79. }