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,67 @@
1
+ /************************************************************
2
+
3
+ cvavgcomp.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvavgcomp.h"
11
+ /*
12
+ * Document-class: OpenCV::CvAvgComp
13
+ *
14
+ * CvRect with parameter "neighbors".
15
+ * CvHaarClassifierCascade#detect_object.
16
+ *
17
+ * typedef struct CvAvgComp {
18
+ * CvRect rect;
19
+ * int neighbors;
20
+ * }
21
+ */
22
+ __NAMESPACE_BEGIN_OPENCV
23
+ __NAMESPACE_BEGIN_AVGCOMP
24
+
25
+ VALUE rb_klass;
26
+
27
+ VALUE
28
+ rb_class()
29
+ {
30
+ return rb_klass;
31
+ }
32
+
33
+ void
34
+ define_ruby_class()
35
+ {
36
+ if (rb_klass)
37
+ return;
38
+ /*
39
+ * opencv = rb_define_module("OpenCV");
40
+ * cvrect = rb_define_class_under(opencv, "CvRect", rb_cObject);
41
+ *
42
+ * note: this comment is used by rdoc.
43
+ */
44
+ VALUE opencv = rb_module_opencv(), cvrect = cCvRect::rb_class();
45
+ rb_klass = rb_define_class_under(opencv, "CvAvgComp", cvrect);
46
+ rb_define_alloc_func(rb_klass, rb_allocate);
47
+ rb_define_method(rb_klass, "neighbors", RUBY_METHOD_FUNC(rb_neighbors), 0);
48
+ }
49
+
50
+ VALUE
51
+ rb_allocate(VALUE klass)
52
+ {
53
+ CvAvgComp *ptr;
54
+ return Data_Make_Struct(klass, CvAvgComp, 0, -1, ptr);
55
+ }
56
+
57
+ /*
58
+ * Return neighbors.
59
+ */
60
+ VALUE
61
+ rb_neighbors(VALUE self)
62
+ {
63
+ return INT2NUM(CVAVGCOMP(self)->neighbors);
64
+ }
65
+
66
+ __NAMESPACE_END_AVGCOMP
67
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,39 @@
1
+ /**********************************************************************
2
+
3
+ cvavgcomp.h
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ **********************************************************************/
10
+ #ifndef RUBY_OPENCV_AVGCOMP_H
11
+ #define RUBY_OPENCV_AVGCOMP_H
12
+
13
+ #define __NAMESPACE_BEGIN_AVGCOMP namespace cCvAvgComp {
14
+ #define __NAMESPACE_END_AVGCOMP }
15
+
16
+ #include <opencv.h>
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_AVGCOMP
20
+
21
+ VALUE rb_class();
22
+
23
+ void define_ruby_class();
24
+
25
+ VALUE rb_allocate(VALUE klass);
26
+ VALUE rb_neighbors(VALUE self);
27
+
28
+ __NAMESPACE_END_AVGCOMP
29
+
30
+ inline CvAvgComp *CVAVGCOMP(VALUE object){
31
+ CvAvgComp *ptr;
32
+ Data_Get_Struct(object, CvAvgComp, ptr);
33
+ return ptr;
34
+ }
35
+
36
+ __NAMESPACE_END_OPENCV
37
+
38
+
39
+ #endif // RUBY_OPENCV_AVGCOMP_H
@@ -0,0 +1,197 @@
1
+ /************************************************************
2
+
3
+ cvbox2d.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvbox2d.h"
11
+ /*
12
+ * Document-class: OpenCV::CvBox2D
13
+ *
14
+ * C structure is here.
15
+ * typdef struct CvBox2D {
16
+ * CvPoint2D32f center; // center of the box.
17
+ * CvSize2D32f size; // box width and length
18
+ * float angle; // angle between the horizonal axis and the first side (i.e length) in radians
19
+ * } CvBox2D;
20
+ */
21
+ __NAMESPACE_BEGIN_OPENCV
22
+ __NAMESPACE_BEGIN_CVBOX2D
23
+
24
+ VALUE rb_klass;
25
+
26
+ VALUE
27
+ rb_class()
28
+ {
29
+ return rb_klass;
30
+ }
31
+
32
+ void
33
+ define_ruby_class()
34
+ {
35
+ if (rb_klass)
36
+ return;
37
+ /*
38
+ * opencv = rb_define_module("OpenCV");
39
+ *
40
+ * note: this comment is used by rdoc.
41
+ */
42
+ VALUE opencv = rb_module_opencv();
43
+ rb_klass = rb_define_class_under(opencv, "CvBox2D", rb_cObject);
44
+ rb_define_alloc_func(rb_klass, rb_allocate);
45
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
46
+ rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
47
+ rb_define_method(rb_klass, "center=", RUBY_METHOD_FUNC(rb_set_center), 1);
48
+ rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
49
+ rb_define_method(rb_klass, "size=", RUBY_METHOD_FUNC(rb_set_size), 1);
50
+ rb_define_method(rb_klass, "angle", RUBY_METHOD_FUNC(rb_angle), 0);
51
+ rb_define_method(rb_klass, "angle=", RUBY_METHOD_FUNC(rb_set_angle), 1);
52
+ rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
53
+ }
54
+
55
+ VALUE
56
+ rb_allocate(VALUE klass)
57
+ {
58
+ CvBox2D *ptr;
59
+ return Data_Make_Struct(klass, CvBox2D, 0, -1, ptr);
60
+ }
61
+
62
+ /*
63
+ * call-seq:
64
+ * CvBox2D.new(<i>[center][, size][, angle]</i>) -> cvbox2d
65
+ *
66
+ * Create a box
67
+ */
68
+ VALUE
69
+ rb_initialize(int argc, VALUE *argv, VALUE self)
70
+ {
71
+ VALUE center, size, angle;
72
+ CvBox2D* self_ptr = CVBOX2D(self);
73
+ rb_scan_args(argc, argv, "03", &center, &size, &angle);
74
+
75
+ if (!NIL_P(center)) {
76
+ self_ptr->center = VALUE_TO_CVPOINT2D32F(center);
77
+ }
78
+ if (!NIL_P(size)) {
79
+ self_ptr->size = VALUE_TO_CVSIZE2D32F(size);
80
+ self_ptr->angle = NUM2DBL(angle);
81
+ }
82
+
83
+ return self;
84
+ }
85
+
86
+ /*
87
+ * call-seq:
88
+ * center -> cvpoint2d32f
89
+ * Return center point of box as CvPoint2D32f.
90
+ */
91
+ VALUE
92
+ rb_center(VALUE self)
93
+ {
94
+ return REFER_OBJECT(cCvPoint2D32f::rb_class(), &CVBOX2D(self)->center, self);
95
+ }
96
+
97
+ /*
98
+ * call-seq:
99
+ * center = <i>value</i>
100
+ *
101
+ * Set center to <i>value</i>
102
+ */
103
+ VALUE
104
+ rb_set_center(VALUE self, VALUE value)
105
+ {
106
+ CVBOX2D(self)->center = VALUE_TO_CVPOINT2D32F(value);
107
+ return self;
108
+ }
109
+
110
+ /*
111
+ * call-seq:
112
+ * size -> cvsize2d32f
113
+ * Return size of box as CvSize2D32f.
114
+ */
115
+ VALUE
116
+ rb_size(VALUE self)
117
+ {
118
+ return REFER_OBJECT(cCvSize2D32f::rb_class(), &CVBOX2D(self)->size, self);
119
+ }
120
+
121
+ /*
122
+ * call-seq:
123
+ * size = <i>value</i>
124
+ *
125
+ * Set size to <i>value</i>
126
+ */
127
+ VALUE
128
+ rb_set_size(VALUE self, VALUE value)
129
+ {
130
+ CVBOX2D(self)->size = VALUE_TO_CVSIZE2D32F(value);
131
+ return self;
132
+ }
133
+
134
+ /*
135
+ * call-seq:
136
+ * angle -> float
137
+ *
138
+ * Return angle of box as Float.
139
+ */
140
+ VALUE
141
+ rb_angle(VALUE self)
142
+ {
143
+ return rb_float_new(CVBOX2D(self)->angle);
144
+ }
145
+
146
+ /*
147
+ * call-seq:
148
+ * angle = <i>value</i>
149
+ *
150
+ * Set angle to <i>value</i>
151
+ */
152
+ VALUE
153
+ rb_set_angle(VALUE self, VALUE value)
154
+ {
155
+ CVBOX2D(self)->angle = NUM2DBL(value);
156
+ return self;
157
+ }
158
+
159
+ /*
160
+ * call-seq:
161
+ * points -> array(include cvpoint2d32f)
162
+ * Find box vertices. Return Array contain 4 CvPoint2D32f.
163
+ */
164
+ VALUE
165
+ rb_points(VALUE self)
166
+ {
167
+ const int n = 4;
168
+ CvPoint2D32f p[n];
169
+ try {
170
+ cvBoxPoints(*CVBOX2D(self), p);
171
+ }
172
+ catch (cv::Exception& e) {
173
+ raise_cverror(e);
174
+ }
175
+ VALUE points = rb_ary_new2(n);
176
+ for (int i = 0; i < n; ++i) {
177
+ rb_ary_store(points, i, cCvPoint2D32f::new_object(p[i]));
178
+ }
179
+ return points;
180
+ }
181
+
182
+ VALUE
183
+ new_object()
184
+ {
185
+ return rb_allocate(cCvBox2D::rb_class());
186
+ }
187
+
188
+ VALUE
189
+ new_object(CvBox2D box)
190
+ {
191
+ VALUE object = rb_allocate(rb_klass);
192
+ *CVBOX2D(object) = box;
193
+ return object;
194
+ }
195
+
196
+ __NAMESPACE_END_CVBOX2D
197
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,61 @@
1
+ /************************************************************
2
+
3
+ cvbox2d.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVBOX2D_H
11
+ #define RUBY_OPENCV_CVBOX2D_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVBOX2D namespace cCvBox2D {
16
+ #define __NAMESPACE_END_CVBOX2D }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVBOX2D
20
+
21
+ VALUE rb_class();
22
+
23
+ void define_ruby_class();
24
+
25
+ VALUE rb_allocate(VALUE klass);
26
+
27
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
28
+ VALUE rb_center(VALUE self);
29
+ VALUE rb_set_center(VALUE self, VALUE value);
30
+ VALUE rb_size(VALUE self);
31
+ VALUE rb_set_size(VALUE self, VALUE value);
32
+ VALUE rb_angle(VALUE self);
33
+ VALUE rb_set_angle(VALUE self, VALUE value);
34
+ VALUE rb_points(VALUE self);
35
+
36
+ VALUE new_object();
37
+ VALUE new_object(CvBox2D box);
38
+
39
+ __NAMESPACE_END_CVBOX2D
40
+
41
+ inline CvBox2D*
42
+ CVBOX2D(VALUE object){
43
+ CvBox2D *ptr;
44
+ Data_Get_Struct(object, CvBox2D, ptr);
45
+ return ptr;
46
+ }
47
+
48
+ inline CvBox2D
49
+ VALUE_TO_CVBOX2D(VALUE object){
50
+ if (rb_obj_is_kind_of(object, cCvBox2D::rb_class())) {
51
+ return *CVBOX2D(object);
52
+ }
53
+ else {
54
+ raise_typeerror(object, cCvBox2D::rb_class());
55
+ }
56
+ throw "Should never reach here";
57
+ }
58
+
59
+ __NAMESPACE_END_OPENCV
60
+
61
+ #endif // RUBY_OPENCV_CVBOX2D_H
@@ -0,0 +1,499 @@
1
+ /************************************************************
2
+
3
+ cvcapture.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvcapture.h"
11
+ /*
12
+ * Document-class: OpenCV::CvCapture
13
+ *
14
+ * Capture image from video stream.
15
+ *
16
+ */
17
+ __NAMESPACE_BEGIN_OPENCV
18
+ __NAMESPACE_BEGIN_CVCAPTURE
19
+
20
+ VALUE rb_klass;
21
+
22
+ VALUE
23
+ rb_class()
24
+ {
25
+ return rb_klass;
26
+ }
27
+
28
+ void
29
+ define_ruby_class()
30
+ {
31
+ if (rb_klass)
32
+ return;
33
+ /*
34
+ * opencv = rb_define_module("OpenCV");
35
+ *
36
+ * note: this comment is used by rdoc.
37
+ */
38
+ VALUE opencv = rb_module_opencv();
39
+
40
+ rb_klass = rb_define_class_under(opencv, "CvCapture", rb_cData);
41
+
42
+ VALUE video_interface = rb_hash_new();
43
+ /* {:any, :mil, :vfw, :v4l, :v4l2, :fireware, :ieee1394, :dc1394, :cmu1394, :stereo,
44
+ :tyzx, :tyzx_left, :tyzx_right, :tyzx_color, :tyzx_z, :qt, :qtuicktime}: video source */
45
+ rb_define_const(rb_klass, "INTERFACE", video_interface);
46
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("any")), INT2FIX(CV_CAP_ANY));
47
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("mil")), INT2FIX(CV_CAP_MIL));
48
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("vfw")), INT2FIX(CV_CAP_VFW));
49
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l")), INT2FIX(CV_CAP_V4L));
50
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l2")), INT2FIX(CV_CAP_V4L2));
51
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("fireware")), INT2FIX(CV_CAP_FIREWARE));
52
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("ieee1394")), INT2FIX(CV_CAP_IEEE1394));
53
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("dc1394")), INT2FIX(CV_CAP_DC1394));
54
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("cmu1394")), INT2FIX(CV_CAP_CMU1394));
55
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("stereo")), INT2FIX(CV_CAP_STEREO));
56
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx")), INT2FIX(CV_CAP_TYZX));
57
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_left")), INT2FIX(CV_TYZX_LEFT));
58
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_right")), INT2FIX(CV_TYZX_RIGHT));
59
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_color")), INT2FIX(CV_TYZX_COLOR));
60
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_z")), INT2FIX(CV_TYZX_Z));
61
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("qt")), INT2FIX(CV_CAP_QT));
62
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("quicktime")), INT2FIX(CV_CAP_QT));
63
+
64
+ rb_define_singleton_method(rb_klass, "open", RUBY_METHOD_FUNC(rb_open), -1);
65
+
66
+ rb_define_method(rb_klass, "grab", RUBY_METHOD_FUNC(rb_grab), 0);
67
+ rb_define_method(rb_klass, "retrieve", RUBY_METHOD_FUNC(rb_retrieve), 0);
68
+ rb_define_method(rb_klass, "query", RUBY_METHOD_FUNC(rb_query), 0);
69
+ rb_define_method(rb_klass, "millisecond", RUBY_METHOD_FUNC(rb_get_millisecond), 0);
70
+ rb_define_method(rb_klass, "millisecond=", RUBY_METHOD_FUNC(rb_set_millisecond), 1);
71
+ rb_define_method(rb_klass, "frames", RUBY_METHOD_FUNC(rb_get_frames), 0);
72
+ rb_define_method(rb_klass, "frames=", RUBY_METHOD_FUNC(rb_set_frames), 1);
73
+ rb_define_method(rb_klass, "avi_ratio", RUBY_METHOD_FUNC(rb_get_avi_ratio), 0);
74
+ rb_define_method(rb_klass, "avi_ratio=", RUBY_METHOD_FUNC(rb_set_avi_ratio), 1);
75
+ rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_get_size), 0);
76
+ rb_define_method(rb_klass, "size=", RUBY_METHOD_FUNC(rb_set_size), 1);
77
+ rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_get_width), 0);
78
+ rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
79
+ rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_get_height), 0);
80
+ rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
81
+ rb_define_method(rb_klass, "fps", RUBY_METHOD_FUNC(rb_get_fps), 0);
82
+ rb_define_method(rb_klass, "fps=", RUBY_METHOD_FUNC(rb_set_fps), 1);
83
+ rb_define_method(rb_klass, "fourcc", RUBY_METHOD_FUNC(rb_get_fourcc), 0);
84
+ rb_define_method(rb_klass, "frame_count", RUBY_METHOD_FUNC(rb_get_frame_count), 0);
85
+ rb_define_method(rb_klass, "format", RUBY_METHOD_FUNC(rb_get_format), 0);
86
+ rb_define_method(rb_klass, "mode", RUBY_METHOD_FUNC(rb_get_mode), 0);
87
+ rb_define_method(rb_klass, "brightness", RUBY_METHOD_FUNC(rb_get_brightness), 0);
88
+ rb_define_method(rb_klass, "contrast", RUBY_METHOD_FUNC(rb_get_contrast), 0);
89
+ rb_define_method(rb_klass, "saturation", RUBY_METHOD_FUNC(rb_get_saturation), 0);
90
+ rb_define_method(rb_klass, "hue", RUBY_METHOD_FUNC(rb_get_hue), 0);
91
+ rb_define_method(rb_klass, "gain", RUBY_METHOD_FUNC(rb_get_gain), 0);
92
+ rb_define_method(rb_klass, "exposure", RUBY_METHOD_FUNC(rb_get_exposure), 0);
93
+ rb_define_method(rb_klass, "convert_rgb", RUBY_METHOD_FUNC(rb_get_convert_rgb), 0);
94
+ rb_define_method(rb_klass, "rectification", RUBY_METHOD_FUNC(rb_get_rectification), 0);
95
+ }
96
+
97
+ void
98
+ cvcapture_free(void *ptr)
99
+ {
100
+ if (ptr)
101
+ cvReleaseCapture((CvCapture**)&ptr);
102
+ }
103
+
104
+ /*
105
+ * call-seq:
106
+ * CvCapture.open(<i>[dev = -1]</i>)
107
+ *
108
+ * Reading video stream from the specified file or camera device.
109
+ * If <i>dev</i> is string (i.e "stream.avi"), reading video stream from file.
110
+ * If <i>dev</i> is number or symbol(include CvCapture::INTERFACE),
111
+ * reading video stream from camera.
112
+ * Currently two camera interfaces can be used on Windows:
113
+ * * Video for Windows(VFW)
114
+ * * Matrox Imaging Library(MIL)
115
+ * and two on Linux
116
+ * * V4L
117
+ * * FireWire(IEEE1394).
118
+ * If there is only one camera or it does not matter what camera to use <i>nil</i> may be passed.
119
+ */
120
+ VALUE
121
+ rb_open(int argc, VALUE *argv, VALUE self)
122
+ {
123
+ VALUE device;
124
+ rb_scan_args(argc, argv, "01", &device);
125
+ CvCapture *capture = 0;
126
+ try {
127
+ switch (TYPE(device)) {
128
+ case T_STRING:
129
+ capture = cvCaptureFromFile(StringValueCStr(device));
130
+ break;
131
+ case T_FIXNUM:
132
+ capture = cvCaptureFromCAM(FIX2INT(device));
133
+ break;
134
+ case T_SYMBOL: {
135
+ VALUE cap_index = rb_hash_lookup(rb_const_get(rb_class(), rb_intern("INTERFACE")), device);
136
+ if (NIL_P(cap_index))
137
+ rb_raise(rb_eArgError, "undefined interface.");
138
+ capture = cvCaptureFromCAM(NUM2INT(cap_index));
139
+ break;
140
+ }
141
+ case T_NIL:
142
+ capture = cvCaptureFromCAM(CV_CAP_ANY);
143
+ break;
144
+ }
145
+ }
146
+ catch (cv::Exception& e) {
147
+ raise_cverror(e);
148
+ }
149
+ if (!capture)
150
+ rb_raise(rb_eStandardError, "Invalid capture format.");
151
+ return Data_Wrap_Struct(rb_klass, 0, cvcapture_free, capture);
152
+ }
153
+
154
+
155
+ /*
156
+ * call-seq:
157
+ * grab -> true or false
158
+ *
159
+ * Grabbed frame is stored internally. To grab frame
160
+ * <i>fast</i> that is important for syncronization in case of reading from
161
+ * several cameras simultaneously. The grabbed frames are not exposed because
162
+ * they may be stored in compressed format (as defined by camera/driver).
163
+ * To retrieve the grabbed frame, retrieve should be used.
164
+ *
165
+ * If grabbed frame was success, return true. Otherwise return false.
166
+ */
167
+ VALUE
168
+ rb_grab(VALUE self)
169
+ {
170
+ int grab = 0;
171
+ try {
172
+ grab = cvGrabFrame(CVCAPTURE(self));
173
+ }
174
+ catch (cv::Exception& e) {
175
+ raise_cverror(e);
176
+ }
177
+ return grab ? Qtrue : Qfalse;
178
+ }
179
+
180
+ /*
181
+ * call-seq:
182
+ * retrieve -> IplImage or nil
183
+ *
184
+ * Gets the image grabbed with grab.
185
+ */
186
+ VALUE
187
+ rb_retrieve(VALUE self)
188
+ {
189
+ VALUE image = Qnil;
190
+ try {
191
+ IplImage *frame = cvRetrieveFrame(CVCAPTURE(self));
192
+ if (!frame)
193
+ return Qnil;
194
+ image = cIplImage::new_object(cvSize(frame->width, frame->height),
195
+ CV_MAKETYPE(CV_8U, frame->nChannels));
196
+ if (frame->origin == IPL_ORIGIN_TL)
197
+ cvCopy(frame, CVARR(image));
198
+ else
199
+ cvFlip(frame, CVARR(image));
200
+ }
201
+ catch (cv::Exception& e) {
202
+ raise_cverror(e);
203
+ }
204
+ return image;
205
+ }
206
+
207
+ /*
208
+ * call-seq:
209
+ * query -> IplImage or nil
210
+ *
211
+ * Grabs and returns a frame camera or file. Just a combination of grab and retrieve in one call.
212
+ */
213
+ VALUE
214
+ rb_query(VALUE self)
215
+ {
216
+ VALUE image = Qnil;
217
+ try {
218
+ IplImage *frame = cvQueryFrame(CVCAPTURE(self));
219
+ if (!frame)
220
+ return Qnil;
221
+ image = cIplImage::new_object(cvSize(frame->width, frame->height),
222
+ CV_MAKETYPE(CV_8U, frame->nChannels));
223
+ if (frame->origin == IPL_ORIGIN_TL)
224
+ cvCopy(frame, CVARR(image));
225
+ else
226
+ cvFlip(frame, CVARR(image));
227
+ }
228
+ catch (cv::Exception& e) {
229
+ raise_cverror(e);
230
+ }
231
+ return image;
232
+ }
233
+
234
+ VALUE
235
+ rb_get_capture_property(VALUE self, int id)
236
+ {
237
+ double result = 0;
238
+ try {
239
+ result = cvGetCaptureProperty(CVCAPTURE(self), id);
240
+ }
241
+ catch (cv::Exception& e) {
242
+ raise_cverror(e);
243
+ }
244
+ return rb_float_new(result);
245
+ }
246
+
247
+ VALUE
248
+ rb_set_capture_property(VALUE self, int id, VALUE value)
249
+ {
250
+ double result = 0;
251
+ try {
252
+ result = cvSetCaptureProperty(CVCAPTURE(self), id, NUM2DBL(value));
253
+ }
254
+ catch (cv::Exception& e) {
255
+ raise_cverror(e);
256
+ }
257
+ return rb_float_new(result);
258
+ }
259
+
260
+ /*
261
+ * Get film current position in milliseconds or video capture timestamp.
262
+ */
263
+ VALUE
264
+ rb_get_millisecond(VALUE self)
265
+ {
266
+ return rb_get_capture_property(self, CV_CAP_PROP_POS_MSEC);
267
+ }
268
+ /*
269
+ * Set film current position in milliseconds or video capture timestamp.
270
+ */
271
+ VALUE
272
+ rb_set_millisecond(VALUE self, VALUE value)
273
+ {
274
+ return rb_set_capture_property(self, CV_CAP_PROP_POS_MSEC, value);
275
+ }
276
+ /*
277
+ * Get 0-based index of the frame to be decoded/captured next
278
+ */
279
+ VALUE
280
+ rb_get_frames(VALUE self)
281
+ {
282
+ return rb_get_capture_property(self, CV_CAP_PROP_POS_FRAMES);
283
+ }
284
+ /*
285
+ * Set 0-based index of the frame to be decoded/captured next
286
+ */
287
+ VALUE
288
+ rb_set_frames(VALUE self, VALUE value)
289
+ {
290
+ return rb_set_capture_property(self, CV_CAP_PROP_POS_FRAMES, value);
291
+ }
292
+ /*
293
+ * Get relative position of video file (0 - start of the film, 1 - end of the film)
294
+ */
295
+ VALUE
296
+ rb_get_avi_ratio(VALUE self)
297
+ {
298
+ return rb_get_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO);
299
+ }
300
+ /*
301
+ * Set relative position of video file (0 - start of the film, 1 - end of the film)
302
+ */
303
+ VALUE
304
+ rb_set_avi_ratio(VALUE self, VALUE value)
305
+ {
306
+ return rb_set_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO, value);
307
+ }
308
+ /*
309
+ * Get size of frames in the video stream.
310
+ */
311
+ VALUE
312
+ rb_get_size(VALUE self)
313
+ {
314
+ CvSize size;
315
+ try {
316
+ CvCapture* self_ptr = CVCAPTURE(self);
317
+ size = cvSize((int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH),
318
+ (int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT));
319
+ }
320
+ catch (cv::Exception& e) {
321
+ raise_cverror(e);
322
+ }
323
+ return cCvSize::new_object(size);
324
+ }
325
+ /*
326
+ * Set size of frames in the video stream.
327
+ */
328
+ VALUE
329
+ rb_set_size(VALUE self, VALUE value)
330
+ {
331
+ double result = 0;
332
+ CvSize size = VALUE_TO_CVSIZE(value);
333
+ try {
334
+ CvCapture* self_ptr = CVCAPTURE(self);
335
+ cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH, size.width);
336
+ result = cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT, size.height);
337
+ }
338
+ catch (cv::Exception& e) {
339
+ raise_cverror(e);
340
+ }
341
+ return DBL2NUM(result);
342
+ }
343
+ /*
344
+ * Get width of frames in the video stream.
345
+ */
346
+ VALUE
347
+ rb_get_width(VALUE self)
348
+ {
349
+ return rb_get_capture_property(self, CV_CAP_PROP_FRAME_WIDTH);
350
+ }
351
+ /*
352
+ * Set width of frames in the video stream.
353
+ */
354
+ VALUE
355
+ rb_set_width(VALUE self, VALUE value)
356
+ {
357
+ return rb_set_capture_property(self, CV_CAP_PROP_FRAME_WIDTH, value);
358
+ }
359
+ /*
360
+ * Get height of frames in the video stream.
361
+ */
362
+ VALUE
363
+ rb_get_height(VALUE self)
364
+ {
365
+ return rb_get_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT);
366
+ }
367
+ /*
368
+ * Set height of frames in the video stream.
369
+ */
370
+ VALUE
371
+ rb_set_height(VALUE self, VALUE value)
372
+ {
373
+ return rb_set_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT, value);
374
+ }
375
+ /*
376
+ * Get frame rate
377
+ */
378
+ VALUE
379
+ rb_get_fps(VALUE self)
380
+ {
381
+ return rb_get_capture_property(self, CV_CAP_PROP_FPS);
382
+ }
383
+ /*
384
+ * Set frame rate
385
+ */
386
+ VALUE
387
+ rb_set_fps(VALUE self, VALUE value)
388
+ {
389
+ return rb_set_capture_property(self, CV_CAP_PROP_FPS, value);
390
+ }
391
+ /*
392
+ * Get 4character code of codec. see http://www.fourcc.org/
393
+ */
394
+ VALUE
395
+ rb_get_fourcc(VALUE self)
396
+ {
397
+ char str[4];
398
+ double fourcc = cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FOURCC);
399
+ sprintf(str, "%s", (char*)&fourcc);
400
+ return rb_str_new2(str);
401
+ }
402
+ /*
403
+ * Get number of frames in video file.
404
+ */
405
+ VALUE
406
+ rb_get_frame_count(VALUE self)
407
+ {
408
+ return rb_get_capture_property(self, CV_CAP_PROP_FRAME_COUNT);
409
+ }
410
+ /*
411
+ * Get the format of the Mat objects returned by CvCapture#retrieve
412
+ */
413
+ VALUE
414
+ rb_get_format(VALUE self)
415
+ {
416
+ return rb_get_capture_property(self, CV_CAP_PROP_FORMAT);
417
+ }
418
+ /*
419
+ * Get a backend-specific value indicating the current capture mode
420
+ */
421
+ VALUE
422
+ rb_get_mode(VALUE self)
423
+ {
424
+ return rb_get_capture_property(self, CV_CAP_PROP_MODE);
425
+ }
426
+ /*
427
+ * Get brightness of the image (only for cameras)
428
+ */
429
+ VALUE
430
+ rb_get_brightness(VALUE self)
431
+ {
432
+ return rb_get_capture_property(self, CV_CAP_PROP_BRIGHTNESS);
433
+ }
434
+ /*
435
+ * Get contrast of the image (only for cameras)
436
+ */
437
+ VALUE
438
+ rb_get_contrast(VALUE self)
439
+ {
440
+ return rb_get_capture_property(self, CV_CAP_PROP_CONTRAST);
441
+ }
442
+ /*
443
+ * Get saturation of the image (only for cameras)
444
+ */
445
+ VALUE
446
+ rb_get_saturation(VALUE self)
447
+ {
448
+ return rb_get_capture_property(self, CV_CAP_PROP_SATURATION);
449
+ }
450
+ /*
451
+ * Get hue of the image (only for cameras)
452
+ */
453
+ VALUE
454
+ rb_get_hue(VALUE self)
455
+ {
456
+ return rb_get_capture_property(self, CV_CAP_PROP_HUE);
457
+ }
458
+ /*
459
+ * Get gain of the image (only for cameras)
460
+ */
461
+ VALUE
462
+ rb_get_gain(VALUE self)
463
+ {
464
+ return rb_get_capture_property(self, CV_CAP_PROP_GAIN);
465
+ }
466
+ /*
467
+ * Get exposure (only for cameras)
468
+ */
469
+ VALUE
470
+ rb_get_exposure(VALUE self)
471
+ {
472
+ return rb_get_capture_property(self, CV_CAP_PROP_EXPOSURE);
473
+ }
474
+ /*
475
+ * Get boolean flags indicating whether images should be converted to RGB
476
+ */
477
+ VALUE
478
+ rb_get_convert_rgb(VALUE self)
479
+ {
480
+ int flag = 0;
481
+ try {
482
+ flag = (int)cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_CONVERT_RGB);
483
+ }
484
+ catch (cv::Exception& e) {
485
+ raise_cverror(e);
486
+ }
487
+ return flag ? Qtrue : Qfalse;
488
+ }
489
+ /*
490
+ * Get TOWRITE (note: only supported by DC1394 v 2.x backend currently)
491
+ */
492
+ VALUE
493
+ rb_get_rectification(VALUE self)
494
+ {
495
+ return rb_get_capture_property(self, CV_CAP_PROP_RECTIFICATION);
496
+ }
497
+ __NAMESPACE_END_CVCAPTURE
498
+ __NAMESPACE_END_OPENCV
499
+