LocalFeatureRGBSift.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. LocalFeatureRGBSift::LocalFeatureRGBSift (const Config *conf) : LocalFeatureSift (conf)
  11. {
  12. deletemode = false;
  13. }
  14. LocalFeatureRGBSift::~LocalFeatureRGBSift()
  15. {
  16. }
  17. int LocalFeatureRGBSift::getDescriptors (const NICE::ColorImage & img,
  18. VVector & positions,
  19. VVector & descriptors) const
  20. {
  21. sortPositions (positions);
  22. descriptors.clear();
  23. // Fuer jede Position wird ein leerer NICE::Vector in descriptors eingefuegt
  24. for (int i = 0; i < (int) positions.size(); i++) {
  25. NICE::Vector v;
  26. descriptors.push_back (v);
  27. }
  28. vector<VVector> desc (3);
  29. // Maximale Anzahl an Thread ist abhaengig von der Anzahl der verfuegbaren Grafikkarten
  30. // bzw. (wenn siftGPU nicht genutzt wird) von der Anzahl der Prozessoren
  31. const int numberOfGPU = getNumOfDevices();
  32. const int numberOfCPU = omp_get_num_procs();
  33. if (numberOfGPU == -1) { // siftGPU wird nicht genutzt
  34. omp_set_num_threads (numberOfCPU);
  35. }
  36. else if (numberOfGPU == 0) {
  37. fthrow (Exception, "No Devices");
  38. }
  39. else { // siftGPU wird genutzt: LocalFeatureSiftGPU kuemmert sich um die threads.
  40. omp_set_num_threads (numberOfGPU);
  41. }
  42. #pragma omp parallel for
  43. // Descriptor fuer jeden der 3 Kanaele berechnen
  44. for (int i = 0; i < 3; i++) {
  45. NICE::Image tmp (img.width(), img.height());
  46. for (int y = 0; y < img.height(); y++) {
  47. for (int x = 0; x < img.width(); x++) {
  48. tmp.setPixel (x, y, img.getPixel (x, y, i));
  49. }
  50. }
  51. VVector pos = positions;
  52. computeDesc (tmp, pos, desc[i]);
  53. }
  54. // ab hier stehen wird nur noch mit dem Prozessor gerechnet
  55. omp_set_num_threads (numberOfCPU);
  56. // ?
  57. //desc[0] = desc[2];
  58. for (int i = 0; i < 3; i++) {
  59. assert (desc[i].size() == descriptors.size());
  60. if (i == 0) {
  61. #pragma omp parallel for
  62. for (int j = 0; j < (int) desc[i].size(); j++) {
  63. // kopiere den roten (1.)-Kanal in den Descriptorsvektor
  64. descriptors[j] = desc[i][j];
  65. }
  66. }
  67. else {
  68. #pragma omp parallel for
  69. for (int j = 0; j < (int) desc[i].size(); j++) {
  70. descriptors[j].append (desc[i][j]);
  71. }
  72. }
  73. }
  74. return positions.size();
  75. }