ruby-opencv 0.0.8-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. data/.gitignore +25 -0
  2. data/DEVELOPERS_NOTE.md +120 -0
  3. data/Gemfile +9 -0
  4. data/History.txt +5 -0
  5. data/License.txt +30 -0
  6. data/Manifest.txt +226 -0
  7. data/README.md +98 -0
  8. data/Rakefile +32 -0
  9. data/examples/alpha_blend.rb +21 -0
  10. data/examples/box.png +0 -0
  11. data/examples/box_in_scene.png +0 -0
  12. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  13. data/examples/contours/bitmap-contours.png +0 -0
  14. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  15. data/examples/contours/contour_retrieval_modes.rb +139 -0
  16. data/examples/contours/rotated-boxes.jpg +0 -0
  17. data/examples/convexhull.rb +47 -0
  18. data/examples/face_detect.rb +20 -0
  19. data/examples/find_obj.rb +169 -0
  20. data/examples/houghcircle.rb +22 -0
  21. data/examples/inpaint.png +0 -0
  22. data/examples/inpaint.rb +57 -0
  23. data/examples/lenna-rotated.jpg +0 -0
  24. data/examples/lenna.jpg +0 -0
  25. data/examples/match_kdtree.rb +88 -0
  26. data/examples/matching_to_many_images.rb +16 -0
  27. data/examples/matching_to_many_images/query.png +0 -0
  28. data/examples/matching_to_many_images/train/1.png +0 -0
  29. data/examples/matching_to_many_images/train/2.png +0 -0
  30. data/examples/matching_to_many_images/train/3.png +0 -0
  31. data/examples/matching_to_many_images/train/trainImages.txt +3 -0
  32. data/examples/paint.rb +70 -0
  33. data/examples/snake.rb +43 -0
  34. data/examples/stuff.jpg +0 -0
  35. data/examples/tiffany.jpg +0 -0
  36. data/ext/opencv/curve.cpp +112 -0
  37. data/ext/opencv/curve.h +34 -0
  38. data/ext/opencv/cvavgcomp.cpp +67 -0
  39. data/ext/opencv/cvavgcomp.h +39 -0
  40. data/ext/opencv/cvbox2d.cpp +197 -0
  41. data/ext/opencv/cvbox2d.h +61 -0
  42. data/ext/opencv/cvcapture.cpp +499 -0
  43. data/ext/opencv/cvcapture.h +72 -0
  44. data/ext/opencv/cvchain.cpp +233 -0
  45. data/ext/opencv/cvchain.h +46 -0
  46. data/ext/opencv/cvcircle32f.cpp +116 -0
  47. data/ext/opencv/cvcircle32f.h +52 -0
  48. data/ext/opencv/cvcondensation.cpp +282 -0
  49. data/ext/opencv/cvcondensation.h +49 -0
  50. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  51. data/ext/opencv/cvconnectedcomp.h +49 -0
  52. data/ext/opencv/cvcontour.cpp +296 -0
  53. data/ext/opencv/cvcontour.h +48 -0
  54. data/ext/opencv/cvcontourtree.cpp +91 -0
  55. data/ext/opencv/cvcontourtree.h +41 -0
  56. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  57. data/ext/opencv/cvconvexitydefect.h +42 -0
  58. data/ext/opencv/cverror.cpp +159 -0
  59. data/ext/opencv/cverror.h +28 -0
  60. data/ext/opencv/cvfeaturetree.cpp +125 -0
  61. data/ext/opencv/cvfeaturetree.h +55 -0
  62. data/ext/opencv/cvfont.cpp +208 -0
  63. data/ext/opencv/cvfont.h +64 -0
  64. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  65. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  66. data/ext/opencv/cvhistogram.cpp +546 -0
  67. data/ext/opencv/cvhistogram.h +73 -0
  68. data/ext/opencv/cvhumoments.cpp +139 -0
  69. data/ext/opencv/cvhumoments.h +51 -0
  70. data/ext/opencv/cvline.cpp +154 -0
  71. data/ext/opencv/cvline.h +54 -0
  72. data/ext/opencv/cvmat.cpp +5848 -0
  73. data/ext/opencv/cvmat.h +284 -0
  74. data/ext/opencv/cvmatnd.cpp +44 -0
  75. data/ext/opencv/cvmatnd.h +28 -0
  76. data/ext/opencv/cvmemstorage.cpp +68 -0
  77. data/ext/opencv/cvmemstorage.h +53 -0
  78. data/ext/opencv/cvmoments.cpp +287 -0
  79. data/ext/opencv/cvmoments.h +75 -0
  80. data/ext/opencv/cvpoint.cpp +228 -0
  81. data/ext/opencv/cvpoint.h +64 -0
  82. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  83. data/ext/opencv/cvpoint2d32f.h +63 -0
  84. data/ext/opencv/cvpoint3d32f.cpp +245 -0
  85. data/ext/opencv/cvpoint3d32f.h +66 -0
  86. data/ext/opencv/cvrect.cpp +333 -0
  87. data/ext/opencv/cvrect.h +79 -0
  88. data/ext/opencv/cvscalar.cpp +236 -0
  89. data/ext/opencv/cvscalar.h +71 -0
  90. data/ext/opencv/cvseq.cpp +599 -0
  91. data/ext/opencv/cvseq.h +74 -0
  92. data/ext/opencv/cvsize.cpp +221 -0
  93. data/ext/opencv/cvsize.h +65 -0
  94. data/ext/opencv/cvsize2d32f.cpp +209 -0
  95. data/ext/opencv/cvsize2d32f.h +64 -0
  96. data/ext/opencv/cvslice.cpp +120 -0
  97. data/ext/opencv/cvslice.h +61 -0
  98. data/ext/opencv/cvsparsemat.cpp +44 -0
  99. data/ext/opencv/cvsparsemat.h +28 -0
  100. data/ext/opencv/cvsurfparams.cpp +199 -0
  101. data/ext/opencv/cvsurfparams.h +58 -0
  102. data/ext/opencv/cvsurfpoint.cpp +223 -0
  103. data/ext/opencv/cvsurfpoint.h +52 -0
  104. data/ext/opencv/cvtermcriteria.cpp +192 -0
  105. data/ext/opencv/cvtermcriteria.h +71 -0
  106. data/ext/opencv/cvtwopoints.cpp +116 -0
  107. data/ext/opencv/cvtwopoints.h +51 -0
  108. data/ext/opencv/cvutils.cpp +194 -0
  109. data/ext/opencv/cvutils.h +29 -0
  110. data/ext/opencv/cvvideowriter.cpp +137 -0
  111. data/ext/opencv/cvvideowriter.h +43 -0
  112. data/ext/opencv/gui.cpp +68 -0
  113. data/ext/opencv/gui.h +30 -0
  114. data/ext/opencv/iplconvkernel.cpp +192 -0
  115. data/ext/opencv/iplconvkernel.h +71 -0
  116. data/ext/opencv/iplimage.cpp +644 -0
  117. data/ext/opencv/iplimage.h +73 -0
  118. data/ext/opencv/lib/opencv.rb +3 -0
  119. data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
  120. data/ext/opencv/lib/opencv/version.rb +3 -0
  121. data/ext/opencv/mouseevent.cpp +181 -0
  122. data/ext/opencv/mouseevent.h +56 -0
  123. data/ext/opencv/opencv.cpp +722 -0
  124. data/ext/opencv/opencv.h +400 -0
  125. data/ext/opencv/pointset.cpp +274 -0
  126. data/ext/opencv/pointset.h +68 -0
  127. data/ext/opencv/trackbar.cpp +121 -0
  128. data/ext/opencv/trackbar.h +69 -0
  129. data/ext/opencv/window.cpp +357 -0
  130. data/ext/opencv/window.h +66 -0
  131. data/extconf.rb +75 -0
  132. data/images/CvMat_sobel.png +0 -0
  133. data/images/CvMat_sub_rect.png +0 -0
  134. data/images/CvSeq_relationmap.png +0 -0
  135. data/images/face_detect_from_lena.jpg +0 -0
  136. data/lib/opencv.rb +3 -0
  137. data/lib/opencv/psyched_yaml.rb +22 -0
  138. data/lib/opencv/version.rb +3 -0
  139. data/ruby-opencv.gemspec +43 -0
  140. data/test/helper.rb +166 -0
  141. data/test/runner.rb +30 -0
  142. data/test/samples/airplane.jpg +0 -0
  143. data/test/samples/baboon.jpg +0 -0
  144. data/test/samples/baboon200.jpg +0 -0
  145. data/test/samples/baboon200_rotated.jpg +0 -0
  146. data/test/samples/blank0.jpg +0 -0
  147. data/test/samples/blank1.jpg +0 -0
  148. data/test/samples/blank2.jpg +0 -0
  149. data/test/samples/blank3.jpg +0 -0
  150. data/test/samples/blank4.jpg +0 -0
  151. data/test/samples/blank5.jpg +0 -0
  152. data/test/samples/blank6.jpg +0 -0
  153. data/test/samples/blank7.jpg +0 -0
  154. data/test/samples/blank8.jpg +0 -0
  155. data/test/samples/blank9.jpg +0 -0
  156. data/test/samples/cat.jpg +0 -0
  157. data/test/samples/chessboard.jpg +0 -0
  158. data/test/samples/contours.jpg +0 -0
  159. data/test/samples/fruits.jpg +0 -0
  160. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  161. data/test/samples/inpaint-mask.bmp +0 -0
  162. data/test/samples/lena-256x256.jpg +0 -0
  163. data/test/samples/lena-32x32.jpg +0 -0
  164. data/test/samples/lena-eyes.jpg +0 -0
  165. data/test/samples/lena-inpaint.jpg +0 -0
  166. data/test/samples/lena.jpg +0 -0
  167. data/test/samples/lines.jpg +0 -0
  168. data/test/samples/messy0.jpg +0 -0
  169. data/test/samples/messy1.jpg +0 -0
  170. data/test/samples/movie_sample.avi +0 -0
  171. data/test/samples/one_way_train_0000.jpg +0 -0
  172. data/test/samples/one_way_train_0001.jpg +0 -0
  173. data/test/samples/partially_blank0.jpg +0 -0
  174. data/test/samples/partially_blank1.jpg +0 -0
  175. data/test/samples/smooth0.jpg +0 -0
  176. data/test/samples/smooth1.jpg +0 -0
  177. data/test/samples/smooth2.jpg +0 -0
  178. data/test/samples/smooth3.jpg +0 -0
  179. data/test/samples/smooth4.jpg +0 -0
  180. data/test/samples/smooth5.jpg +0 -0
  181. data/test/samples/smooth6.jpg +0 -0
  182. data/test/samples/str-cv-rotated.jpg +0 -0
  183. data/test/samples/str-cv.jpg +0 -0
  184. data/test/samples/str-ov.jpg +0 -0
  185. data/test/samples/stuff.jpg +0 -0
  186. data/test/test_curve.rb +43 -0
  187. data/test/test_cvavgcomp.rb +24 -0
  188. data/test/test_cvbox2d.rb +76 -0
  189. data/test/test_cvcapture.rb +183 -0
  190. data/test/test_cvchain.rb +108 -0
  191. data/test/test_cvcircle32f.rb +41 -0
  192. data/test/test_cvconnectedcomp.rb +61 -0
  193. data/test/test_cvcontour.rb +150 -0
  194. data/test/test_cvcontourtree.rb +43 -0
  195. data/test/test_cverror.rb +50 -0
  196. data/test/test_cvfeaturetree.rb +65 -0
  197. data/test/test_cvfont.rb +58 -0
  198. data/test/test_cvhaarclassifiercascade.rb +63 -0
  199. data/test/test_cvhistogram.rb +271 -0
  200. data/test/test_cvhumoments.rb +83 -0
  201. data/test/test_cvline.rb +50 -0
  202. data/test/test_cvmat.rb +2947 -0
  203. data/test/test_cvmat_drawing.rb +349 -0
  204. data/test/test_cvmat_dxt.rb +150 -0
  205. data/test/test_cvmat_imageprocessing.rb +2025 -0
  206. data/test/test_cvmat_matching.rb +57 -0
  207. data/test/test_cvmoments.rb +180 -0
  208. data/test/test_cvpoint.rb +75 -0
  209. data/test/test_cvpoint2d32f.rb +75 -0
  210. data/test/test_cvpoint3d32f.rb +93 -0
  211. data/test/test_cvrect.rb +144 -0
  212. data/test/test_cvscalar.rb +113 -0
  213. data/test/test_cvseq.rb +295 -0
  214. data/test/test_cvsize.rb +75 -0
  215. data/test/test_cvsize2d32f.rb +75 -0
  216. data/test/test_cvslice.rb +31 -0
  217. data/test/test_cvsurfparams.rb +57 -0
  218. data/test/test_cvsurfpoint.rb +66 -0
  219. data/test/test_cvtermcriteria.rb +56 -0
  220. data/test/test_cvtwopoints.rb +40 -0
  221. data/test/test_cvvideowriter.rb +58 -0
  222. data/test/test_iplconvkernel.rb +54 -0
  223. data/test/test_iplimage.rb +236 -0
  224. data/test/test_mouseevent.rb +17 -0
  225. data/test/test_opencv.rb +324 -0
  226. data/test/test_pointset.rb +126 -0
  227. data/test/test_preliminary.rb +130 -0
  228. data/test/test_trackbar.rb +47 -0
  229. data/test/test_window.rb +115 -0
  230. metadata +414 -0
@@ -0,0 +1,39 @@
1
+ /************************************************************
2
+
3
+ cvhaarclassifiercascade.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
11
+ #define RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
12
+
13
+ #define __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE namespace cCvHaarClassifierCascade {
14
+ #define __NAMESPACE_END_CVHAARCLASSIFERCASCADE }
15
+
16
+ #include "opencv.h"
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
20
+
21
+ VALUE rb_class();
22
+
23
+ void define_ruby_class();
24
+
25
+ VALUE rb_allocate(VALUE klass);
26
+
27
+ VALUE rb_load(VALUE klass, VALUE path);
28
+ VALUE rb_detect_objects(int argc, VALUE *argv, VALUE self);
29
+
30
+ __NAMESPACE_END_CVHAARCLASSIFERCASCADE
31
+ inline CvHaarClassifierCascade*
32
+ CVHAARCLASSIFIERCASCADE(VALUE object) {
33
+ CvHaarClassifierCascade *ptr;
34
+ Data_Get_Struct(object, CvHaarClassifierCascade, ptr);
35
+ return ptr;
36
+ }
37
+ __NAMESPACE_END_OPENCV
38
+
39
+ #endif // RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
@@ -0,0 +1,546 @@
1
+ /************************************************************
2
+
3
+ cvhistogram.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2008 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvhistogram.h"
11
+ /*
12
+ * Document-class: OpenCV::CvHistogram
13
+ *
14
+ * Muti-dimensional histogram.
15
+ */
16
+ __NAMESPACE_BEGIN_OPENCV
17
+ __NAMESPACE_BEGIN_CVHISTOGRAM
18
+
19
+ VALUE rb_klass;
20
+
21
+ VALUE
22
+ rb_class()
23
+ {
24
+ return rb_klass;
25
+ }
26
+
27
+ void
28
+ define_ruby_class()
29
+ {
30
+ if (rb_klass)
31
+ return;
32
+ /*
33
+ * opencv = rb_define_module("OpenCV");
34
+ *
35
+ * note: this comment is used by rdoc.
36
+ */
37
+ VALUE opencv = rb_module_opencv();
38
+ rb_klass = rb_define_class_under(opencv, "CvHistogram", rb_cObject);
39
+
40
+ rb_define_alloc_func(rb_klass, rb_allocate);
41
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
42
+ rb_define_method(rb_klass, "is_uniform?", RUBY_METHOD_FUNC(rb_is_uniform), 0);
43
+ rb_define_method(rb_klass, "is_sparse?", RUBY_METHOD_FUNC(rb_is_sparse), 0);
44
+ rb_define_method(rb_klass, "has_range?", RUBY_METHOD_FUNC(rb_has_range), 0);
45
+ rb_define_method(rb_klass, "dims", RUBY_METHOD_FUNC(rb_dims), 0);
46
+ rb_define_method(rb_klass, "calc_hist", RUBY_METHOD_FUNC(rb_calc_hist), -1);
47
+ rb_define_method(rb_klass, "calc_hist!", RUBY_METHOD_FUNC(rb_calc_hist_bang), -1);
48
+ rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), -2);
49
+ rb_define_alias(rb_klass, "query_hist_value", "[]");
50
+ rb_define_method(rb_klass, "min_max_value", RUBY_METHOD_FUNC(rb_min_max_value), 0);
51
+ rb_define_method(rb_klass, "copy_hist", RUBY_METHOD_FUNC(rb_copy_hist), 0);
52
+
53
+ rb_define_method(rb_klass, "clear_hist", RUBY_METHOD_FUNC(rb_clear_hist), 0);
54
+ rb_define_alias(rb_klass, "clear", "clear_hist");
55
+ rb_define_method(rb_klass, "clear_hist!", RUBY_METHOD_FUNC(rb_clear_hist_bang), 0);
56
+ rb_define_alias(rb_klass, "clear!", "clear_hist!");
57
+
58
+ rb_define_method(rb_klass, "normalize_hist", RUBY_METHOD_FUNC(rb_normalize_hist), 1);
59
+ rb_define_alias(rb_klass, "normalize", "normalize_hist");
60
+ rb_define_method(rb_klass, "normalize_hist!", RUBY_METHOD_FUNC(rb_normalize_hist_bang), 1);
61
+ rb_define_alias(rb_klass, "normalize!", "normalize_hist!");
62
+
63
+ rb_define_method(rb_klass, "thresh_hist", RUBY_METHOD_FUNC(rb_thresh_hist), 1);
64
+ rb_define_alias(rb_klass, "thresh", "thresh_hist");
65
+ rb_define_method(rb_klass, "thresh_hist!", RUBY_METHOD_FUNC(rb_thresh_hist_bang), 1);
66
+ rb_define_alias(rb_klass, "thresh!", "thresh_hist!");
67
+
68
+ rb_define_method(rb_klass, "set_hist_bin_ranges", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges), -1);
69
+ rb_define_method(rb_klass, "set_hist_bin_ranges!", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges_bang), -1);
70
+
71
+ rb_define_method(rb_klass, "calc_back_project", RUBY_METHOD_FUNC(rb_calc_back_project), 1);
72
+ rb_define_method(rb_klass, "calc_back_project_patch", RUBY_METHOD_FUNC(rb_calc_back_project_patch), 4);
73
+
74
+ rb_define_singleton_method(rb_klass, "calc_prob_density", RUBY_METHOD_FUNC(rb_calc_prob_density), -1);
75
+ rb_define_singleton_method(rb_klass, "compare_hist", RUBY_METHOD_FUNC(rb_compare_hist), 3);
76
+ }
77
+
78
+ void
79
+ release_hist(void* ptr)
80
+ {
81
+ if (ptr) {
82
+ try {
83
+ cvReleaseHist((CvHistogram**)&ptr);
84
+ }
85
+ catch (cv::Exception& e) {
86
+ raise_cverror(e);
87
+ }
88
+ }
89
+ }
90
+
91
+ VALUE
92
+ rb_allocate(VALUE klass)
93
+ {
94
+ CvHistogram* ptr = NULL;
95
+ return Data_Wrap_Struct(klass, 0, release_hist, ptr);
96
+ }
97
+
98
+ float*
99
+ ary2fltptr(VALUE ary, float* buff)
100
+ {
101
+ Check_Type(ary, T_ARRAY);
102
+ int size = RARRAY_LEN(ary);
103
+ VALUE* ary_ptr = RARRAY_PTR(ary);
104
+ for (int i = 0; i < size; ++i) {
105
+ buff[i] = NUM2DBL(ary_ptr[i]);
106
+ }
107
+ return buff;
108
+ }
109
+
110
+ int*
111
+ ary2intptr(VALUE ary, int* buff)
112
+ {
113
+ Check_Type(ary, T_ARRAY);
114
+ int size = RARRAY_LEN(ary);
115
+ VALUE* ary_ptr = RARRAY_PTR(ary);
116
+ for (int i = 0; i < size; ++i) {
117
+ buff[i] = NUM2INT(ary_ptr[i]);
118
+ }
119
+ return buff;
120
+ }
121
+
122
+ VALUE
123
+ rb_initialize(int argc, VALUE *argv, VALUE self)
124
+ {
125
+ VALUE _dims, _sizes, _type, _ranges, _uniform;
126
+ int uniform;
127
+ int* sizes;
128
+ float** ranges = NULL;
129
+
130
+ rb_scan_args(argc, argv, "32", &_dims, &_sizes, &_type, &_ranges, &_uniform);
131
+ int sizes_len = RARRAY_LEN(_sizes);
132
+ sizes = ALLOCA_N(int, sizes_len);
133
+
134
+ if (NIL_P(_ranges)) {
135
+ sizes = ary2intptr(_sizes, sizes);
136
+ ranges = NULL;
137
+ }
138
+ else {
139
+ ranges = ALLOCA_N(float*, sizes_len);
140
+ VALUE* range_ptr = RARRAY_PTR(_ranges);
141
+ int i;
142
+ for (i = 0; i < sizes_len; i++) {
143
+ sizes[i] = NUM2INT(RARRAY_PTR(_sizes)[i]);
144
+ ranges[i] = ary2fltptr(range_ptr[i], ALLOCA_N(float, 2));
145
+ }
146
+ }
147
+ uniform = TRUE_OR_FALSE(_uniform, 1);
148
+
149
+ try {
150
+ DATA_PTR(self) = cvCreateHist(NUM2INT(_dims), sizes, NUM2INT(_type), ranges, uniform);
151
+ }
152
+ catch (cv::Exception& e) {
153
+ raise_cverror(e);
154
+ }
155
+
156
+ return self;
157
+ }
158
+
159
+ /*
160
+ * call-seq:
161
+ * is_uniform? -> true or false
162
+ *
163
+ */
164
+ VALUE
165
+ rb_is_uniform(VALUE self)
166
+ {
167
+ return CV_IS_UNIFORM_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
168
+ }
169
+
170
+ /*
171
+ * call-seq:
172
+ * is_sparse? -> true or false
173
+ *
174
+ */
175
+ VALUE
176
+ rb_is_sparse(VALUE self)
177
+ {
178
+ return CV_IS_SPARSE_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
179
+ }
180
+
181
+ /*
182
+ * call-seq:
183
+ * has_range? -> true or false
184
+ */
185
+ VALUE
186
+ rb_has_range(VALUE self)
187
+ {
188
+ return CV_HIST_HAS_RANGES(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
189
+ }
190
+
191
+ VALUE
192
+ rb_calc_hist(int argc, VALUE* argv, VALUE self)
193
+ {
194
+ return rb_calc_hist_bang(argc, argv, rb_copy_hist(self));
195
+ }
196
+
197
+ VALUE
198
+ rb_calc_hist_bang(int argc, VALUE* argv, VALUE self)
199
+ {
200
+ VALUE images, accumulate, mask;
201
+ rb_scan_args(argc, argv, "12", &images, &accumulate, &mask);
202
+ Check_Type(images, T_ARRAY);
203
+ int num_images = RARRAY_LEN(images);
204
+ IplImage** img = ALLOCA_N(IplImage*, num_images);
205
+ VALUE* images_ptr = RARRAY_PTR(images);
206
+ for (int i = 0; i < num_images; i++) {
207
+ img[i] = IPLIMAGE_WITH_CHECK(images_ptr[i]);
208
+ }
209
+ CvMat* m = NIL_P(mask) ? NULL : CVMAT_WITH_CHECK(mask);
210
+ try {
211
+ cvCalcHist(img, CVHISTOGRAM(self), TRUE_OR_FALSE(accumulate, 0), m);
212
+ }
213
+ catch (cv::Exception& e) {
214
+ raise_cverror(e);
215
+ }
216
+
217
+ return self;
218
+ }
219
+
220
+ /*
221
+ * call-seq:
222
+ * [<i>idx1[,idx2]...</i>]
223
+ */
224
+ VALUE
225
+ rb_aref(VALUE self, VALUE args)
226
+ {
227
+ int num_idx = RARRAY_LEN(args);
228
+ int* idx = ALLOCA_N(int, num_idx);
229
+ VALUE* args_ptr = RARRAY_PTR(args);
230
+ for (int i = 0; i < num_idx; i++) {
231
+ idx[i] = NUM2INT(args_ptr[i]);
232
+ }
233
+
234
+ float value = 0.0;
235
+ CvHistogram* self_ptr = CVHISTOGRAM(self);
236
+ try {
237
+ switch (num_idx) {
238
+ case 1:
239
+ value = cvQueryHistValue_1D(self_ptr, idx[0]);
240
+ break;
241
+ case 2:
242
+ value = cvQueryHistValue_2D(self_ptr, idx[0], idx[1]);
243
+ break;
244
+ case 3:
245
+ value = cvQueryHistValue_3D(self_ptr, idx[0], idx[1], idx[2]);
246
+ break;
247
+ default:
248
+ value = cvQueryHistValue_nD(self_ptr, idx);
249
+ break;
250
+ }
251
+ }
252
+ catch (cv::Exception& e) {
253
+ raise_cverror(e);
254
+ }
255
+
256
+ return rb_float_new((double)value);
257
+ }
258
+
259
+ VALUE
260
+ rb_min_max_value(VALUE self)
261
+ {
262
+ CvHistogram* self_ptr = CVHISTOGRAM(self);
263
+ int dims = 0;
264
+ float min_value = 0.0, max_value = 0.0;
265
+ int *min_idx = NULL;
266
+ int *max_idx = NULL;
267
+ try {
268
+ dims = cvGetDims(self_ptr->bins, NULL);
269
+ min_idx = ALLOCA_N(int, dims);
270
+ max_idx = ALLOCA_N(int, dims);
271
+ cvGetMinMaxHistValue(CVHISTOGRAM(self), &min_value, &max_value, min_idx, max_idx);
272
+ }
273
+ catch (cv::Exception& e) {
274
+ raise_cverror(e);
275
+ }
276
+
277
+ VALUE _min_idx = rb_ary_new2(dims);
278
+ VALUE _max_idx = rb_ary_new2(dims);
279
+ for (int i = 0; i < dims; i++) {
280
+ rb_ary_store(_min_idx, i, INT2NUM(min_idx[i]));
281
+ rb_ary_store(_max_idx, i, INT2NUM(max_idx[i]));
282
+ }
283
+
284
+ return rb_ary_new3(4, rb_float_new((double)min_value), rb_float_new((double)max_value),
285
+ _min_idx, _max_idx);
286
+ }
287
+
288
+ /*
289
+ * call-seq:
290
+ * dims -> [int[,int...]]
291
+ */
292
+ VALUE
293
+ rb_dims(VALUE self)
294
+ {
295
+ VALUE _sizes = Qnil;
296
+ int size[CV_MAX_DIM];
297
+ int dims = 0;
298
+ try {
299
+ dims = cvGetDims(CVHISTOGRAM(self)->bins, size);
300
+ _sizes = rb_ary_new2(dims);
301
+ for (int i = 0; i < dims; ++i) {
302
+ rb_ary_store(_sizes, i, INT2NUM(size[i]));
303
+ }
304
+ }
305
+ catch (cv::Exception& e) {
306
+ raise_cverror(e);
307
+ }
308
+ return rb_assoc_new(INT2NUM(dims), _sizes);
309
+ }
310
+
311
+ /*
312
+ * call-seq:
313
+ * copy_hist -> cvhist
314
+ *
315
+ * Clone histogram.
316
+ */
317
+ VALUE
318
+ rb_copy_hist(VALUE self)
319
+ {
320
+ CvHistogram* hist = NULL;
321
+ try {
322
+ cvCopyHist(CVHISTOGRAM(self), &hist);
323
+ }
324
+ catch (cv::Exception& e) {
325
+ raise_cverror(e);
326
+ }
327
+ return Data_Wrap_Struct(rb_klass, 0, release_hist, hist);
328
+ }
329
+
330
+ /*
331
+ * call-seq:
332
+ * clear_hist
333
+ */
334
+ VALUE
335
+ rb_clear_hist(VALUE self)
336
+ {
337
+ return rb_clear_hist_bang(rb_copy_hist(self));
338
+ }
339
+
340
+ /*
341
+ * call-seq:
342
+ * clear_hist!
343
+ *
344
+ * Sets all histogram bins to 0 in case of dense histogram and removes all histogram bins in case of sparse array.
345
+ */
346
+ VALUE
347
+ rb_clear_hist_bang(VALUE self)
348
+ {
349
+ try {
350
+ cvClearHist(CVHISTOGRAM(self));
351
+ }
352
+ catch (cv::Exception& e) {
353
+ raise_cverror(e);
354
+ }
355
+ return self;
356
+ }
357
+
358
+ /*
359
+ * call-seq:
360
+ * normalize(<i>factor</i>) -> cvhist
361
+ *
362
+ * Return normalized the histogram bins by scaling them, such that the sum of the bins becomes equal to <i>factor</i>.
363
+ */
364
+ VALUE
365
+ rb_normalize_hist(VALUE self, VALUE factor)
366
+ {
367
+ return rb_normalize_hist_bang(rb_copy_hist(self), factor);
368
+ }
369
+
370
+ /*
371
+ * call-seq:
372
+ * normalize!(<i>factor</i>) -> self
373
+ *
374
+ * normalizes the histogram bins by scaling them, such that the sum of the bins becomes equal to <i>factor</i>.
375
+ */
376
+ VALUE
377
+ rb_normalize_hist_bang(VALUE self, VALUE factor)
378
+ {
379
+ try {
380
+ cvNormalizeHist(CVHISTOGRAM(self), NUM2DBL(factor));
381
+ }
382
+ catch (cv::Exception& e) {
383
+ raise_cverror(e);
384
+ }
385
+ return self;
386
+ }
387
+
388
+ /*
389
+ * call-seq:
390
+ * thresh_hist(<i>threshold</i>) -> cvhist
391
+ *
392
+ * Return cleared histogram bins that are below the specified threshold.
393
+ */
394
+ VALUE
395
+ rb_thresh_hist(VALUE self, VALUE threshold)
396
+ {
397
+ return rb_thresh_hist_bang(rb_copy_hist(self), threshold);
398
+ }
399
+
400
+ /*
401
+ * call-seq:
402
+ * thresh_hist!(<i>threshold</i>) -> self
403
+ *
404
+ * Cleares histogram bins that are below the specified threshold.
405
+ */
406
+ VALUE
407
+ rb_thresh_hist_bang(VALUE self, VALUE threshold)
408
+ {
409
+ try {
410
+ cvThreshHist(CVHISTOGRAM(self), NUM2DBL(threshold));
411
+ }
412
+ catch (cv::Exception& e) {
413
+ raise_cverror(e);
414
+ }
415
+ return self;
416
+ }
417
+
418
+ VALUE
419
+ rb_set_hist_bin_ranges(int argc, VALUE* argv, VALUE self)
420
+ {
421
+ return rb_set_hist_bin_ranges_bang(argc, argv, rb_copy_hist(self));
422
+ }
423
+
424
+ VALUE
425
+ rb_set_hist_bin_ranges_bang(int argc, VALUE* argv, VALUE self)
426
+ {
427
+ VALUE _ranges, _uniform;
428
+ rb_scan_args(argc, argv, "11", &_ranges, &_uniform);
429
+ Check_Type(_ranges, T_ARRAY);
430
+
431
+ int ranges_size = RARRAY_LEN(_ranges);
432
+ float** ranges = ALLOCA_N(float*, ranges_size);
433
+ VALUE* range_ptr = RARRAY_PTR(_ranges);
434
+ for (int i = 0; i < ranges_size; ++i) {
435
+ ranges[i] = ary2fltptr(range_ptr[i], ALLOCA_N(float, 2));
436
+ }
437
+ int uniform = TRUE_OR_FALSE(_uniform, 1);
438
+
439
+ try {
440
+ cvSetHistBinRanges(CVHISTOGRAM(self), ranges, uniform);
441
+ }
442
+ catch (cv::Exception& e) {
443
+ raise_cverror(e);
444
+ }
445
+
446
+ return self;
447
+ }
448
+
449
+ VALUE
450
+ rb_calc_back_project(VALUE self, VALUE image)
451
+ {
452
+ Check_Type(image, T_ARRAY);
453
+ int num_images = RARRAY_LEN(image);
454
+ if (num_images == 0) {
455
+ return Qnil;
456
+ }
457
+
458
+ IplImage** img = ALLOCA_N(IplImage*, num_images);
459
+ VALUE* image_ptr = RARRAY_PTR(image);
460
+ for (int i = 0; i < num_images; ++i) {
461
+ img[i] = IPLIMAGE_WITH_CHECK(image_ptr[i]);
462
+ }
463
+
464
+ CvSize size;
465
+ size.width = img[0]->width;
466
+ size.height = img[0]->height;
467
+ VALUE back_project = cCvMat::new_mat_kind_object(size, image_ptr[0]);
468
+ try {
469
+ cvCalcBackProject(img, CVARR(back_project), CVHISTOGRAM(self));
470
+ }
471
+ catch (cv::Exception& e) {
472
+ raise_cverror(e);
473
+ }
474
+
475
+ return back_project;
476
+ }
477
+
478
+ VALUE
479
+ rb_calc_back_project_patch(VALUE self, VALUE image, VALUE patch_size, VALUE method, VALUE factor)
480
+ {
481
+ Check_Type(image, T_ARRAY);
482
+ int num_images = RARRAY_LEN(image);
483
+ if (num_images == 0) {
484
+ return Qnil;
485
+ }
486
+
487
+ IplImage** img = ALLOCA_N(IplImage*, num_images);
488
+ VALUE* image_ptr = RARRAY_PTR(image);
489
+ for (int i = 0; i < num_images; ++i) {
490
+ img[i] = IPLIMAGE_WITH_CHECK(image_ptr[i]);
491
+ }
492
+
493
+ CvSize patchsize = VALUE_TO_CVSIZE(patch_size);
494
+ CvSize dst_size;
495
+ dst_size.width = img[0]->width - patchsize.width + 1;
496
+ dst_size.height = img[0]->height - patchsize.height + 1;
497
+
498
+ VALUE dst = cCvMat::new_mat_kind_object(dst_size, image_ptr[0], CV_32F, 1);
499
+ try {
500
+ cvCalcBackProjectPatch(img, CVARR(dst), patchsize, CVHISTOGRAM(self),
501
+ NUM2INT(method), NUM2DBL(factor));
502
+ }
503
+ catch (cv::Exception& e) {
504
+ raise_cverror(e);
505
+ }
506
+
507
+ return dst;
508
+ }
509
+
510
+ VALUE
511
+ rb_compare_hist(VALUE self, VALUE hist1, VALUE hist2, VALUE method)
512
+ {
513
+ double result = 0;
514
+ try {
515
+ result = cvCompareHist(CVHISTOGRAM_WITH_CHECK(hist1), CVHISTOGRAM_WITH_CHECK(hist2),
516
+ NUM2INT(method));
517
+ }
518
+ catch (cv::Exception& e) {
519
+ raise_cverror(e);
520
+ }
521
+
522
+ return rb_float_new(result);
523
+ }
524
+
525
+ VALUE
526
+ rb_calc_prob_density(int argc, VALUE* argv, VALUE self)
527
+ {
528
+ VALUE hist1, hist2, scale;
529
+ rb_scan_args(argc, argv, "21", &hist1, &hist2, &scale);
530
+ double s = NIL_P(scale) ? 255 : NUM2DBL(scale);
531
+
532
+ CvHistogram* hist1_ptr = CVHISTOGRAM_WITH_CHECK(hist1);
533
+ VALUE dst_hist = rb_allocate(rb_klass);
534
+ try {
535
+ cvCopyHist(hist1_ptr, (CvHistogram**)&(DATA_PTR(dst_hist)));
536
+ cvCalcProbDensity(hist1_ptr, CVHISTOGRAM_WITH_CHECK(hist2), CVHISTOGRAM(dst_hist), s);
537
+ }
538
+ catch (cv::Exception& e) {
539
+ raise_cverror(e);
540
+ }
541
+
542
+ return dst_hist;
543
+ }
544
+
545
+ __NAMESPACE_END_CVHISTOGRAM
546
+ __NAMESPACE_END_OPENCV