LocalFeatureRGBSift.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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
  18. LocalFeatureRGBSift::getDescriptors (const NICE::ColorImage & img, VVector & positions, VVector & descriptors) const
  19. {
  20. sortPositions (positions);
  21. descriptors.clear();
  22. for (int i = 0; i < (int) positions.size(); i++)
  23. {
  24. NICE::Vector v;
  25. descriptors.push_back (v);
  26. }
  27. vector<VVector> desc (3);
  28. #ifdef NICE_USELIB_OPENMP
  29. // check whether siftGPU should be used
  30. int numberOfCPU = omp_get_num_procs();
  31. int numberOfThreads = 0;
  32. if (isGpuUsed())
  33. {
  34. // in case of siftGPU it is possible to use one device
  35. numberOfThreads = 1;
  36. clog << "[log] LocalFeatureRGBSift: no multithreading" << endl;
  37. }
  38. else
  39. {
  40. // in case of siftpp it is possible to use all given cores
  41. numberOfThreads = numberOfCPU;
  42. clog << "[log] LocalFeatureRGBSift: multithreading with (max) " << numberOfCPU << " threads" << endl;
  43. }
  44. #endif
  45. #pragma omp parallel for num_threads(numberOfThreads)
  46. for (int i = 0; i < 3; i++) {
  47. NICE::Image tmp (img.width(), img.height());
  48. for (int y = 0; y < img.height(); y++) {
  49. for (int x = 0; x < img.width(); x++) {
  50. tmp.setPixel (x, y, img.getPixel (x, y, i));
  51. }
  52. }
  53. VVector pos = positions;
  54. computeDesc (tmp, pos, desc[i]);
  55. }
  56. for (int i = 0; i < 3; i++) {
  57. assert (desc[i].size() == descriptors.size());
  58. if (i == 0) {
  59. #pragma omp parallel for num_threads( numberOfCPU )
  60. for (int j = 0; j < (int) desc[i].size(); j++) {
  61. descriptors[j] = desc[i][j];
  62. }
  63. }
  64. else {
  65. #pragma omp parallel for num_threads( numberOfCPU )
  66. for (int j = 0; j < (int) desc[i].size(); j++) {
  67. descriptors[j].append (desc[i][j]);
  68. }
  69. }
  70. }
  71. return positions.size();
  72. }