ruby-opencv 0.0.9-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -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 +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/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/opencv.rb +12 -0
  136. data/lib/opencv/psyched_yaml.rb +22 -0
  137. data/lib/opencv/version.rb +3 -0
  138. data/ruby-opencv.gemspec +44 -0
  139. data/test/helper.rb +166 -0
  140. data/test/runner.rb +30 -0
  141. data/test/samples/airplane.jpg +0 -0
  142. data/test/samples/baboon.jpg +0 -0
  143. data/test/samples/baboon200.jpg +0 -0
  144. data/test/samples/baboon200_rotated.jpg +0 -0
  145. data/test/samples/blank0.jpg +0 -0
  146. data/test/samples/blank1.jpg +0 -0
  147. data/test/samples/blank2.jpg +0 -0
  148. data/test/samples/blank3.jpg +0 -0
  149. data/test/samples/blank4.jpg +0 -0
  150. data/test/samples/blank5.jpg +0 -0
  151. data/test/samples/blank6.jpg +0 -0
  152. data/test/samples/blank7.jpg +0 -0
  153. data/test/samples/blank8.jpg +0 -0
  154. data/test/samples/blank9.jpg +0 -0
  155. data/test/samples/cat.jpg +0 -0
  156. data/test/samples/chessboard.jpg +0 -0
  157. data/test/samples/contours.jpg +0 -0
  158. data/test/samples/fruits.jpg +0 -0
  159. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  160. data/test/samples/inpaint-mask.bmp +0 -0
  161. data/test/samples/lena-256x256.jpg +0 -0
  162. data/test/samples/lena-32x32.jpg +0 -0
  163. data/test/samples/lena-eyes.jpg +0 -0
  164. data/test/samples/lena-inpaint.jpg +0 -0
  165. data/test/samples/lena.jpg +0 -0
  166. data/test/samples/lines.jpg +0 -0
  167. data/test/samples/messy0.jpg +0 -0
  168. data/test/samples/messy1.jpg +0 -0
  169. data/test/samples/movie_sample.avi +0 -0
  170. data/test/samples/one_way_train_0000.jpg +0 -0
  171. data/test/samples/one_way_train_0001.jpg +0 -0
  172. data/test/samples/partially_blank0.jpg +0 -0
  173. data/test/samples/partially_blank1.jpg +0 -0
  174. data/test/samples/smooth0.jpg +0 -0
  175. data/test/samples/smooth1.jpg +0 -0
  176. data/test/samples/smooth2.jpg +0 -0
  177. data/test/samples/smooth3.jpg +0 -0
  178. data/test/samples/smooth4.jpg +0 -0
  179. data/test/samples/smooth5.jpg +0 -0
  180. data/test/samples/smooth6.jpg +0 -0
  181. data/test/samples/str-cv-rotated.jpg +0 -0
  182. data/test/samples/str-cv.jpg +0 -0
  183. data/test/samples/str-ov.jpg +0 -0
  184. data/test/samples/stuff.jpg +0 -0
  185. data/test/test_curve.rb +43 -0
  186. data/test/test_cvavgcomp.rb +24 -0
  187. data/test/test_cvbox2d.rb +76 -0
  188. data/test/test_cvcapture.rb +183 -0
  189. data/test/test_cvchain.rb +108 -0
  190. data/test/test_cvcircle32f.rb +41 -0
  191. data/test/test_cvconnectedcomp.rb +61 -0
  192. data/test/test_cvcontour.rb +150 -0
  193. data/test/test_cvcontourtree.rb +43 -0
  194. data/test/test_cverror.rb +50 -0
  195. data/test/test_cvfeaturetree.rb +65 -0
  196. data/test/test_cvfont.rb +58 -0
  197. data/test/test_cvhaarclassifiercascade.rb +63 -0
  198. data/test/test_cvhistogram.rb +271 -0
  199. data/test/test_cvhumoments.rb +83 -0
  200. data/test/test_cvline.rb +50 -0
  201. data/test/test_cvmat.rb +2947 -0
  202. data/test/test_cvmat_drawing.rb +349 -0
  203. data/test/test_cvmat_dxt.rb +150 -0
  204. data/test/test_cvmat_imageprocessing.rb +2025 -0
  205. data/test/test_cvmat_matching.rb +57 -0
  206. data/test/test_cvmoments.rb +180 -0
  207. data/test/test_cvpoint.rb +75 -0
  208. data/test/test_cvpoint2d32f.rb +75 -0
  209. data/test/test_cvpoint3d32f.rb +93 -0
  210. data/test/test_cvrect.rb +144 -0
  211. data/test/test_cvscalar.rb +113 -0
  212. data/test/test_cvseq.rb +295 -0
  213. data/test/test_cvsize.rb +75 -0
  214. data/test/test_cvsize2d32f.rb +75 -0
  215. data/test/test_cvslice.rb +31 -0
  216. data/test/test_cvsurfparams.rb +57 -0
  217. data/test/test_cvsurfpoint.rb +66 -0
  218. data/test/test_cvtermcriteria.rb +56 -0
  219. data/test/test_cvtwopoints.rb +40 -0
  220. data/test/test_cvvideowriter.rb +58 -0
  221. data/test/test_iplconvkernel.rb +54 -0
  222. data/test/test_iplimage.rb +236 -0
  223. data/test/test_mouseevent.rb +17 -0
  224. data/test/test_opencv.rb +324 -0
  225. data/test/test_pointset.rb +126 -0
  226. data/test/test_preliminary.rb +130 -0
  227. data/test/test_trackbar.rb +47 -0
  228. data/test/test_window.rb +115 -0
  229. metadata +386 -0
@@ -0,0 +1,74 @@
1
+ /************************************************************
2
+
3
+ cvseq.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVSEQ_H
11
+ #define RUBY_OPENCV_CVSEQ_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVSEQ namespace cCvSeq {
16
+ #define __NAMESPACE_END_CVSEQ }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVSEQ
20
+
21
+ VALUE rb_class();
22
+ void define_ruby_class();
23
+
24
+ VALUE seqblock_class(void *ptr);
25
+ void register_elem_class(CvSeq *seq, VALUE klass);
26
+ void unregister_elem_class(void *ptr);
27
+
28
+ VALUE rb_allocate(VALUE klass);
29
+
30
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
31
+ VALUE rb_total(VALUE self);
32
+ VALUE rb_empty_q(VALUE self);
33
+ VALUE rb_aref(VALUE self, VALUE index);
34
+ VALUE rb_first(VALUE self);
35
+ VALUE rb_last(VALUE self);
36
+ VALUE rb_h_prev(VALUE self);
37
+ VALUE rb_h_next(VALUE self);
38
+ VALUE rb_v_prev(VALUE self);
39
+ VALUE rb_v_next(VALUE self);
40
+ VALUE rb_push(VALUE self, VALUE args);
41
+ VALUE rb_pop(VALUE self);
42
+ VALUE rb_unshift(VALUE self, VALUE args);
43
+ VALUE rb_shift(VALUE self);
44
+ VALUE rb_each(VALUE self);
45
+ VALUE rb_each_index(VALUE self);
46
+ VALUE rb_insert(VALUE self, VALUE index, VALUE object);
47
+ VALUE rb_remove(VALUE self, VALUE index);
48
+ VALUE rb_clear(VALUE self);
49
+
50
+ VALUE new_object(CvSeq *seq, VALUE klass);
51
+ VALUE new_object(CvSeq *seq, VALUE klass, VALUE storage);
52
+ VALUE new_sequence(VALUE klass, CvSeq *seq, VALUE element_klass, VALUE storage);
53
+
54
+ __NAMESPACE_END_CVSEQ
55
+
56
+ inline CvSeq*
57
+ CVSEQ(VALUE object)
58
+ {
59
+ CvSeq *ptr;
60
+ Data_Get_Struct(object, CvSeq, ptr);
61
+ return ptr;
62
+ }
63
+
64
+ inline CvSeq*
65
+ CVSEQ_WITH_CHECK(VALUE object)
66
+ {
67
+ if (!rb_obj_is_kind_of(object, cCvSeq::rb_class()))
68
+ raise_typeerror(object, cCvSeq::rb_class());
69
+ return CVSEQ(object);
70
+ }
71
+
72
+ __NAMESPACE_END_OPENCV
73
+
74
+ #endif // RUBY_OPENCV_CVSEQ_H
@@ -0,0 +1,221 @@
1
+ /************************************************************
2
+
3
+ cvsize.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvsize.h"
11
+ /*
12
+ * Document-class: OpenCV::CvSize
13
+ *
14
+ * This class means one size on X axis Y axis.
15
+ * X and Y takes the value of the Fixnum.
16
+ *
17
+ * C structure is here, very simple.
18
+ * typdef struct CvSize {
19
+ * int width;
20
+ * int height;
21
+ * }
22
+ */
23
+ __NAMESPACE_BEGIN_OPENCV
24
+ __NAMESPACE_BEGIN_CVSIZE
25
+
26
+ VALUE rb_klass;
27
+
28
+ VALUE
29
+ rb_class()
30
+ {
31
+ return rb_klass;
32
+ }
33
+
34
+ void
35
+ define_ruby_class()
36
+ {
37
+ if (rb_klass)
38
+ return;
39
+ /*
40
+ * opencv = rb_define_module("OpenCV");
41
+ *
42
+ * note: this comment is used by rdoc.
43
+ */
44
+ VALUE opencv = rb_module_opencv();
45
+
46
+ rb_klass = rb_define_class_under(opencv, "CvSize", rb_cObject);
47
+ rb_define_alloc_func(rb_klass, rb_allocate);
48
+ rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
49
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
50
+ rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
51
+ rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
52
+ rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
53
+ rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
54
+
55
+ rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
56
+ rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
57
+ rb_define_alias(rb_klass, "to_a", "to_ary");
58
+ }
59
+
60
+ /*
61
+ * call-seq:
62
+ * compatible?(obj)
63
+ *
64
+ * Return compatibility to CvSize. Return true if object have method #width and #height.
65
+ *
66
+ * For example.
67
+ * class MySize
68
+ * def width
69
+ * 10
70
+ * end
71
+ * def height
72
+ * 20
73
+ * end
74
+ * end
75
+ * mp = MySize.new
76
+ * CvSize.compatible?(mp) #=> true
77
+ * CvSize.new(mp) #=> same as CvSize(10, 20)
78
+ */
79
+ VALUE
80
+ rb_compatible_q(VALUE klass, VALUE object)
81
+ {
82
+ return (rb_respond_to(object, rb_intern("width")) && rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
83
+ }
84
+
85
+ VALUE
86
+ rb_allocate(VALUE klass)
87
+ {
88
+ CvSize *ptr;
89
+ return Data_Make_Struct(klass, CvSize, 0, -1, ptr);
90
+ }
91
+
92
+ /*
93
+ * call-seq:
94
+ * new
95
+ * new(obj)
96
+ * new(width, height)
97
+ *
98
+ * Create new size of 2D, (width, height). It is dropped below the decimal point.
99
+ *
100
+ * new() is same as new(0, 0)
101
+ *
102
+ * new(obj) is same as new(obj.x.to_i, obj.y.to_i)
103
+ */
104
+ VALUE
105
+ rb_initialize(int argc, VALUE *argv, VALUE self)
106
+ {
107
+ CvSize *self_ptr = CVSIZE(self);
108
+ switch (argc) {
109
+ case 0:
110
+ break;
111
+ case 1: {
112
+ CvSize size = VALUE_TO_CVSIZE(argv[0]);
113
+ self_ptr->width = size.width;
114
+ self_ptr->height = size.height;
115
+ break;
116
+ }
117
+ case 2:
118
+ self_ptr->width = NUM2INT(argv[0]);
119
+ self_ptr->height = NUM2INT(argv[1]);
120
+ break;
121
+ default:
122
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
123
+ break;
124
+ }
125
+ return self;
126
+ }
127
+
128
+ /*
129
+ * Return size of x-axis.
130
+ */
131
+ VALUE
132
+ rb_width(VALUE self)
133
+ {
134
+ return INT2NUM(CVSIZE(self)->width);
135
+ }
136
+
137
+ /*
138
+ * call-seq:
139
+ * width = val
140
+ *
141
+ * Set x-axis size, return self.
142
+ * It is dropped below the decimal point.
143
+ */
144
+ VALUE
145
+ rb_set_width(VALUE self, VALUE x)
146
+ {
147
+ CVSIZE(self)->width = NUM2INT(x);
148
+ return self;
149
+ }
150
+
151
+ /*
152
+ * Return size of yaxis.
153
+ */
154
+ VALUE
155
+ rb_height(VALUE self)
156
+ {
157
+ return INT2NUM(CVSIZE(self)->height);
158
+ }
159
+
160
+ /*
161
+ * call-seq:
162
+ * height = val
163
+ *
164
+ * Set y-axis size, return self.
165
+ * It is dropped below the decimal point.
166
+ */
167
+ VALUE
168
+ rb_set_height(VALUE self, VALUE y)
169
+ {
170
+ CVSIZE(self)->height = NUM2INT(y);
171
+ return self;
172
+ }
173
+
174
+ /*
175
+ * call-seq:
176
+ * to_s -> "<OpenCV::CvSize:widthxheight>"
177
+ *
178
+ * Return width and height by String.
179
+ */
180
+ VALUE
181
+ rb_to_s(VALUE self)
182
+ {
183
+ const int i = 4;
184
+ VALUE str[i];
185
+ str[0] = rb_str_new2("<%s:%dx%d>");
186
+ str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
187
+ str[2] = rb_width(self);
188
+ str[3] = rb_height(self);
189
+ return rb_f_sprintf(i, str);
190
+ }
191
+
192
+ /*
193
+ * call-seq:
194
+ * to_ary -> [width, height]
195
+ *
196
+ * Return width and height by Array.
197
+ */
198
+ VALUE
199
+ rb_to_ary(VALUE self)
200
+ {
201
+ return rb_ary_new3(2, rb_width(self), rb_height(self));
202
+ }
203
+
204
+ VALUE
205
+ new_object()
206
+ {
207
+ VALUE object = rb_allocate(rb_klass);
208
+ *CVSIZE(object) = cvSize(0, 0);
209
+ return object;
210
+ }
211
+
212
+ VALUE
213
+ new_object(CvSize size)
214
+ {
215
+ VALUE object = rb_allocate(rb_klass);
216
+ *CVSIZE(object) = size;
217
+ return object;
218
+ }
219
+
220
+ __NAMESPACE_END_CVSIZE
221
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,65 @@
1
+ /************************************************************
2
+
3
+ cvsize.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVSIZE_H
11
+ #define RUBY_OPENCV_CVSIZE_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVSIZE namespace cCvSize {
16
+ #define __NAMESPACE_END_CVSIZE }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVSIZE
20
+
21
+ VALUE rb_class();
22
+
23
+ void define_ruby_class();
24
+
25
+ VALUE rb_compatible_q(VALUE klass, VALUE object);
26
+
27
+ VALUE rb_allocate(VALUE klass);
28
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
29
+ VALUE rb_width(VALUE self);
30
+ VALUE rb_set_width(VALUE self, VALUE width);
31
+ VALUE rb_height(VALUE self);
32
+ VALUE rb_set_height(VALUE self, VALUE height);
33
+
34
+ VALUE rb_to_s(VALUE self);
35
+ VALUE rb_to_ary(VALUE self);
36
+
37
+ VALUE new_object();
38
+ VALUE new_object(CvSize size);
39
+
40
+ __NAMESPACE_END_CVSIZE
41
+
42
+ inline CvSize*
43
+ CVSIZE(VALUE object)
44
+ {
45
+ CvSize *ptr;
46
+ Data_Get_Struct(object, CvSize, ptr);
47
+ return ptr;
48
+ }
49
+
50
+ inline CvSize
51
+ VALUE_TO_CVSIZE(VALUE object)
52
+ {
53
+ if (cCvSize::rb_compatible_q(cCvSize::rb_class(), object)) {
54
+ return cvSize(NUM2INT(rb_funcall(object, rb_intern("width"), 0)),
55
+ NUM2INT(rb_funcall(object, rb_intern("height"), 0)));
56
+ }
57
+ else {
58
+ raise_compatible_typeerror(object, cCvSize::rb_class());
59
+ }
60
+ throw "Should never reach here";
61
+ }
62
+
63
+ __NAMESPACE_END_OPENCV
64
+
65
+ #endif // RUBY_OPENCV_CVSIZE_H
@@ -0,0 +1,209 @@
1
+ /************************************************************
2
+
3
+ cvsize2d32f.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvsize2d32f.h"
11
+ /*
12
+ * Document-class: OpenCV::CvSize2D32f
13
+ *
14
+ * This class means one size on X axis Y axis.
15
+ * X and Y takes the value of the Float.
16
+ *
17
+ * C structure is here, very simple.
18
+ * typdef struct CvSize2D32f {
19
+ * float width;
20
+ * float height;
21
+ * } CvSize2D32f;
22
+ */
23
+ __NAMESPACE_BEGIN_OPENCV
24
+ __NAMESPACE_BEGIN_CVSIZE2D32F
25
+
26
+ VALUE rb_klass;
27
+
28
+ VALUE
29
+ rb_class()
30
+ {
31
+ return rb_klass;
32
+ }
33
+
34
+ void
35
+ define_ruby_class()
36
+ {
37
+ if (rb_klass)
38
+ return;
39
+ /*
40
+ * opencv = rb_define_module("OpenCV");
41
+ *
42
+ * note: this comment is used by rdoc.
43
+ */
44
+ VALUE opencv = rb_module_opencv();
45
+
46
+ rb_klass = rb_define_class_under(opencv, "CvSize2D32f", rb_cObject);
47
+ rb_define_alloc_func(rb_klass, rb_allocate);
48
+ rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
49
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
50
+ rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
51
+ rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
52
+ rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
53
+ rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
54
+ rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
55
+ rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
56
+ rb_define_alias(rb_klass, "to_a", "to_ary");
57
+ }
58
+
59
+ /*
60
+ * call-seq:
61
+ * compatible?(obj)
62
+ *
63
+ * Return compatibility to CvSize2D32f. Return true if object have method #width and #height.
64
+ *
65
+ * For example.
66
+ * class MySize
67
+ * def width
68
+ * 10.1
69
+ * end
70
+ * def height
71
+ * 20.2
72
+ * end
73
+ * end
74
+ * mp = MySize.new
75
+ * CvSize2D32f.compatible?(mp) #=> true
76
+ * CvSize2D32f.new(mp) #=> same as CvSize2D32f.new(10.1, 20.2)
77
+ */
78
+ VALUE
79
+ rb_compatible_q(VALUE klass, VALUE object)
80
+ {
81
+ return (rb_respond_to(object, rb_intern("width")) && rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
82
+ }
83
+
84
+ VALUE
85
+ rb_allocate(VALUE klass)
86
+ {
87
+ CvSize2D32f *ptr;
88
+ return Data_Make_Struct(klass, CvSize2D32f, 0, -1, ptr);
89
+ }
90
+
91
+ /*
92
+ * call-seq:
93
+ * new
94
+ * new(obj)
95
+ * new(width, height)
96
+ *
97
+ * Create new size of 2D, (width, height).
98
+ *
99
+ * new() is same as new(0.0, 0.0)
100
+ *
101
+ * new(obj) is same as new(obj.x.to_f, obj.y.to_f)
102
+ */
103
+ VALUE
104
+ rb_initialize(int argc, VALUE *argv, VALUE self)
105
+ {
106
+ CvSize2D32f *self_ptr = CVSIZE2D32F(self);
107
+ switch(argc){
108
+ case 0:
109
+ break;
110
+ case 1: {
111
+ CvSize2D32f size = VALUE_TO_CVSIZE2D32F(argv[0]);
112
+ self_ptr->width = size.width;
113
+ self_ptr->height = size.height;
114
+ break;
115
+ }
116
+ case 2:
117
+ self_ptr->width = NUM2DBL(argv[0]);
118
+ self_ptr->height = NUM2DBL(argv[1]);
119
+ break;
120
+ default:
121
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
122
+ }
123
+ return self;
124
+ }
125
+
126
+ /*
127
+ * Return size of x-axis.
128
+ */
129
+ VALUE
130
+ rb_width(VALUE self)
131
+ {
132
+ return rb_float_new(CVSIZE2D32F(self)->width);
133
+ }
134
+
135
+ /*
136
+ * call-seq:
137
+ * width = val
138
+ *
139
+ * Set x-axis size, return self.
140
+ */
141
+ VALUE
142
+ rb_set_width(VALUE self, VALUE x)
143
+ {
144
+ CVSIZE2D32F(self)->width = NUM2DBL(x);
145
+ return self;
146
+ }
147
+
148
+ /*
149
+ * Return size of yaxis.
150
+ */
151
+ VALUE
152
+ rb_height(VALUE self)
153
+ {
154
+ return rb_float_new(CVSIZE2D32F(self)->height);
155
+ }
156
+
157
+ /*
158
+ * call-seq:
159
+ * height = val
160
+ *
161
+ * Set y-axis size, return self.
162
+ */
163
+ VALUE
164
+ rb_set_height(VALUE self, VALUE y)
165
+ {
166
+ CVSIZE2D32F(self)->height = NUM2DBL(y);
167
+ return self;
168
+ }
169
+
170
+ /*
171
+ * call-seq:
172
+ * to_s -> "<OpenCV::CvSize2D32f:widthxheight>"
173
+ *
174
+ * Return width and height by String.
175
+ */
176
+ VALUE
177
+ rb_to_s(VALUE self)
178
+ {
179
+ const int i = 4;
180
+ VALUE str[i];
181
+ str[0] = rb_str_new2("<%s:%gx%g>");
182
+ str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
183
+ str[2] = rb_width(self);
184
+ str[3] = rb_height(self);
185
+ return rb_f_sprintf(i, str);
186
+ }
187
+
188
+ /*
189
+ * call-seq:
190
+ * to_ary -> [width, height]
191
+ *
192
+ * Return width and height by Array.
193
+ */
194
+ VALUE
195
+ rb_to_ary(VALUE self)
196
+ {
197
+ return rb_ary_new3(2, rb_width(self), rb_height(self));
198
+ }
199
+
200
+ VALUE
201
+ new_object(CvSize2D32f size)
202
+ {
203
+ VALUE object = rb_allocate(rb_klass);
204
+ *CVSIZE2D32F(object) = size;
205
+ return object;
206
+ }
207
+
208
+ __NAMESPACE_END_CVSIZE2D32F
209
+ __NAMESPACE_END_OPENCV