PICCANTE  0.4
The hottest HDR imaging library!
orb_descriptor.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_FEATURES_MATCHING_ORB_DESCRIPTOR_HPP
19 #define PIC_FEATURES_MATCHING_ORB_DESCRIPTOR_HPP
20 
21 #include <vector>
22 
23 #include "../base.hpp"
24 #include "../image.hpp"
25 #include "../features_matching/brief_descriptor.hpp"
26 
27 namespace pic {
28 
29 #ifndef PIC_DISABLE_EIGEN
30 
35 {
36 protected:
37  std::vector< int* > x_theta, y_theta;
38 
47  void rotate2D(int x, int y, int &x_out, int &y_out, float angle)
48  {
49  float cosAng = cosf(angle);
50  float sinAng = sinf(angle);
51 
52  float x_f = float(x);
53  float y_f = float(y);
54 
55  x_out = int(x_f * cosAng - y_f * sinAng);
56  y_out = int(x_f * sinAng + y_f * cosAng);
57  }
58 
63  {
64  uint n2 = n * 2;
65 
66  for(uint i = 0; i < 360; i += 12) {
67  int * X_r = new int[n2];
68  int * Y_r = new int[n2];
69 
70  float ang = (float(i) * C_PI_2) / 360.0f;
71 
72  for(uint j = 0; j < n2; j += 2) {
73  rotate2D(x[j], x[j + 1], X_r[j], X_r[j + 1], ang);
74  rotate2D(y[j], y[j + 1], Y_r[j], Y_r[j + 1], ang);
75  }
76 
77  x_theta.push_back(X_r);
78  y_theta.push_back(Y_r);
79  }
80  }
81 
82  int halfS;
83 
84 public:
85 
91  ORBDescriptor(int S = 31, int n = 256, unsigned int seed = 1)
92  {
93  m = new std::mt19937(seed);
94 
95  this->S = S;
96  this->halfS = S >> 1;
97  this->sigma_sq = float(S * S) / 25.0f;
98  this->sigma_sq_2 = 2.0f * this->sigma_sq;
99 
101  rotateSamples();
102  }
103 
105  {
106  release();
107  }
108 
117  uint *get(Image *img, int x0, int y0, uint* desc = NULL)
118  {
119  if(img == NULL){
120  return NULL;
121  }
122 
123  if(!img->checkCoordinates(x0, y0)) {
124  return NULL;
125  }
126 
127  float grad[2];
128 
129  img->getMomentsVal(x0, y0, S, grad);
130 
131  float theta = atan2f(grad[1], grad[0]);
132 
133  if(theta < 0.0f) {
134  theta = CLAMPi(C_PI_2 + theta, 0.0f, C_PI_2);
135  }
136 
137  //float theta_nor = CLAMPi(theta / C_PI_2, 0.0f, 1.0f);
138 
139  uint theta_nor = CLAMPi(uint(theta * 255.0f / C_PI_2), 0, 255);
140 
141  uint n = x_theta.size() - 1;
142 
143  uint index = (n * theta_nor) >> 8;
144 
145  return getAux(img, x0, y0, x_theta[index], y_theta[index], desc);
146  }
147 };
148 
149 #endif
150 
151 } // end namespace pic
152 
153 #endif /* PIC_FEATURES_MATCHING_ORB_DESCRIPTOR_HPP */
154 
std::vector< int *> x_theta
Definition: orb_descriptor.hpp:37
unsigned int uint
Definition: base.hpp:23
void rotate2D(int x, int y, int &x_out, int &y_out, float angle)
rotate2D
Definition: orb_descriptor.hpp:47
int S
Definition: brief_descriptor.hpp:50
~ORBDescriptor()
Definition: orb_descriptor.hpp:104
std::mt19937 * m
Definition: brief_descriptor.hpp:53
The BRIEFDescriptor class.
Definition: brief_descriptor.hpp:47
float sigma_sq
Definition: brief_descriptor.hpp:52
std::vector< int *> y_theta
Definition: orb_descriptor.hpp:37
ORBDescriptor(int S=31, int n=256, unsigned int seed=1)
ORBDescriptor.
Definition: orb_descriptor.hpp:91
const float C_PI_2
Definition: math.hpp:52
void generateSamples(unsigned int n)
generateSamples
Definition: brief_descriptor.hpp:77
void release()
Release deallocates memory.
Definition: brief_descriptor.hpp:191
int * y
Definition: brief_descriptor.hpp:56
uint * getAux(Image *img, int x0, int y0, int *x, int *y, uint *desc=NULL)
getAux computes a descriptor at position (x0,y0) with size n.
Definition: brief_descriptor.hpp:119
int * x
Definition: brief_descriptor.hpp:56
The Image class stores an image as buffer of float.
Definition: image.hpp:60
float sigma_sq_2
Definition: brief_descriptor.hpp:52
The ORBDescriptor class.
Definition: orb_descriptor.hpp:34
#define CLAMPi(x, a, b)
Definition: math.hpp:81
Definition: bilateral_separation.hpp:25
unsigned int n
Definition: brief_descriptor.hpp:51
void rotateSamples()
rotateSamples rotates x and y samples
Definition: orb_descriptor.hpp:62
int halfS
Definition: orb_descriptor.hpp:82