ruby-opencv 0.0.10-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +26 -0
  3. data/DEVELOPERS_NOTE.md +137 -0
  4. data/Gemfile +8 -0
  5. data/History.txt +5 -0
  6. data/License.txt +30 -0
  7. data/Manifest.txt +227 -0
  8. data/README.md +98 -0
  9. data/Rakefile +90 -0
  10. data/config.yml +7 -0
  11. data/examples/alpha_blend.rb +21 -0
  12. data/examples/box.png +0 -0
  13. data/examples/box_in_scene.png +0 -0
  14. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  15. data/examples/contours/bitmap-contours.png +0 -0
  16. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  17. data/examples/contours/contour_retrieval_modes.rb +139 -0
  18. data/examples/contours/rotated-boxes.jpg +0 -0
  19. data/examples/convexhull.rb +47 -0
  20. data/examples/face_detect.rb +20 -0
  21. data/examples/find_obj.rb +169 -0
  22. data/examples/houghcircle.rb +22 -0
  23. data/examples/inpaint.png +0 -0
  24. data/examples/inpaint.rb +57 -0
  25. data/examples/lenna-rotated.jpg +0 -0
  26. data/examples/lenna.jpg +0 -0
  27. data/examples/match_kdtree.rb +88 -0
  28. data/examples/matching_to_many_images.rb +16 -0
  29. data/examples/matching_to_many_images/query.png +0 -0
  30. data/examples/matching_to_many_images/train/1.png +0 -0
  31. data/examples/matching_to_many_images/train/2.png +0 -0
  32. data/examples/matching_to_many_images/train/3.png +0 -0
  33. data/examples/matching_to_many_images/train/trainImages.txt +3 -0
  34. data/examples/paint.rb +70 -0
  35. data/examples/snake.rb +43 -0
  36. data/examples/stuff.jpg +0 -0
  37. data/examples/tiffany.jpg +0 -0
  38. data/ext/opencv/curve.cpp +112 -0
  39. data/ext/opencv/curve.h +34 -0
  40. data/ext/opencv/cvavgcomp.cpp +67 -0
  41. data/ext/opencv/cvavgcomp.h +39 -0
  42. data/ext/opencv/cvbox2d.cpp +197 -0
  43. data/ext/opencv/cvbox2d.h +61 -0
  44. data/ext/opencv/cvcapture.cpp +506 -0
  45. data/ext/opencv/cvcapture.h +72 -0
  46. data/ext/opencv/cvchain.cpp +233 -0
  47. data/ext/opencv/cvchain.h +46 -0
  48. data/ext/opencv/cvcircle32f.cpp +116 -0
  49. data/ext/opencv/cvcircle32f.h +52 -0
  50. data/ext/opencv/cvcondensation.cpp +282 -0
  51. data/ext/opencv/cvcondensation.h +49 -0
  52. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  53. data/ext/opencv/cvconnectedcomp.h +49 -0
  54. data/ext/opencv/cvcontour.cpp +296 -0
  55. data/ext/opencv/cvcontour.h +48 -0
  56. data/ext/opencv/cvcontourtree.cpp +91 -0
  57. data/ext/opencv/cvcontourtree.h +41 -0
  58. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  59. data/ext/opencv/cvconvexitydefect.h +42 -0
  60. data/ext/opencv/cverror.cpp +159 -0
  61. data/ext/opencv/cverror.h +28 -0
  62. data/ext/opencv/cvfeaturetree.cpp +125 -0
  63. data/ext/opencv/cvfeaturetree.h +55 -0
  64. data/ext/opencv/cvfont.cpp +208 -0
  65. data/ext/opencv/cvfont.h +64 -0
  66. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  67. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  68. data/ext/opencv/cvhistogram.cpp +546 -0
  69. data/ext/opencv/cvhistogram.h +73 -0
  70. data/ext/opencv/cvhumoments.cpp +139 -0
  71. data/ext/opencv/cvhumoments.h +51 -0
  72. data/ext/opencv/cvline.cpp +154 -0
  73. data/ext/opencv/cvline.h +54 -0
  74. data/ext/opencv/cvmat.cpp +5848 -0
  75. data/ext/opencv/cvmat.h +284 -0
  76. data/ext/opencv/cvmatnd.cpp +44 -0
  77. data/ext/opencv/cvmatnd.h +28 -0
  78. data/ext/opencv/cvmemstorage.cpp +68 -0
  79. data/ext/opencv/cvmemstorage.h +53 -0
  80. data/ext/opencv/cvmoments.cpp +287 -0
  81. data/ext/opencv/cvmoments.h +75 -0
  82. data/ext/opencv/cvpoint.cpp +228 -0
  83. data/ext/opencv/cvpoint.h +64 -0
  84. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  85. data/ext/opencv/cvpoint2d32f.h +63 -0
  86. data/ext/opencv/cvpoint3d32f.cpp +245 -0
  87. data/ext/opencv/cvpoint3d32f.h +66 -0
  88. data/ext/opencv/cvrect.cpp +333 -0
  89. data/ext/opencv/cvrect.h +79 -0
  90. data/ext/opencv/cvscalar.cpp +236 -0
  91. data/ext/opencv/cvscalar.h +71 -0
  92. data/ext/opencv/cvseq.cpp +599 -0
  93. data/ext/opencv/cvseq.h +74 -0
  94. data/ext/opencv/cvsize.cpp +221 -0
  95. data/ext/opencv/cvsize.h +65 -0
  96. data/ext/opencv/cvsize2d32f.cpp +209 -0
  97. data/ext/opencv/cvsize2d32f.h +64 -0
  98. data/ext/opencv/cvslice.cpp +120 -0
  99. data/ext/opencv/cvslice.h +61 -0
  100. data/ext/opencv/cvsparsemat.cpp +44 -0
  101. data/ext/opencv/cvsparsemat.h +28 -0
  102. data/ext/opencv/cvsurfparams.cpp +199 -0
  103. data/ext/opencv/cvsurfparams.h +58 -0
  104. data/ext/opencv/cvsurfpoint.cpp +223 -0
  105. data/ext/opencv/cvsurfpoint.h +52 -0
  106. data/ext/opencv/cvtermcriteria.cpp +192 -0
  107. data/ext/opencv/cvtermcriteria.h +71 -0
  108. data/ext/opencv/cvtwopoints.cpp +116 -0
  109. data/ext/opencv/cvtwopoints.h +51 -0
  110. data/ext/opencv/cvutils.cpp +192 -0
  111. data/ext/opencv/cvutils.h +30 -0
  112. data/ext/opencv/cvvideowriter.cpp +137 -0
  113. data/ext/opencv/cvvideowriter.h +43 -0
  114. data/ext/opencv/extconf.rb +83 -0
  115. data/ext/opencv/gui.cpp +68 -0
  116. data/ext/opencv/gui.h +30 -0
  117. data/ext/opencv/iplconvkernel.cpp +192 -0
  118. data/ext/opencv/iplconvkernel.h +71 -0
  119. data/ext/opencv/iplimage.cpp +644 -0
  120. data/ext/opencv/iplimage.h +73 -0
  121. data/ext/opencv/mouseevent.cpp +181 -0
  122. data/ext/opencv/mouseevent.h +56 -0
  123. data/ext/opencv/opencv.cpp +727 -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/images/CvMat_sobel.png +0 -0
  132. data/images/CvMat_sub_rect.png +0 -0
  133. data/images/CvSeq_relationmap.png +0 -0
  134. data/images/face_detect_from_lena.jpg +0 -0
  135. data/lib/1.9/opencv.so +0 -0
  136. data/lib/2.0/opencv.so +0 -0
  137. data/lib/opencv.rb +12 -0
  138. data/lib/opencv/psyched_yaml.rb +22 -0
  139. data/lib/opencv/version.rb +3 -0
  140. data/ruby-opencv.gemspec +44 -0
  141. data/test/helper.rb +166 -0
  142. data/test/runner.rb +30 -0
  143. data/test/samples/airplane.jpg +0 -0
  144. data/test/samples/baboon.jpg +0 -0
  145. data/test/samples/baboon200.jpg +0 -0
  146. data/test/samples/baboon200_rotated.jpg +0 -0
  147. data/test/samples/blank0.jpg +0 -0
  148. data/test/samples/blank1.jpg +0 -0
  149. data/test/samples/blank2.jpg +0 -0
  150. data/test/samples/blank3.jpg +0 -0
  151. data/test/samples/blank4.jpg +0 -0
  152. data/test/samples/blank5.jpg +0 -0
  153. data/test/samples/blank6.jpg +0 -0
  154. data/test/samples/blank7.jpg +0 -0
  155. data/test/samples/blank8.jpg +0 -0
  156. data/test/samples/blank9.jpg +0 -0
  157. data/test/samples/cat.jpg +0 -0
  158. data/test/samples/chessboard.jpg +0 -0
  159. data/test/samples/contours.jpg +0 -0
  160. data/test/samples/fruits.jpg +0 -0
  161. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  162. data/test/samples/inpaint-mask.bmp +0 -0
  163. data/test/samples/lena-256x256.jpg +0 -0
  164. data/test/samples/lena-32x32.jpg +0 -0
  165. data/test/samples/lena-eyes.jpg +0 -0
  166. data/test/samples/lena-inpaint.jpg +0 -0
  167. data/test/samples/lena.jpg +0 -0
  168. data/test/samples/lines.jpg +0 -0
  169. data/test/samples/messy0.jpg +0 -0
  170. data/test/samples/messy1.jpg +0 -0
  171. data/test/samples/movie_sample.avi +0 -0
  172. data/test/samples/one_way_train_0000.jpg +0 -0
  173. data/test/samples/one_way_train_0001.jpg +0 -0
  174. data/test/samples/partially_blank0.jpg +0 -0
  175. data/test/samples/partially_blank1.jpg +0 -0
  176. data/test/samples/smooth0.jpg +0 -0
  177. data/test/samples/smooth1.jpg +0 -0
  178. data/test/samples/smooth2.jpg +0 -0
  179. data/test/samples/smooth3.jpg +0 -0
  180. data/test/samples/smooth4.jpg +0 -0
  181. data/test/samples/smooth5.jpg +0 -0
  182. data/test/samples/smooth6.jpg +0 -0
  183. data/test/samples/str-cv-rotated.jpg +0 -0
  184. data/test/samples/str-cv.jpg +0 -0
  185. data/test/samples/str-ov.jpg +0 -0
  186. data/test/samples/stuff.jpg +0 -0
  187. data/test/test_curve.rb +43 -0
  188. data/test/test_cvavgcomp.rb +24 -0
  189. data/test/test_cvbox2d.rb +76 -0
  190. data/test/test_cvcapture.rb +183 -0
  191. data/test/test_cvchain.rb +108 -0
  192. data/test/test_cvcircle32f.rb +41 -0
  193. data/test/test_cvconnectedcomp.rb +61 -0
  194. data/test/test_cvcontour.rb +150 -0
  195. data/test/test_cvcontourtree.rb +43 -0
  196. data/test/test_cverror.rb +50 -0
  197. data/test/test_cvfeaturetree.rb +65 -0
  198. data/test/test_cvfont.rb +58 -0
  199. data/test/test_cvhaarclassifiercascade.rb +63 -0
  200. data/test/test_cvhistogram.rb +271 -0
  201. data/test/test_cvhumoments.rb +83 -0
  202. data/test/test_cvline.rb +50 -0
  203. data/test/test_cvmat.rb +2947 -0
  204. data/test/test_cvmat_drawing.rb +349 -0
  205. data/test/test_cvmat_dxt.rb +150 -0
  206. data/test/test_cvmat_imageprocessing.rb +2015 -0
  207. data/test/test_cvmat_matching.rb +57 -0
  208. data/test/test_cvmoments.rb +180 -0
  209. data/test/test_cvpoint.rb +75 -0
  210. data/test/test_cvpoint2d32f.rb +75 -0
  211. data/test/test_cvpoint3d32f.rb +93 -0
  212. data/test/test_cvrect.rb +144 -0
  213. data/test/test_cvscalar.rb +113 -0
  214. data/test/test_cvseq.rb +295 -0
  215. data/test/test_cvsize.rb +75 -0
  216. data/test/test_cvsize2d32f.rb +75 -0
  217. data/test/test_cvslice.rb +31 -0
  218. data/test/test_cvsurfparams.rb +57 -0
  219. data/test/test_cvsurfpoint.rb +66 -0
  220. data/test/test_cvtermcriteria.rb +56 -0
  221. data/test/test_cvtwopoints.rb +40 -0
  222. data/test/test_cvvideowriter.rb +58 -0
  223. data/test/test_iplconvkernel.rb +54 -0
  224. data/test/test_iplimage.rb +236 -0
  225. data/test/test_mouseevent.rb +17 -0
  226. data/test/test_opencv.rb +329 -0
  227. data/test/test_pointset.rb +126 -0
  228. data/test/test_preliminary.rb +130 -0
  229. data/test/test_trackbar.rb +47 -0
  230. data/test/test_window.rb +115 -0
  231. metadata +386 -0
@@ -0,0 +1,52 @@
1
+ /************************************************************
2
+
3
+ cvcircle32f.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVCIRCLE32F_H
11
+ #define RUBY_OPENCV_CVCIRCLE32F_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVCIRCLE32F namespace cCvCircle32f {
16
+ #define __NAMESPACE_END_CVCIRCLE32F }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+
20
+ typedef struct CvCircle32f {
21
+ CvPoint2D32f center;
22
+ float radius;
23
+ } CvCircle32f;
24
+
25
+ __NAMESPACE_BEGIN_CVCIRCLE32F
26
+
27
+ VALUE rb_class();
28
+
29
+ void define_ruby_class();
30
+
31
+ VALUE rb_allocate(VALUE klass);
32
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
33
+ VALUE rb_center(VALUE self);
34
+ VALUE rb_radius(VALUE self);
35
+ VALUE rb_aref(VALUE self, VALUE index);
36
+ VALUE rb_to_ary(VALUE self);
37
+
38
+ VALUE new_object(CvCircle32f circle32f);
39
+
40
+ __NAMESPACE_END_CVCIRCLE32F
41
+
42
+ inline CvCircle32f*
43
+ CVCIRCLE32F(VALUE object)
44
+ {
45
+ CvCircle32f *ptr;
46
+ Data_Get_Struct(object, CvCircle32f, ptr);
47
+ return ptr;
48
+ }
49
+
50
+ __NAMESPACE_END_OPENCV
51
+
52
+ #endif // RUBY_OPENCV_CVCIRCLE32F_H
@@ -0,0 +1,282 @@
1
+ /************************************************************
2
+
3
+ cvcondensation.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvcondensation.h"
11
+ /*
12
+ * Document-class: OpenCV::CvConDensation
13
+ *
14
+ */
15
+ __NAMESPACE_BEGIN_OPENCV
16
+ __NAMESPACE_BEGIN_CVCONDENSATION
17
+
18
+ VALUE rb_klass;
19
+
20
+ VALUE
21
+ rb_class()
22
+ {
23
+ return rb_klass;
24
+ }
25
+
26
+ void
27
+ define_ruby_class()
28
+ {
29
+ if (rb_klass)
30
+ return;
31
+ /*
32
+ * opencv = rb_define_module("OpenCV");
33
+ *
34
+ * note: this comment is used by rdoc.
35
+ */
36
+ VALUE opencv = rb_module_opencv();
37
+ rb_klass = rb_define_class_under(opencv, "CvConDensation", rb_cObject);
38
+ rb_define_method(rb_klass, "dp", RUBY_METHOD_FUNC(rb_dp), 0);
39
+ rb_define_method(rb_klass, "mp", RUBY_METHOD_FUNC(rb_mp), 0);
40
+ rb_define_method(rb_klass, "dynamic_matrix", RUBY_METHOD_FUNC(rb_dynamic_matrix), 0);
41
+ rb_define_method(rb_klass, "confidence", RUBY_METHOD_FUNC(rb_confidence), 0);
42
+ rb_define_method(rb_klass, "cumulative", RUBY_METHOD_FUNC(rb_cumulative), 0);
43
+ rb_define_method(rb_klass, "state", RUBY_METHOD_FUNC(rb_state), 0);
44
+ rb_define_method(rb_klass, "samples_num", RUBY_METHOD_FUNC(rb_samples_num), 0);
45
+ rb_define_method(rb_klass, "init_sample_set", RUBY_METHOD_FUNC(rb_init_sample_set), 2);
46
+ rb_define_method(rb_klass, "update_by_time", RUBY_METHOD_FUNC(rb_update_by_time), 0);
47
+ rb_define_alias(rb_klass, "update", "update_by_time");
48
+ rb_define_method(rb_klass, "each_sample", RUBY_METHOD_FUNC(rb_each_sample), 0);
49
+ rb_define_method(rb_klass, "calculate_confidence", RUBY_METHOD_FUNC(rb_calculate_confidence), 0);
50
+ }
51
+
52
+ /*
53
+ * call-seq:
54
+ * dp -> int
55
+ *
56
+ * Return dimension of state vector
57
+ */
58
+ VALUE
59
+ rb_dp(VALUE self)
60
+ {
61
+ return INT2NUM(CVCONDENSATION(self)->DP);
62
+ }
63
+
64
+ /*
65
+ * call-seq:
66
+ * mp -> int
67
+ *
68
+ * Return demension of measurement vector.
69
+ */
70
+ VALUE
71
+ rb_mp(VALUE self)
72
+ {
73
+ return INT2NUM(CVCONDENSATION(self)->MP);
74
+ }
75
+
76
+ /*
77
+ * call-seq:
78
+ * dynamic_matrix -> mat
79
+ *
80
+ * Return matrix of the linear Dynamics system.
81
+ */
82
+ VALUE
83
+ rb_dynamic_matrix(VALUE self)
84
+ {
85
+ CvConDensation *cd = CVCONDENSATION(self);
86
+ CvMat* mat = NULL;
87
+ try {
88
+ mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, cd->DP, CV_MAKETYPE(CV_32F, 1), cd->DynamMatr);
89
+ }
90
+ catch (cv::Exception& e) {
91
+ raise_cverror(e);
92
+ }
93
+ return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
94
+ }
95
+
96
+ /*
97
+ * call-seq:
98
+ * confidence -> mat
99
+ *
100
+ * Return confidence for each sample.
101
+ */
102
+ VALUE
103
+ rb_confidence(VALUE self)
104
+ {
105
+ CvConDensation *cd = CVCONDENSATION(self);
106
+ CvMat* mat = NULL;
107
+ try {
108
+ mat = cvInitMatHeader(ALLOC(CvMat), cd->SamplesNum, 1, CV_MAKETYPE(CV_32F, 1), cd->flConfidence);
109
+ }
110
+ catch (cv::Exception& e) {
111
+ raise_cverror(e);
112
+ }
113
+ return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
114
+ }
115
+
116
+ /*
117
+ * call-seq:
118
+ * cumulative -> mat
119
+ *
120
+ * Return cumulative confidence.
121
+ */
122
+ VALUE
123
+ rb_cumulative(VALUE self)
124
+ {
125
+ CvConDensation *cd = CVCONDENSATION(self);
126
+ CvMat* mat = NULL;
127
+ try {
128
+ mat = cvInitMatHeader(ALLOC(CvMat), cd->SamplesNum, 1, CV_MAKETYPE(CV_32F, 1), cd->flCumulative);
129
+ }
130
+ catch (cv::Exception& e) {
131
+ raise_cverror(e);
132
+ }
133
+ return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
134
+ }
135
+
136
+ /*
137
+ * call-seq:
138
+ * state -> mat
139
+ *
140
+ * Return vector of state
141
+ */
142
+ VALUE
143
+ rb_state(VALUE self)
144
+ {
145
+ CvConDensation *cd = CVCONDENSATION(self);
146
+ CvMat* mat = NULL;
147
+ try {
148
+ mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, 1, CV_MAKETYPE(CV_32F, 1), cd->State);
149
+ }
150
+ catch (cv::Exception& e) {
151
+ raise_cverror(e);
152
+ }
153
+ return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
154
+ }
155
+
156
+ /*
157
+ * call-seq:
158
+ * samples_num -> int
159
+ *
160
+ * Return number of the samples
161
+ */
162
+ VALUE
163
+ rb_samples_num(VALUE self)
164
+ {
165
+ return INT2NUM(CVCONDENSATION(self)->SamplesNum);
166
+ }
167
+
168
+ /*
169
+ * call-seq:
170
+ * init_sample_set(upper, lower)
171
+ *
172
+ * Initializes sample set for ConDensation algorithm.
173
+ * Fills the samples with values within specified(lower to upper) ranges.
174
+ */
175
+ VALUE
176
+ rb_init_sample_set(VALUE self, VALUE lower, VALUE upper)
177
+ {
178
+ CvConDensation *cd = CVCONDENSATION(self);
179
+ CvMat *lower_bound = CVMAT_WITH_CHECK(lower), *upper_bound = CVMAT_WITH_CHECK(upper), lb_stub, ub_stub;
180
+ int lower_type = lower_bound->type, upper_type = lower_bound->type;
181
+ try {
182
+ if (lower_type != CV_32FC1 || lower_bound->cols != 1) {
183
+ if (CV_MAT_DEPTH(lower_type) == CV_32F) {
184
+ lower_bound = cvReshape(lower_bound, &lb_stub, 1, lower_bound->rows * lower_bound->cols);
185
+ }
186
+ else {
187
+ lower = cCvMat::new_object(cvSize(lower_bound->rows * lower_bound->cols, 1), CV_MAKETYPE(CV_32S, 1));
188
+ cvConvertScale(lower_bound, CVARR(lower));
189
+ lower_bound = CVMAT(lower);
190
+ }
191
+ }
192
+ if (upper_type != CV_32FC1 || upper_bound->cols != 1) {
193
+ if (CV_MAT_DEPTH(upper_type) == CV_32F) {
194
+ upper_bound = cvReshape(upper_bound, &ub_stub, 1, upper_bound->rows * upper_bound->cols);
195
+ }
196
+ else {
197
+ upper = cCvMat::new_object(cvSize(upper_bound->rows * upper_bound->cols, 1), CV_MAKETYPE(CV_32F, 1));
198
+ cvConvertScale(upper_bound, CVARR(upper));
199
+ upper_bound = CVMAT(upper);
200
+ }
201
+ }
202
+ if (lower_bound->rows != cd->DP || upper_bound->rows != cd->DP) {
203
+ rb_raise(rb_eTypeError, "sample matrix step unmatch.");
204
+ }
205
+ cvConDensInitSampleSet(cd, lower_bound, upper_bound);
206
+ }
207
+ catch (cv::Exception& e) {
208
+ raise_cverror(e);
209
+ }
210
+ return self;
211
+ }
212
+
213
+ /*
214
+ * call-seq:
215
+ * update_by_time
216
+ *
217
+ * Estimates subsequent model state.
218
+ */
219
+ VALUE
220
+ rb_update_by_time(VALUE self)
221
+ {
222
+ try {
223
+ cvConDensUpdateByTime(CVCONDENSATION(self));
224
+ }
225
+ catch (cv::Exception& e) {
226
+ raise_cverror(e);
227
+ }
228
+ return self;
229
+ }
230
+
231
+ /*
232
+ * call-seq:
233
+ * each_sample {|mat| ... }
234
+ *
235
+ * Evaluate each sample by given block.
236
+ */
237
+ VALUE
238
+ rb_each_sample(VALUE self)
239
+ {
240
+ CvConDensation *cd = CVCONDENSATION(self);
241
+ if (rb_block_given_p()) {
242
+ try {
243
+ for (int i = 0; i < cd->SamplesNum; ++i) {
244
+ CvMat* mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, 1, CV_MAKETYPE(CV_32F, 1), cd->flSamples[i]);
245
+ rb_yield(DEPEND_OBJECT(cCvMat::rb_class(), mat, self));
246
+ }
247
+ }
248
+ catch (cv::Exception& e) {
249
+ raise_cverror(e);
250
+ }
251
+ }
252
+ return self;
253
+ }
254
+
255
+ /*
256
+ * call-seq:
257
+ * calculate_confidence {|value| ... }
258
+ *
259
+ * Evalute each sample by given block, then return value set to confidence.
260
+ */
261
+ VALUE
262
+ rb_calculate_confidence(VALUE self)
263
+ {
264
+ VALUE value;
265
+ CvConDensation *cd = CVCONDENSATION(self);
266
+ if (rb_block_given_p()) {
267
+ try {
268
+ for (int i = 0; i < cd->SamplesNum; ++i) {
269
+ CvMat* mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, 1, CV_MAKETYPE(CV_32F, 1), cd->flSamples[i]);
270
+ value = rb_yield(DEPEND_OBJECT(cCvMat::rb_class(), mat, self));
271
+ cd->flConfidence[i] = NUM2DBL(value);
272
+ }
273
+ }
274
+ catch (cv::Exception& e) {
275
+ raise_cverror(e);
276
+ }
277
+ }
278
+ return self;
279
+ }
280
+
281
+ __NAMESPACE_END_CVCONDENSATION
282
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,49 @@
1
+ /************************************************************
2
+
3
+ cvcondensation.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVCONDENSATION_H
11
+ #define RUBY_OPENCV_CVCONDENSATION_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVCONDENSATION namespace cCvConDensation {
16
+ #define __NAMESPACE_END_CVCONDENSATION }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVCONDENSATION
20
+
21
+ VALUE rb_class();
22
+ void define_ruby_class();
23
+
24
+ VALUE rb_dp(VALUE self);
25
+ VALUE rb_mp(VALUE self);
26
+ VALUE rb_dynamic_matrix(VALUE self);
27
+ VALUE rb_state(VALUE self);
28
+ VALUE rb_confidence(VALUE self);
29
+ VALUE rb_cumulative(VALUE self);
30
+ VALUE rb_samples_num(VALUE self);
31
+
32
+ VALUE rb_init_sample_set(VALUE self, VALUE lower, VALUE upper);
33
+ VALUE rb_update_by_time(VALUE self);
34
+ VALUE rb_each_sample(VALUE self);
35
+ VALUE rb_calculate_confidence(VALUE self);
36
+
37
+ __NAMESPACE_END_CVCONDENSATION
38
+
39
+ inline CvConDensation*
40
+ CVCONDENSATION(VALUE object)
41
+ {
42
+ CvConDensation *ptr;
43
+ Data_Get_Struct(object, CvConDensation, ptr);
44
+ return ptr;
45
+ }
46
+
47
+ __NAMESPACE_END_OPENCV
48
+
49
+ #endif // RUBY_OPENCV_CVCONDENSATION_H
@@ -0,0 +1,143 @@
1
+ /************************************************************
2
+
3
+ cvconnectedcomp.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvconnectedcomp.h"
11
+ /*
12
+ * Document-class: OpenCV::CvConnectedComp
13
+ *
14
+ * see CvMat#flood_fill
15
+ *
16
+ * C structure is here.
17
+ * typedef struct CvConnectedComp
18
+ * {
19
+ * double area;
20
+ * CvScalar value;
21
+ * CvRect rect;
22
+ * CvSeq* contour;
23
+ * } CvConnectedComp;
24
+ */
25
+ __NAMESPACE_BEGIN_OPENCV
26
+ __NAMESPACE_BEGIN_CVCONNECTEDCOMP
27
+
28
+ VALUE rb_klass;
29
+
30
+ VALUE
31
+ rb_class()
32
+ {
33
+ return rb_klass;
34
+ }
35
+
36
+ void
37
+ define_ruby_class()
38
+ {
39
+ if (rb_klass)
40
+ return;
41
+ /*
42
+ * opencv = rb_define_module("OpenCV");
43
+ *
44
+ * note: this comment is used by rdoc.
45
+ */
46
+ VALUE opencv = rb_module_opencv();
47
+
48
+ rb_klass = rb_define_class_under(opencv, "CvConnectedComp", rb_cObject);
49
+ rb_define_alloc_func(rb_klass, rb_allocate);
50
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
51
+ rb_define_method(rb_klass, "area", RUBY_METHOD_FUNC(rb_area), 0);
52
+ rb_define_method(rb_klass, "value", RUBY_METHOD_FUNC(rb_value), 0);
53
+ rb_define_method(rb_klass, "rect", RUBY_METHOD_FUNC(rb_rect), 0);
54
+ rb_define_method(rb_klass, "rect=", RUBY_METHOD_FUNC(rb_set_rect), 1);
55
+ rb_define_method(rb_klass, "contour", RUBY_METHOD_FUNC(rb_contour), 0);
56
+ }
57
+
58
+ VALUE
59
+ rb_allocate(VALUE klass)
60
+ {
61
+ CvConnectedComp *ptr;
62
+ return Data_Make_Struct(klass, CvConnectedComp, 0, -1, ptr);
63
+ }
64
+
65
+ VALUE
66
+ rb_initialize(int argc, VALUE *argv, VALUE self)
67
+ {
68
+ VALUE area, value, rect, contour;
69
+ rb_scan_args(argc, argv, "04", &area, &value, &rect, &contour);
70
+
71
+ if (!NIL_P(area))
72
+ CVCONNECTEDCOMP(self)->area = NUM2DBL(area);
73
+ if (!NIL_P(value))
74
+ CVCONNECTEDCOMP(self)->value = *CVSCALAR(value);
75
+ if (!NIL_P(rect))
76
+ CVCONNECTEDCOMP(self)->rect = *CVRECT(rect);
77
+ if (!NIL_P(contour))
78
+ CVCONNECTEDCOMP(self)->contour = CVSEQ(contour);
79
+ return self;
80
+ }
81
+
82
+ /*
83
+ * Return area of connected component.
84
+ */
85
+ VALUE
86
+ rb_area(VALUE self)
87
+ {
88
+ return rb_float_new(CVCONNECTEDCOMP(self)->area);
89
+ }
90
+
91
+ /*
92
+ * Return average color of the connected component.
93
+ */
94
+ VALUE
95
+ rb_value(VALUE self)
96
+ {
97
+ return REFER_OBJECT(cCvScalar::rb_class(), &CVCONNECTEDCOMP(self)->value, self);
98
+ }
99
+
100
+ /*
101
+ * Return ROI of the component.
102
+ */
103
+ VALUE
104
+ rb_rect(VALUE self)
105
+ {
106
+ return REFER_OBJECT(cCvRect::rb_class(), &CVCONNECTEDCOMP(self)->rect, self);
107
+ }
108
+
109
+ /*
110
+ * Set ROI of the component.
111
+ */
112
+ VALUE
113
+ rb_set_rect(VALUE self, VALUE rect)
114
+ {
115
+ CVCONNECTEDCOMP(self)->rect = VALUE_TO_CVRECT(rect);
116
+ return self;
117
+ }
118
+
119
+ /*
120
+ * Return optional component boundary
121
+ */
122
+ VALUE
123
+ rb_contour(VALUE self)
124
+ {
125
+ return REFER_OBJECT(cCvContour::rb_class(), &CVCONNECTEDCOMP(self)->contour, self);
126
+ }
127
+
128
+ VALUE
129
+ new_object()
130
+ {
131
+ return rb_allocate(rb_klass);
132
+ }
133
+
134
+ VALUE
135
+ new_object(CvConnectedComp comp)
136
+ {
137
+ VALUE object = rb_allocate(rb_klass);
138
+ *CVCONNECTEDCOMP(object) = comp;
139
+ return object;
140
+ }
141
+
142
+ __NAMESPACE_END_CVCONNECTEDCOMP
143
+ __NAMESPACE_END_OPENCV