opencv-ffi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +15 -0
  3. data/README.md +126 -0
  4. data/Rakefile +52 -0
  5. data/docs/DocsIndex.md +1 -0
  6. data/docs/examples/load_image.rb +25 -0
  7. data/ext/Rakefile +13 -0
  8. data/ext/aishack-sift/.gitignore +4 -0
  9. data/ext/aishack-sift/Descriptor.h +34 -0
  10. data/ext/aishack-sift/KeyPoint.h +38 -0
  11. data/ext/aishack-sift/README +20 -0
  12. data/ext/aishack-sift/SIFT.cpp +1036 -0
  13. data/ext/aishack-sift/SIFT.h +84 -0
  14. data/ext/aishack-sift/example/.gitignore +2 -0
  15. data/ext/aishack-sift/example/Makefile +24 -0
  16. data/ext/aishack-sift/example/MySIFT.cpp +29 -0
  17. data/ext/aishack-sift/mkrf_conf.rb +13 -0
  18. data/ext/aishack-sift/siftlib.cpp +85 -0
  19. data/ext/eigen/.gitignore +4 -0
  20. data/ext/eigen/eigen_polynomial.cpp +41 -0
  21. data/ext/eigen/eigen_svd.cpp +100 -0
  22. data/ext/eigen/mkrf_conf.rb +14 -0
  23. data/ext/mkrf-monkey.rb +85 -0
  24. data/ext/mkrf-rakehelper-monkey.rb +52 -0
  25. data/ext/mkrf_conf.rb +3 -0
  26. data/ext/opencv-ffi/.gitignore +4 -0
  27. data/ext/opencv-ffi/matcher_helper.cpp +56 -0
  28. data/ext/opencv-ffi/mkrf_conf.rb +12 -0
  29. data/ext/opencv-ffi/vector_math.cpp +39 -0
  30. data/ext/opensurf/.gitignore +4 -0
  31. data/ext/opensurf/README +38 -0
  32. data/ext/opensurf/fasthessian.cpp +376 -0
  33. data/ext/opensurf/fasthessian.h +108 -0
  34. data/ext/opensurf/integral.cpp +58 -0
  35. data/ext/opensurf/integral.h +55 -0
  36. data/ext/opensurf/ipoint.cpp +108 -0
  37. data/ext/opensurf/ipoint.h +76 -0
  38. data/ext/opensurf/kmeans.h +172 -0
  39. data/ext/opensurf/mkrf_conf.rb +10 -0
  40. data/ext/opensurf/responselayer.h +92 -0
  41. data/ext/opensurf/surf.cpp +317 -0
  42. data/ext/opensurf/surf.h +66 -0
  43. data/ext/opensurf/surflib.cpp +98 -0
  44. data/ext/opensurf/surflib.h +96 -0
  45. data/ext/opensurf/utils.cpp +357 -0
  46. data/ext/opensurf/utils.h +63 -0
  47. data/lib/.gitignore +1 -0
  48. data/lib/opencv-ffi-ext/eigen.rb +84 -0
  49. data/lib/opencv-ffi-ext/features2d.rb +4 -0
  50. data/lib/opencv-ffi-ext/matcher_helper.rb +24 -0
  51. data/lib/opencv-ffi-ext/opensurf.rb +217 -0
  52. data/lib/opencv-ffi-ext/sift.rb +118 -0
  53. data/lib/opencv-ffi-ext/vector_math.rb +115 -0
  54. data/lib/opencv-ffi-wrappers.rb +7 -0
  55. data/lib/opencv-ffi-wrappers/core.rb +24 -0
  56. data/lib/opencv-ffi-wrappers/core/iplimage.rb +50 -0
  57. data/lib/opencv-ffi-wrappers/core/mat.rb +268 -0
  58. data/lib/opencv-ffi-wrappers/core/misc_draw.rb +44 -0
  59. data/lib/opencv-ffi-wrappers/core/point.rb +286 -0
  60. data/lib/opencv-ffi-wrappers/core/rect.rb +40 -0
  61. data/lib/opencv-ffi-wrappers/core/scalar.rb +104 -0
  62. data/lib/opencv-ffi-wrappers/core/size.rb +88 -0
  63. data/lib/opencv-ffi-wrappers/enumerable.rb +10 -0
  64. data/lib/opencv-ffi-wrappers/features2d.rb +17 -0
  65. data/lib/opencv-ffi-wrappers/features2d/image_patch.rb +322 -0
  66. data/lib/opencv-ffi-wrappers/features2d/star.rb +111 -0
  67. data/lib/opencv-ffi-wrappers/features2d/surf.rb +115 -0
  68. data/lib/opencv-ffi-wrappers/highgui.rb +10 -0
  69. data/lib/opencv-ffi-wrappers/imgproc.rb +4 -0
  70. data/lib/opencv-ffi-wrappers/imgproc/features.rb +35 -0
  71. data/lib/opencv-ffi-wrappers/imgproc/geometric.rb +39 -0
  72. data/lib/opencv-ffi-wrappers/matcher.rb +297 -0
  73. data/lib/opencv-ffi-wrappers/matrix.rb +37 -0
  74. data/lib/opencv-ffi-wrappers/misc.rb +41 -0
  75. data/lib/opencv-ffi-wrappers/misc/params.rb +34 -0
  76. data/lib/opencv-ffi-wrappers/sequence.rb +37 -0
  77. data/lib/opencv-ffi-wrappers/vectors.rb +38 -0
  78. data/lib/opencv-ffi.rb +12 -0
  79. data/lib/opencv-ffi/calib3d.rb +26 -0
  80. data/lib/opencv-ffi/core.rb +15 -0
  81. data/lib/opencv-ffi/core/draw.rb +68 -0
  82. data/lib/opencv-ffi/core/dynamic.rb +13 -0
  83. data/lib/opencv-ffi/core/library.rb +5 -0
  84. data/lib/opencv-ffi/core/operations.rb +122 -0
  85. data/lib/opencv-ffi/core/point.rb +22 -0
  86. data/lib/opencv-ffi/core/types.rb +172 -0
  87. data/lib/opencv-ffi/cvffi.rb +8 -0
  88. data/lib/opencv-ffi/features2d.rb +7 -0
  89. data/lib/opencv-ffi/features2d/library.rb +6 -0
  90. data/lib/opencv-ffi/features2d/star.rb +30 -0
  91. data/lib/opencv-ffi/features2d/surf.rb +38 -0
  92. data/lib/opencv-ffi/highgui.rb +31 -0
  93. data/lib/opencv-ffi/imgproc.rb +9 -0
  94. data/lib/opencv-ffi/imgproc/features.rb +37 -0
  95. data/lib/opencv-ffi/imgproc/geometric.rb +42 -0
  96. data/lib/opencv-ffi/imgproc/library.rb +6 -0
  97. data/lib/opencv-ffi/imgproc/misc.rb +39 -0
  98. data/lib/opencv-ffi/version.rb +3 -0
  99. data/opencv-ffi.gemspec +26 -0
  100. data/test/core/test_draw.rb +46 -0
  101. data/test/core/test_operations.rb +135 -0
  102. data/test/core/test_size.rb +14 -0
  103. data/test/core/test_text.rb +52 -0
  104. data/test/ext/test_eigen.rb +105 -0
  105. data/test/ext/test_opensurf.rb +35 -0
  106. data/test/ext/test_sift.rb +26 -0
  107. data/test/ext/test_vector_math.rb +85 -0
  108. data/test/features2d/test_surf.rb +63 -0
  109. data/test/imgproc/test_goodfeatures.rb +18 -0
  110. data/test/setup.rb +65 -0
  111. data/test/test_calib3d.rb +38 -0
  112. data/test/test_core.rb +26 -0
  113. data/test/test_ext.rb +8 -0
  114. data/test/test_features2d.rb +9 -0
  115. data/test/test_files/images/IMG_7088.JPG +0 -0
  116. data/test/test_files/images/IMG_7088_small.JPG +0 -0
  117. data/test/test_files/images/IMG_7089.JPG +0 -0
  118. data/test/test_highgui.rb +26 -0
  119. data/test/test_imgproc.rb +35 -0
  120. data/test/test_wrappers.rb +8 -0
  121. data/test/wrappers/core/test_draw.rb +41 -0
  122. data/test/wrappers/core/test_mat.rb +40 -0
  123. data/test/wrappers/core/test_operations.rb +35 -0
  124. data/test/wrappers/core/test_types.rb +235 -0
  125. data/test/wrappers/features2d/test_image_patch.rb +108 -0
  126. data/test/wrappers/test_imgproc.rb +87 -0
  127. data/test/wrappers/test_matcher.rb +96 -0
  128. data/test/wrappers/test_star.rb +28 -0
  129. data/test/wrappers/test_surf.rb +36 -0
  130. metadata +234 -0
@@ -0,0 +1,10 @@
1
+ require '../mkrf-monkey'
2
+
3
+ Mkrf::Generator.new('libcvffi_opensurf', [ "*.cpp"]) { |g|
4
+ g.include_library 'stdc++'
5
+ raise "Can't find 'opencv_core'" unless g.include_library 'opencv_core', 'main', "#{ENV['HOME']}/usr/lib"
6
+ raise "Can't find 'opencv_imgproc'" unless g.include_library 'opencv_imgproc', 'main', "#{ENV['HOME']}/usr/lib"
7
+ g.cflags += "-I#{ENV['HOME']}/usr/include "
8
+ }
9
+
10
+
@@ -0,0 +1,92 @@
1
+ /***********************************************************
2
+ * --- OpenSURF --- *
3
+ * This library is distributed under the GNU GPL. Please *
4
+ * use the contact form at http://www.chrisevansdev.com *
5
+ * for more information. *
6
+ * *
7
+ * C. Evans, Research Into Robust Visual Features, *
8
+ * MSc University of Bristol, 2008. *
9
+ * *
10
+ ************************************************************/
11
+
12
+ #include <memory.h>
13
+
14
+ //#define RL_DEBUG // un-comment to test response layer
15
+
16
+ class ResponseLayer
17
+ {
18
+ public:
19
+
20
+ int width, height, step, filter;
21
+ float *responses;
22
+ unsigned char *laplacian;
23
+
24
+ ResponseLayer(int width, int height, int step, int filter)
25
+ {
26
+ assert(width > 0 && height > 0);
27
+
28
+ this->width = width;
29
+ this->height = height;
30
+ this->step = step;
31
+ this->filter = filter;
32
+
33
+ responses = new float[width*height];
34
+ laplacian = new unsigned char[width*height];
35
+
36
+ memset(responses,0,sizeof(float)*width*height);
37
+ memset(laplacian,0,sizeof(unsigned char)*width*height);
38
+ }
39
+
40
+ ~ResponseLayer()
41
+ {
42
+ if (responses) delete [] responses;
43
+ if (laplacian) delete [] laplacian;
44
+ }
45
+
46
+ inline unsigned char getLaplacian(unsigned int row, unsigned int column)
47
+ {
48
+ return laplacian[row * width + column];
49
+ }
50
+
51
+ inline unsigned char getLaplacian(unsigned int row, unsigned int column, ResponseLayer *src)
52
+ {
53
+ int scale = this->width / src->width;
54
+
55
+ #ifdef RL_DEBUG
56
+ assert(src->getCoords(row, column) == this->getCoords(scale * row, scale * column));
57
+ #endif
58
+
59
+ return laplacian[(scale * row) * width + (scale * column)];
60
+ }
61
+
62
+ inline float getResponse(unsigned int row, unsigned int column)
63
+ {
64
+ return responses[row * width + column];
65
+ }
66
+
67
+ inline float getResponse(unsigned int row, unsigned int column, ResponseLayer *src)
68
+ {
69
+ int scale = this->width / src->width;
70
+
71
+ #ifdef RL_DEBUG
72
+ assert(src->getCoords(row, column) == this->getCoords(scale * row, scale * column));
73
+ #endif
74
+
75
+ return responses[(scale * row) * width + (scale * column)];
76
+ }
77
+
78
+ #ifdef RL_DEBUG
79
+ std::vector<std::pair<int, int>> coords;
80
+
81
+ inline std::pair<int,int> getCoords(unsigned int row, unsigned int column)
82
+ {
83
+ return coords[row * width + column];
84
+ }
85
+
86
+ inline std::pair<int,int> getCoords(unsigned int row, unsigned int column, ResponseLayer *src)
87
+ {
88
+ int scale = this->width / src->width;
89
+ return coords[(scale * row) * width + (scale * column)];
90
+ }
91
+ #endif
92
+ };
@@ -0,0 +1,317 @@
1
+ /***********************************************************
2
+ * --- OpenSURF --- *
3
+ * This library is distributed under the GNU GPL. Please *
4
+ * use the contact form at http://www.chrisevansdev.com *
5
+ * for more information. *
6
+ * *
7
+ * C. Evans, Research Into Robust Visual Features, *
8
+ * MSc University of Bristol, 2008. *
9
+ * *
10
+ ************************************************************/
11
+
12
+ #include "utils.h"
13
+
14
+ #include "surf.h"
15
+
16
+ //-------------------------------------------------------
17
+ //! SURF priors (these need not be done at runtime)
18
+ const float pi = 3.14159f;
19
+
20
+ const double gauss25 [7][7] = {
21
+ 0.02350693969273,0.01849121369071,0.01239503121241,0.00708015417522,0.00344628101733,0.00142945847484,0.00050524879060,
22
+ 0.02169964028389,0.01706954162243,0.01144205592615,0.00653580605408,0.00318131834134,0.00131955648461,0.00046640341759,
23
+ 0.01706954162243,0.01342737701584,0.00900063997939,0.00514124713667,0.00250251364222,0.00103799989504,0.00036688592278,
24
+ 0.01144205592615,0.00900063997939,0.00603330940534,0.00344628101733,0.00167748505986,0.00069579213743,0.00024593098864,
25
+ 0.00653580605408,0.00514124713667,0.00344628101733,0.00196854695367,0.00095819467066,0.00039744277546,0.00014047800980,
26
+ 0.00318131834134,0.00250251364222,0.00167748505986,0.00095819467066,0.00046640341759,0.00019345616757,0.00006837798818,
27
+ 0.00131955648461,0.00103799989504,0.00069579213743,0.00039744277546,0.00019345616757,0.00008024231247,0.00002836202103
28
+ };
29
+
30
+ const double gauss33 [11][11] = {
31
+ 0.014614763,0.013958917,0.012162744,0.00966788,0.00701053,0.004637568,0.002798657,0.001540738,0.000773799,0.000354525,0.000148179,
32
+ 0.013958917,0.013332502,0.011616933,0.009234028,0.006695928,0.004429455,0.002673066,0.001471597,0.000739074,0.000338616,0.000141529,
33
+ 0.012162744,0.011616933,0.010122116,0.008045833,0.005834325,0.003859491,0.002329107,0.001282238,0.000643973,0.000295044,0.000123318,
34
+ 0.00966788,0.009234028,0.008045833,0.006395444,0.004637568,0.003067819,0.001851353,0.001019221,0.000511879,0.000234524,9.80224E-05,
35
+ 0.00701053,0.006695928,0.005834325,0.004637568,0.003362869,0.002224587,0.001342483,0.000739074,0.000371182,0.000170062,7.10796E-05,
36
+ 0.004637568,0.004429455,0.003859491,0.003067819,0.002224587,0.001471597,0.000888072,0.000488908,0.000245542,0.000112498,4.70202E-05,
37
+ 0.002798657,0.002673066,0.002329107,0.001851353,0.001342483,0.000888072,0.000535929,0.000295044,0.000148179,6.78899E-05,2.83755E-05,
38
+ 0.001540738,0.001471597,0.001282238,0.001019221,0.000739074,0.000488908,0.000295044,0.00016243,8.15765E-05,3.73753E-05,1.56215E-05,
39
+ 0.000773799,0.000739074,0.000643973,0.000511879,0.000371182,0.000245542,0.000148179,8.15765E-05,4.09698E-05,1.87708E-05,7.84553E-06,
40
+ 0.000354525,0.000338616,0.000295044,0.000234524,0.000170062,0.000112498,6.78899E-05,3.73753E-05,1.87708E-05,8.60008E-06,3.59452E-06,
41
+ 0.000148179,0.000141529,0.000123318,9.80224E-05,7.10796E-05,4.70202E-05,2.83755E-05,1.56215E-05,7.84553E-06,3.59452E-06,1.50238E-06
42
+ };
43
+
44
+ //-------------------------------------------------------
45
+
46
+ //-------------------------------------------------------
47
+
48
+ //! Constructor
49
+ Surf::Surf(IplImage *img, IpVec &ipts)
50
+ : ipts(ipts)
51
+ {
52
+ this->img = img;
53
+ }
54
+
55
+ //-------------------------------------------------------
56
+
57
+ //! Describe all features in the supplied vector
58
+ void Surf::getDescriptors(bool upright)
59
+ {
60
+ // Check there are Ipoints to be described
61
+ if (!ipts.size()) return;
62
+
63
+ // Get the size of the vector for fixed loop bounds
64
+ int ipts_size = (int)ipts.size();
65
+
66
+ if (upright)
67
+ {
68
+ // U-SURF loop just gets descriptors
69
+ for (int i = 0; i < ipts_size; ++i)
70
+ {
71
+ // Set the Ipoint to be described
72
+ index = i;
73
+
74
+ // Extract upright (i.e. not rotation invariant) descriptors
75
+ getDescriptor(true);
76
+ }
77
+ }
78
+ else
79
+ {
80
+ // Main SURF-64 loop assigns orientations and gets descriptors
81
+ for (int i = 0; i < ipts_size; ++i)
82
+ {
83
+ // Set the Ipoint to be described
84
+ index = i;
85
+
86
+ // Assign Orientations and extract rotation invariant descriptors
87
+ getOrientation();
88
+ getDescriptor(false);
89
+ }
90
+ }
91
+ }
92
+
93
+ //-------------------------------------------------------
94
+
95
+ //! Assign the supplied Ipoint an orientation
96
+ void Surf::getOrientation()
97
+ {
98
+ Ipoint *ipt = &ipts[index];
99
+ float gauss = 0.f, scale = ipt->scale;
100
+ const int s = fRound(scale), r = fRound(ipt->y), c = fRound(ipt->x);
101
+ std::vector<float> resX(109), resY(109), Ang(109);
102
+ const int id[] = {6,5,4,3,2,1,0,1,2,3,4,5,6};
103
+
104
+ int idx = 0;
105
+ // calculate haar responses for points within radius of 6*scale
106
+ for(int i = -6; i <= 6; ++i)
107
+ {
108
+ for(int j = -6; j <= 6; ++j)
109
+ {
110
+ if(i*i + j*j < 36)
111
+ {
112
+ gauss = static_cast<float>(gauss25[id[i+6]][id[j+6]]);
113
+ resX[idx] = gauss * haarX(r+j*s, c+i*s, 4*s);
114
+ resY[idx] = gauss * haarY(r+j*s, c+i*s, 4*s);
115
+ Ang[idx] = getAngle(resX[idx], resY[idx]);
116
+ ++idx;
117
+ }
118
+ }
119
+ }
120
+
121
+ // calculate the dominant direction
122
+ float sumX=0.f, sumY=0.f;
123
+ float max=0.f, orientation = 0.f;
124
+ float ang1=0.f, ang2=0.f;
125
+
126
+ // loop slides pi/3 window around feature point
127
+ for(ang1 = 0; ang1 < 2*pi; ang1+=0.15f) {
128
+ ang2 = ( ang1+pi/3.0f > 2*pi ? ang1-5.0f*pi/3.0f : ang1+pi/3.0f);
129
+ sumX = sumY = 0.f;
130
+ for(unsigned int k = 0; k < Ang.size(); ++k)
131
+ {
132
+ // get angle from the x-axis of the sample point
133
+ const float & ang = Ang[k];
134
+
135
+ // determine whether the point is within the window
136
+ if (ang1 < ang2 && ang1 < ang && ang < ang2)
137
+ {
138
+ sumX+=resX[k];
139
+ sumY+=resY[k];
140
+ }
141
+ else if (ang2 < ang1 &&
142
+ ((ang > 0 && ang < ang2) || (ang > ang1 && ang < 2*pi) ))
143
+ {
144
+ sumX+=resX[k];
145
+ sumY+=resY[k];
146
+ }
147
+ }
148
+
149
+ // if the vector produced from this window is longer than all
150
+ // previous vectors then this forms the new dominant direction
151
+ if (sumX*sumX + sumY*sumY > max)
152
+ {
153
+ // store largest orientation
154
+ max = sumX*sumX + sumY*sumY;
155
+ orientation = getAngle(sumX, sumY);
156
+ }
157
+ }
158
+
159
+ // assign orientation of the dominant response vector
160
+ ipt->orientation = orientation;
161
+ }
162
+
163
+ //-------------------------------------------------------
164
+
165
+ //! Get the modified descriptor. See Agrawal ECCV 08
166
+ //! Modified descriptor contributed by Pablo Fernandez
167
+ void Surf::getDescriptor(bool bUpright)
168
+ {
169
+ int y, x, sample_x, sample_y, count=0;
170
+ int i = 0, ix = 0, j = 0, jx = 0, xs = 0, ys = 0;
171
+ float scale, *desc, dx, dy, mdx, mdy, co, si;
172
+ float gauss_s1 = 0.f, gauss_s2 = 0.f;
173
+ float rx = 0.f, ry = 0.f, rrx = 0.f, rry = 0.f, len = 0.f;
174
+ float cx = -0.5f, cy = 0.f; //Subregion centers for the 4x4 gaussian weighting
175
+
176
+ Ipoint *ipt = &ipts[index];
177
+ scale = ipt->scale;
178
+ x = fRound(ipt->x);
179
+ y = fRound(ipt->y);
180
+ desc = ipt->descriptor;
181
+
182
+ if (bUpright)
183
+ {
184
+ co = 1;
185
+ si = 0;
186
+ }
187
+ else
188
+ {
189
+ co = cos(ipt->orientation);
190
+ si = sin(ipt->orientation);
191
+ }
192
+
193
+ i = -8;
194
+
195
+ //Calculate descriptor for this interest point
196
+ while(i < 12)
197
+ {
198
+ j = -8;
199
+ i = i-4;
200
+
201
+ cx += 1.f;
202
+ cy = -0.5f;
203
+
204
+ while(j < 12)
205
+ {
206
+ dx=dy=mdx=mdy=0.f;
207
+ cy += 1.f;
208
+
209
+ j = j - 4;
210
+
211
+ ix = i + 5;
212
+ jx = j + 5;
213
+
214
+ xs = fRound(x + ( -jx*scale*si + ix*scale*co));
215
+ ys = fRound(y + ( jx*scale*co + ix*scale*si));
216
+
217
+ for (int k = i; k < i + 9; ++k)
218
+ {
219
+ for (int l = j; l < j + 9; ++l)
220
+ {
221
+ //Get coords of sample point on the rotated axis
222
+ sample_x = fRound(x + (-l*scale*si + k*scale*co));
223
+ sample_y = fRound(y + ( l*scale*co + k*scale*si));
224
+
225
+ //Get the gaussian weighted x and y responses
226
+ gauss_s1 = gaussian(xs-sample_x,ys-sample_y,2.5f*scale);
227
+ rx = haarX(sample_y, sample_x, 2*fRound(scale));
228
+ ry = haarY(sample_y, sample_x, 2*fRound(scale));
229
+
230
+ //Get the gaussian weighted x and y responses on rotated axis
231
+ rrx = gauss_s1*(-rx*si + ry*co);
232
+ rry = gauss_s1*(rx*co + ry*si);
233
+
234
+ dx += rrx;
235
+ dy += rry;
236
+ mdx += fabs(rrx);
237
+ mdy += fabs(rry);
238
+
239
+ }
240
+ }
241
+
242
+ //Add the values to the descriptor vector
243
+ gauss_s2 = gaussian(cx-2.0f,cy-2.0f,1.5f);
244
+
245
+ desc[count++] = dx*gauss_s2;
246
+ desc[count++] = dy*gauss_s2;
247
+ desc[count++] = mdx*gauss_s2;
248
+ desc[count++] = mdy*gauss_s2;
249
+
250
+ len += (dx*dx + dy*dy + mdx*mdx + mdy*mdy) * gauss_s2*gauss_s2;
251
+
252
+ j += 9;
253
+ }
254
+ i += 9;
255
+ }
256
+
257
+ //Convert to Unit Vector
258
+ len = sqrt(len);
259
+ for(int i = 0; i < 64; ++i)
260
+ desc[i] /= len;
261
+
262
+ }
263
+
264
+
265
+ //-------------------------------------------------------
266
+
267
+ //! Calculate the value of the 2d gaussian at x,y
268
+ inline float Surf::gaussian(int x, int y, float sig)
269
+ {
270
+ return (1.0f/(2.0f*pi*sig*sig)) * exp( -(x*x+y*y)/(2.0f*sig*sig));
271
+ }
272
+
273
+ //-------------------------------------------------------
274
+
275
+ //! Calculate the value of the 2d gaussian at x,y
276
+ inline float Surf::gaussian(float x, float y, float sig)
277
+ {
278
+ return 1.0f/(2.0f*pi*sig*sig) * exp( -(x*x+y*y)/(2.0f*sig*sig));
279
+ }
280
+
281
+ //-------------------------------------------------------
282
+
283
+ //! Calculate Haar wavelet responses in x direction
284
+ inline float Surf::haarX(int row, int column, int s)
285
+ {
286
+ return BoxIntegral(img, row-s/2, column, s, s/2)
287
+ -1 * BoxIntegral(img, row-s/2, column-s/2, s, s/2);
288
+ }
289
+
290
+ //-------------------------------------------------------
291
+
292
+ //! Calculate Haar wavelet responses in y direction
293
+ inline float Surf::haarY(int row, int column, int s)
294
+ {
295
+ return BoxIntegral(img, row, column-s/2, s/2, s)
296
+ -1 * BoxIntegral(img, row-s/2, column-s/2, s/2, s);
297
+ }
298
+
299
+ //-------------------------------------------------------
300
+
301
+ //! Get the angle from the +ve x-axis of the vector given by (X Y)
302
+ float Surf::getAngle(float X, float Y)
303
+ {
304
+ if(X > 0 && Y >= 0)
305
+ return atan(Y/X);
306
+
307
+ if(X < 0 && Y >= 0)
308
+ return pi - atan(-Y/X);
309
+
310
+ if(X < 0 && Y < 0)
311
+ return pi + atan(Y/X);
312
+
313
+ if(X > 0 && Y < 0)
314
+ return 2*pi - atan(-Y/X);
315
+
316
+ return 0;
317
+ }
@@ -0,0 +1,66 @@
1
+ /***********************************************************
2
+ * --- OpenSURF --- *
3
+ * This library is distributed under the GNU GPL. Please *
4
+ * use the contact form at http://www.chrisevansdev.com *
5
+ * for more information. *
6
+ * *
7
+ * C. Evans, Research Into Robust Visual Features, *
8
+ * MSc University of Bristol, 2008. *
9
+ * *
10
+ ************************************************************/
11
+
12
+ #ifndef SURF_H
13
+ #define SURF_H
14
+
15
+ #include <opencv2/core/core.hpp>
16
+ #include "ipoint.h"
17
+ #include "integral.h"
18
+
19
+ #include <vector>
20
+
21
+ class Surf {
22
+
23
+ public:
24
+
25
+ //! Standard Constructor (img is an integral image)
26
+ Surf(IplImage *img, std::vector<Ipoint> &ipts);
27
+
28
+ //! Describe all features in the supplied vector
29
+ void getDescriptors(bool bUpright = false);
30
+
31
+ private:
32
+
33
+ //---------------- Private Functions -----------------//
34
+
35
+ //! Assign the current Ipoint an orientation
36
+ void getOrientation();
37
+
38
+ //! Get the descriptor. See Agrawal ECCV 08
39
+ void getDescriptor(bool bUpright = false);
40
+
41
+ //! Calculate the value of the 2d gaussian at x,y
42
+ inline float gaussian(int x, int y, float sig);
43
+ inline float gaussian(float x, float y, float sig);
44
+
45
+ //! Calculate Haar wavelet responses in x and y directions
46
+ inline float haarX(int row, int column, int size);
47
+ inline float haarY(int row, int column, int size);
48
+
49
+ //! Get the angle from the +ve x-axis of the vector given by [X Y]
50
+ float getAngle(float X, float Y);
51
+
52
+
53
+ //---------------- Private Variables -----------------//
54
+
55
+ //! Integral image where Ipoints have been detected
56
+ IplImage *img;
57
+
58
+ //! Ipoints vector
59
+ IpVec &ipts;
60
+
61
+ //! Index of current Ipoint in the vector
62
+ int index;
63
+ };
64
+
65
+
66
+ #endif