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,64 @@
1
+ /************************************************************
2
+
3
+ cvpoint.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVPOINT_H
11
+ #define RUBY_OPENCV_CVPOINT_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVPOINT namespace cCvPoint {
16
+ #define __NAMESPACE_END_CVPOINT }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVPOINT
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_x(VALUE self);
30
+ VALUE rb_set_x(VALUE self, VALUE x);
31
+ VALUE rb_y(VALUE self);
32
+ VALUE rb_set_y(VALUE self, VALUE y);
33
+
34
+ VALUE rb_to_s(VALUE self);
35
+ VALUE rb_to_ary(VALUE self);
36
+
37
+ VALUE new_object();
38
+ VALUE new_object(CvPoint point);
39
+
40
+ __NAMESPACE_END_CVPOINT
41
+
42
+ inline CvPoint*
43
+ CVPOINT(VALUE object){
44
+ CvPoint *ptr;
45
+ Data_Get_Struct(object, CvPoint, ptr);
46
+ return ptr;
47
+ }
48
+
49
+ inline CvPoint
50
+ VALUE_TO_CVPOINT(VALUE object)
51
+ {
52
+ if (cCvPoint::rb_compatible_q(cCvPoint::rb_class(), object)) {
53
+ return cvPoint(NUM2INT(rb_funcall(object, rb_intern("x"), 0)),
54
+ NUM2INT(rb_funcall(object, rb_intern("y"), 0)));
55
+ }
56
+ else {
57
+ raise_compatible_typeerror(object, cCvPoint::rb_class());
58
+ }
59
+ throw "Should never reach here";
60
+ }
61
+
62
+ __NAMESPACE_END_OPENCV
63
+
64
+ #endif // RUBY_OPENCV_CVPOINT_H
@@ -0,0 +1,211 @@
1
+ /************************************************************
2
+
3
+ cvpoint2d32f.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvpoint2d32f.h"
11
+ /*
12
+ * Document-class: OpenCV::CvPoint2D32f
13
+ *
14
+ * This class means one point on X axis Y axis.
15
+ * X and Y takes the value of the Float. see also CvPoint
16
+ *
17
+ * C structure is here, very simple.
18
+ * typdef struct CvPoint2D32f {
19
+ * float x;
20
+ * float y;
21
+ * }
22
+ */
23
+ __NAMESPACE_BEGIN_OPENCV
24
+ __NAMESPACE_BEGIN_CVPOINT2D32F
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, "CvPoint2D32f", 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, "x", RUBY_METHOD_FUNC(rb_x), 0);
51
+ rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
52
+ rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
53
+ rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 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
+ * combatible?(obj)
63
+ *
64
+ * Return compatibility to CvPoint2D32f. Return true if object have method #x and #y.
65
+ *
66
+ * For example.
67
+ * class MyPoint2D32f
68
+ * def x
69
+ * 95.7
70
+ * end
71
+ * def y
72
+ * 70.2
73
+ * end
74
+ * end
75
+ * mp = MyPoint2D32f.new
76
+ * CvPoint2D32f.compatible?(mp) #=> true
77
+ * CvPoint2D32f.new(mp) #=> same as CvPoint2D32f(95.7, 70.2)
78
+ */
79
+ VALUE
80
+ rb_compatible_q(VALUE klass, VALUE object)
81
+ {
82
+ return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y"))) ? Qtrue : Qfalse;
83
+ }
84
+
85
+ VALUE
86
+ rb_allocate(VALUE klass)
87
+ {
88
+ CvPoint2D32f *ptr;
89
+ return Data_Make_Struct(klass, CvPoint2D32f, 0, -1, ptr);
90
+ }
91
+
92
+ /*
93
+ * call-seq:
94
+ * new
95
+ * new(obj)
96
+ * new(x, y)
97
+ *
98
+ * Create new 2D-coordinate, (x, y).
99
+ *
100
+ * new() is same as new(0.0, 0.0)
101
+ *
102
+ * new(obj) is same as new(obj.x.to_f, obj.y.to_f)
103
+ */
104
+ VALUE
105
+ rb_initialize(int argc, VALUE *argv, VALUE self)
106
+ {
107
+ CvPoint2D32f *self_ptr = CVPOINT2D32F(self);
108
+ switch (argc) {
109
+ case 0:
110
+ break;
111
+ case 1: {
112
+ CvPoint2D32f point = VALUE_TO_CVPOINT2D32F(argv[0]);
113
+ self_ptr->x = point.x;
114
+ self_ptr->y = point.y;
115
+ break;
116
+ }
117
+ case 2:
118
+ self_ptr->x = NUM2DBL(argv[0]);
119
+ self_ptr->y = NUM2DBL(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 parameter on x-axis.
130
+ */
131
+ VALUE
132
+ rb_x(VALUE self)
133
+ {
134
+ return rb_float_new(CVPOINT2D32F(self)->x);
135
+ }
136
+
137
+ /*
138
+ * call-seq:
139
+ * x = val
140
+ *
141
+ * Set x-axis parameter, return self.
142
+ */
143
+ VALUE
144
+ rb_set_x(VALUE self, VALUE x)
145
+ {
146
+ CVPOINT2D32F(self)->x = NUM2DBL(x);
147
+ return self;
148
+ }
149
+
150
+ /*
151
+ * Return parameter on y-axis.
152
+ */
153
+ VALUE
154
+ rb_y(VALUE self)
155
+ {
156
+ return rb_float_new(CVPOINT2D32F(self)->y);
157
+ }
158
+
159
+ /*
160
+ * call-seq:
161
+ * y = val
162
+ *
163
+ * Set y-axis parameter, return self.
164
+ */
165
+ VALUE
166
+ rb_set_y(VALUE self, VALUE y)
167
+ {
168
+ CVPOINT2D32F(self)->y = NUM2DBL(y);
169
+ return self;
170
+ }
171
+
172
+ /*
173
+ * call-seq:
174
+ * to_s -> "<OpenCV::CvSize2D32f:(self.x,self.y)>"
175
+ *
176
+ * Return x and y by String.
177
+ */
178
+ VALUE
179
+ rb_to_s(VALUE self)
180
+ {
181
+ const int i = 4;
182
+ VALUE str[i];
183
+ str[0] = rb_str_new2("<%s:(%g,%g)>");
184
+ str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
185
+ str[2] = rb_x(self);
186
+ str[3] = rb_y(self);
187
+ return rb_f_sprintf(i, str);
188
+ }
189
+
190
+ /*
191
+ * call-seq:
192
+ * to_ary -> [x, y]
193
+ *
194
+ * Return x and y by Array.
195
+ */
196
+ VALUE
197
+ rb_to_ary(VALUE self)
198
+ {
199
+ return rb_ary_new3(2, rb_x(self), rb_y(self));
200
+ }
201
+
202
+ VALUE
203
+ new_object(CvPoint2D32f point)
204
+ {
205
+ VALUE object = rb_allocate(rb_klass);
206
+ *CVPOINT2D32F(object) = point;
207
+ return object;
208
+ }
209
+
210
+ __NAMESPACE_END_CVPOINT2D32F
211
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,63 @@
1
+ /************************************************************
2
+
3
+ cvpoint2d32f.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVPOINT2D32F_H
11
+ #define RUBY_OPENCV_CVPOINT2D32F_H
12
+
13
+ #define __NAMESPACE_BEGIN_CVPOINT2D32F namespace cCvPoint2D32f {
14
+ #define __NAMESPACE_END_CVPOINT2D32F }
15
+
16
+ #include "opencv.h"
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVPOINT2D32F
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_x(VALUE self);
30
+ VALUE rb_set_x(VALUE self, VALUE x);
31
+ VALUE rb_y(VALUE self);
32
+ VALUE rb_set_y(VALUE self, VALUE y);
33
+
34
+ VALUE rb_to_s(VALUE self);
35
+ VALUE rb_to_ary(VALUE self);
36
+
37
+ VALUE new_object(CvPoint2D32f point);
38
+
39
+ __NAMESPACE_END_CVPOINT2D32F
40
+
41
+ inline CvPoint2D32f*
42
+ CVPOINT2D32F(VALUE object)
43
+ {
44
+ CvPoint2D32f *ptr;
45
+ Data_Get_Struct(object, CvPoint2D32f, ptr);
46
+ return ptr;
47
+ }
48
+
49
+ inline CvPoint2D32f
50
+ VALUE_TO_CVPOINT2D32F(VALUE object)
51
+ {
52
+ if (cCvPoint2D32f::rb_compatible_q(cCvPoint2D32f::rb_class(), object)) {
53
+ return cvPoint2D32f(NUM2DBL(rb_funcall(object, rb_intern("x"), 0)),
54
+ NUM2DBL(rb_funcall(object, rb_intern("y"), 0)));
55
+ }
56
+ else {
57
+ raise_compatible_typeerror(object, cCvPoint2D32f::rb_class());
58
+ }
59
+ throw "Should never reach here";
60
+ }
61
+
62
+ __NAMESPACE_END_OPENCV
63
+ #endif // RUBY_OPENCV_CVPOINT2D32F_H
@@ -0,0 +1,245 @@
1
+ /************************************************************
2
+
3
+ cvpoint3d32f.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2008 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvpoint3d32f.h"
11
+ /*
12
+ * Document-class: OpenCV::CvPoint3D32f
13
+ *
14
+ * This class means one point on X axis Y axis.
15
+ * X and Y takes the value of the Float. see also CvPoint
16
+ *
17
+ * C structure is here, very simple.
18
+ * typdef struct CvPoint3D32f {
19
+ * float x;
20
+ * float y;
21
+ * float z;
22
+ * }
23
+ */
24
+ __NAMESPACE_BEGIN_OPENCV
25
+ __NAMESPACE_BEGIN_CVPOINT3D32F
26
+
27
+ VALUE rb_klass;
28
+
29
+ VALUE
30
+ rb_class()
31
+ {
32
+ return rb_klass;
33
+ }
34
+
35
+ void
36
+ define_ruby_class()
37
+ {
38
+ if (rb_klass)
39
+ return;
40
+ /*
41
+ * opencv = rb_define_module("OpenCV");
42
+ * cvpoint2d32f = rb_define_class_under(opencv, "CvPoint2D32f", rb_cObject);
43
+ *
44
+ * note: this comment is used by rdoc.
45
+ */
46
+ VALUE opencv = rb_module_opencv();
47
+ VALUE cvpoint2d32f = cCvPoint2D32f::rb_class();
48
+ rb_klass = rb_define_class_under(opencv, "CvPoint3D32f", cvpoint2d32f);
49
+ rb_define_alloc_func(rb_klass, rb_allocate);
50
+ rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
51
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
52
+ rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
53
+ rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
54
+ rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
55
+ rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
56
+ rb_define_method(rb_klass, "z", RUBY_METHOD_FUNC(rb_z), 0);
57
+ rb_define_method(rb_klass, "z=", RUBY_METHOD_FUNC(rb_set_z), 1);
58
+
59
+ rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
60
+ rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
61
+ rb_define_alias(rb_klass, "to_a", "to_ary");
62
+ }
63
+
64
+ /*
65
+ * call-seq:
66
+ * combatible?(obj)
67
+ *
68
+ * Return compatibility to CvPoint3D32f. Return true if object have method #x and #y and #z.
69
+ *
70
+ * For example.
71
+ * class MyPoint3D32f
72
+ * def x
73
+ * 95.7
74
+ * end
75
+ * def y
76
+ * 70.2
77
+ * end
78
+ * def z
79
+ * 10.0
80
+ * end
81
+ * end
82
+ * mp = MyPoint3D32f.new
83
+ * CvPoint3D32f.compatible?(mp) #=> true
84
+ * CvPoint3D32f.new(mp) #=> same as CvPoint3D32f(95.7, 70.2)
85
+ */
86
+ VALUE
87
+ rb_compatible_q(VALUE klass, VALUE object)
88
+ {
89
+ return (rb_respond_to(object, rb_intern("x")) &&
90
+ rb_respond_to(object, rb_intern("y")) &&
91
+ rb_respond_to(object, rb_intern("z"))) ? Qtrue : Qfalse;
92
+ }
93
+
94
+ VALUE
95
+ rb_allocate(VALUE klass)
96
+ {
97
+ CvPoint3D32f *ptr;
98
+ return Data_Make_Struct(klass, CvPoint3D32f, 0, -1, ptr);
99
+ }
100
+
101
+ /*
102
+ * call-seq:
103
+ * new
104
+ * new(obj)
105
+ * new(x, y, z)
106
+ *
107
+ * Create new 3D-coordinate, (x, y, z).
108
+ *
109
+ * new() is same as new(0.0, 0.0, 0.0)
110
+ *
111
+ * new(obj) is same as new(obj.x.to_f, obj.y.to_f, obj.z.to_f)
112
+ */
113
+ VALUE
114
+ rb_initialize(int argc, VALUE *argv, VALUE self)
115
+ {
116
+ CvPoint3D32f *self_ptr = CVPOINT3D32F(self);
117
+ switch (argc) {
118
+ case 0:
119
+ break;
120
+ case 1: {
121
+ CvPoint3D32f point = VALUE_TO_CVPOINT3D32F(argv[0]);
122
+ self_ptr->x = point.x;
123
+ self_ptr->y = point.y;
124
+ self_ptr->z = point.z;
125
+ break;
126
+ }
127
+ case 3:
128
+ self_ptr->x = NUM2DBL(argv[0]);
129
+ self_ptr->y = NUM2DBL(argv[1]);
130
+ self_ptr->z = NUM2DBL(argv[2]);
131
+ break;
132
+ default:
133
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
134
+ break;
135
+ }
136
+ return self;
137
+ }
138
+
139
+ /*
140
+ * Return parameter on x-axis.
141
+ */
142
+ VALUE
143
+ rb_x(VALUE self)
144
+ {
145
+ return rb_float_new(CVPOINT2D32F(self)->x);
146
+ }
147
+
148
+ /*
149
+ * call-seq:
150
+ * x = val
151
+ *
152
+ * Set x-axis parameter, return self.
153
+ */
154
+ VALUE
155
+ rb_set_x(VALUE self, VALUE x)
156
+ {
157
+ CVPOINT2D32F(self)->x = NUM2DBL(x);
158
+ return self;
159
+ }
160
+
161
+ /*
162
+ * Return parameter on y-axis.
163
+ */
164
+ VALUE
165
+ rb_y(VALUE self)
166
+ {
167
+ return rb_float_new(CVPOINT2D32F(self)->y);
168
+ }
169
+
170
+ /*
171
+ * call-seq:
172
+ * y = val
173
+ *
174
+ * Set y-axis parameter, return self.
175
+ */
176
+ VALUE
177
+ rb_set_y(VALUE self, VALUE y)
178
+ {
179
+ CVPOINT2D32F(self)->y = NUM2DBL(y);
180
+ return self;
181
+ }
182
+
183
+ /*
184
+ * Return parameter on z-axis.
185
+ */
186
+ VALUE
187
+ rb_z(VALUE self)
188
+ {
189
+ return rb_float_new(CVPOINT3D32F(self)->z);
190
+ }
191
+
192
+ /*
193
+ * call-seq:
194
+ * z = val
195
+ *
196
+ * Set z-axis parameter, return self.
197
+ */
198
+ VALUE
199
+ rb_set_z(VALUE self, VALUE z)
200
+ {
201
+ CVPOINT3D32F(self)->z = NUM2DBL(z);
202
+ return self;
203
+ }
204
+
205
+ /*
206
+ * call-seq:
207
+ * to_s -> "<OpenCV::CvSize3D32f:(self.x,self.y,self.z)>"
208
+ *
209
+ * Return x and y by String.
210
+ */
211
+ VALUE
212
+ rb_to_s(VALUE self)
213
+ {
214
+ const int i = 5;
215
+ VALUE str[i];
216
+ str[0] = rb_str_new2("<%s:(%g,%g,%g)>");
217
+ str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
218
+ str[2] = rb_x(self);
219
+ str[3] = rb_y(self);
220
+ str[4] = rb_z(self);
221
+ return rb_f_sprintf(i, str);
222
+ }
223
+
224
+ /*
225
+ * call-seq:
226
+ * to_ary -> [x, y, z]
227
+ *
228
+ * Return x and y by Array.
229
+ */
230
+ VALUE
231
+ rb_to_ary(VALUE self)
232
+ {
233
+ return rb_ary_new3(3, rb_x(self), rb_y(self), rb_z(self));
234
+ }
235
+
236
+ VALUE
237
+ new_object(CvPoint3D32f point)
238
+ {
239
+ VALUE object = rb_allocate(rb_klass);
240
+ *CVPOINT3D32F(object) = point;
241
+ return object;
242
+ }
243
+
244
+ __NAMESPACE_END_CVPOINT3D32F
245
+ __NAMESPACE_END_OPENCV