LocalFeatureRGBSift.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "objrec/features/localfeatures/LocalFeatureRGBSift.h"
  2. using namespace OBJREC;
  3. using namespace std;
  4. using namespace NICE;
  5. LocalFeatureRGBSift::LocalFeatureRGBSift (const Config *conf) : LocalFeatureSift (conf)
  6. {
  7. deletemode = false;
  8. }
  9. LocalFeatureRGBSift::~LocalFeatureRGBSift()
  10. {
  11. }
  12. int
  13. LocalFeatureRGBSift::getDescriptors (const NICE::ColorImage & img, VVector & positions, VVector & descriptors) const
  14. {
  15. sortPositions (positions);
  16. descriptors.clear();
  17. for (int i = 0; i < (int) positions.size(); i++)
  18. {
  19. NICE::Vector v;
  20. descriptors.push_back (v);
  21. }
  22. vector<VVector> desc (3);
  23. #ifdef NICE_USELIB_OPENMP
  24. // check whether siftGPU should be used
  25. int numberOfCPU = omp_get_num_procs();
  26. int numberOfThreads = 0;
  27. if (isGpuUsed())
  28. {
  29. // in case of siftGPU it is possible to use one device
  30. numberOfThreads = 1;
  31. clog << "[log] LocalFeatureRGBSift: no multithreading" << endl;
  32. }
  33. else
  34. {
  35. // in case of siftpp it is possible to use all given cores
  36. numberOfThreads = numberOfCPU;
  37. clog << "[log] LocalFeatureRGBSift: multithreading with (max) " << numberOfCPU << " threads" << endl;
  38. }
  39. #endif
  40. #pragma omp parallel for num_threads(numberOfThreads)
  41. for (int i = 0; i < 3; i++) {
  42. NICE::Image tmp (img.width(), img.height());
  43. for (int y = 0; y < img.height(); y++) {
  44. for (int x = 0; x < img.width(); x++) {
  45. tmp.setPixel (x, y, img.getPixel (x, y, i));
  46. }
  47. }
  48. VVector pos = positions;
  49. computeDesc (tmp, pos, desc[i]);
  50. }
  51. for (int i = 0; i < 3; i++) {
  52. assert (desc[i].size() == descriptors.size());
  53. if (i == 0) {
  54. #pragma omp parallel for num_threads( numberOfCPU )
  55. for (int j = 0; j < (int) desc[i].size(); j++) {
  56. descriptors[j] = desc[i][j];
  57. }
  58. }
  59. else {
  60. #pragma omp parallel for num_threads( numberOfCPU )
  61. for (int j = 0; j < (int) desc[i].size(); j++) {
  62. descriptors[j].append (desc[i][j]);
  63. }
  64. }
  65. }
  66. return positions.size();
  67. }