jf-ruby-opencv 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.yardopts +3 -0
  4. data/DEVELOPERS_NOTE.md +137 -0
  5. data/Gemfile +9 -0
  6. data/History.txt +5 -0
  7. data/License.txt +30 -0
  8. data/Manifest.txt +239 -0
  9. data/README.md +94 -0
  10. data/Rakefile +99 -0
  11. data/config.yml +7 -0
  12. data/examples/alpha_blend.rb +21 -0
  13. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  14. data/examples/contours/bitmap-contours.png +0 -0
  15. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  16. data/examples/contours/contour_retrieval_modes.rb +139 -0
  17. data/examples/contours/rotated-boxes.jpg +0 -0
  18. data/examples/convexhull.rb +47 -0
  19. data/examples/face_detect.rb +20 -0
  20. data/examples/facerec/create_csv.rb +43 -0
  21. data/examples/facerec/facerec_eigenfaces.rb +132 -0
  22. data/examples/facerec/facerec_fisherfaces.rb +131 -0
  23. data/examples/facerec/facerec_lbph.rb +116 -0
  24. data/examples/facerec/readme.md +111 -0
  25. data/examples/find_obj.rb +169 -0
  26. data/examples/houghcircle.rb +22 -0
  27. data/examples/images/box.png +0 -0
  28. data/examples/images/box_in_scene.png +0 -0
  29. data/examples/images/inpaint.png +0 -0
  30. data/examples/images/lena-256x256.jpg +0 -0
  31. data/examples/images/lena-eyes.jpg +0 -0
  32. data/examples/images/lenna-rotated.jpg +0 -0
  33. data/examples/images/lenna.jpg +0 -0
  34. data/examples/images/stuff.jpg +0 -0
  35. data/examples/images/tiffany.jpg +0 -0
  36. data/examples/inpaint.rb +57 -0
  37. data/examples/match_kdtree.rb +88 -0
  38. data/examples/match_template.rb +26 -0
  39. data/examples/paint.rb +70 -0
  40. data/examples/snake.rb +43 -0
  41. data/ext/opencv/algorithm.cpp +291 -0
  42. data/ext/opencv/algorithm.h +38 -0
  43. data/ext/opencv/curve.cpp +127 -0
  44. data/ext/opencv/curve.h +34 -0
  45. data/ext/opencv/cvavgcomp.cpp +64 -0
  46. data/ext/opencv/cvavgcomp.h +39 -0
  47. data/ext/opencv/cvbox2d.cpp +195 -0
  48. data/ext/opencv/cvbox2d.h +61 -0
  49. data/ext/opencv/cvcapture.cpp +633 -0
  50. data/ext/opencv/cvcapture.h +82 -0
  51. data/ext/opencv/cvchain.cpp +233 -0
  52. data/ext/opencv/cvchain.h +46 -0
  53. data/ext/opencv/cvcircle32f.cpp +126 -0
  54. data/ext/opencv/cvcircle32f.h +52 -0
  55. data/ext/opencv/cvconnectedcomp.cpp +156 -0
  56. data/ext/opencv/cvconnectedcomp.h +49 -0
  57. data/ext/opencv/cvcontour.cpp +384 -0
  58. data/ext/opencv/cvcontour.h +51 -0
  59. data/ext/opencv/cvcontourtree.cpp +96 -0
  60. data/ext/opencv/cvcontourtree.h +41 -0
  61. data/ext/opencv/cvconvexitydefect.cpp +92 -0
  62. data/ext/opencv/cvconvexitydefect.h +42 -0
  63. data/ext/opencv/cverror.cpp +115 -0
  64. data/ext/opencv/cverror.h +28 -0
  65. data/ext/opencv/cvfeaturetree.cpp +123 -0
  66. data/ext/opencv/cvfeaturetree.h +55 -0
  67. data/ext/opencv/cvfont.cpp +228 -0
  68. data/ext/opencv/cvfont.h +64 -0
  69. data/ext/opencv/cvhaarclassifiercascade.cpp +148 -0
  70. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  71. data/ext/opencv/cvhistogram.cpp +717 -0
  72. data/ext/opencv/cvhistogram.h +73 -0
  73. data/ext/opencv/cvhumoments.cpp +178 -0
  74. data/ext/opencv/cvhumoments.h +51 -0
  75. data/ext/opencv/cvline.cpp +159 -0
  76. data/ext/opencv/cvline.h +54 -0
  77. data/ext/opencv/cvmat.cpp +6086 -0
  78. data/ext/opencv/cvmat.h +290 -0
  79. data/ext/opencv/cvmemstorage.cpp +73 -0
  80. data/ext/opencv/cvmemstorage.h +50 -0
  81. data/ext/opencv/cvmoments.cpp +293 -0
  82. data/ext/opencv/cvmoments.h +75 -0
  83. data/ext/opencv/cvpoint.cpp +234 -0
  84. data/ext/opencv/cvpoint.h +64 -0
  85. data/ext/opencv/cvpoint2d32f.cpp +216 -0
  86. data/ext/opencv/cvpoint2d32f.h +63 -0
  87. data/ext/opencv/cvpoint3d32f.cpp +252 -0
  88. data/ext/opencv/cvpoint3d32f.h +66 -0
  89. data/ext/opencv/cvrect.cpp +338 -0
  90. data/ext/opencv/cvrect.h +79 -0
  91. data/ext/opencv/cvscalar.cpp +241 -0
  92. data/ext/opencv/cvscalar.h +71 -0
  93. data/ext/opencv/cvseq.cpp +663 -0
  94. data/ext/opencv/cvseq.h +75 -0
  95. data/ext/opencv/cvsize.cpp +227 -0
  96. data/ext/opencv/cvsize.h +65 -0
  97. data/ext/opencv/cvsize2d32f.cpp +215 -0
  98. data/ext/opencv/cvsize2d32f.h +64 -0
  99. data/ext/opencv/cvslice.cpp +126 -0
  100. data/ext/opencv/cvslice.h +61 -0
  101. data/ext/opencv/cvsurfparams.cpp +208 -0
  102. data/ext/opencv/cvsurfparams.h +58 -0
  103. data/ext/opencv/cvsurfpoint.cpp +246 -0
  104. data/ext/opencv/cvsurfpoint.h +52 -0
  105. data/ext/opencv/cvtermcriteria.cpp +198 -0
  106. data/ext/opencv/cvtermcriteria.h +71 -0
  107. data/ext/opencv/cvtwopoints.cpp +122 -0
  108. data/ext/opencv/cvtwopoints.h +51 -0
  109. data/ext/opencv/cvutils.cpp +192 -0
  110. data/ext/opencv/cvutils.h +30 -0
  111. data/ext/opencv/cvvideowriter.cpp +142 -0
  112. data/ext/opencv/cvvideowriter.h +43 -0
  113. data/ext/opencv/eigenfaces.cpp +75 -0
  114. data/ext/opencv/eigenfaces.h +30 -0
  115. data/ext/opencv/extconf.rb +77 -0
  116. data/ext/opencv/facerecognizer.cpp +219 -0
  117. data/ext/opencv/facerecognizer.h +46 -0
  118. data/ext/opencv/fisherfaces.cpp +75 -0
  119. data/ext/opencv/fisherfaces.h +30 -0
  120. data/ext/opencv/gui.cpp +71 -0
  121. data/ext/opencv/gui.h +30 -0
  122. data/ext/opencv/iplconvkernel.cpp +198 -0
  123. data/ext/opencv/iplconvkernel.h +71 -0
  124. data/ext/opencv/iplimage.cpp +651 -0
  125. data/ext/opencv/iplimage.h +73 -0
  126. data/ext/opencv/lbph.cpp +78 -0
  127. data/ext/opencv/lbph.h +30 -0
  128. data/ext/opencv/mouseevent.cpp +186 -0
  129. data/ext/opencv/mouseevent.h +56 -0
  130. data/ext/opencv/opencv.cpp +819 -0
  131. data/ext/opencv/opencv.h +408 -0
  132. data/ext/opencv/pointset.cpp +280 -0
  133. data/ext/opencv/pointset.h +68 -0
  134. data/ext/opencv/trackbar.cpp +127 -0
  135. data/ext/opencv/trackbar.h +69 -0
  136. data/ext/opencv/window.cpp +377 -0
  137. data/ext/opencv/window.h +66 -0
  138. data/images/CvMat_sobel.png +0 -0
  139. data/images/CvMat_sub_rect.png +0 -0
  140. data/images/CvSeq_relationmap.png +0 -0
  141. data/lib/opencv.rb +12 -0
  142. data/lib/opencv/psyched_yaml.rb +22 -0
  143. data/lib/opencv/version.rb +3 -0
  144. data/ruby-opencv.gemspec +44 -0
  145. data/test/eigenfaces_save.xml +7524 -0
  146. data/test/fisherfaces_save.xml +7530 -0
  147. data/test/helper.rb +167 -0
  148. data/test/lbph_save.xml +4304 -0
  149. data/test/runner.rb +30 -0
  150. data/test/samples/airplane.jpg +0 -0
  151. data/test/samples/baboon.jpg +0 -0
  152. data/test/samples/baboon200.jpg +0 -0
  153. data/test/samples/baboon200_rotated.jpg +0 -0
  154. data/test/samples/blank0.jpg +0 -0
  155. data/test/samples/blank1.jpg +0 -0
  156. data/test/samples/blank2.jpg +0 -0
  157. data/test/samples/blank3.jpg +0 -0
  158. data/test/samples/blank4.jpg +0 -0
  159. data/test/samples/blank5.jpg +0 -0
  160. data/test/samples/blank6.jpg +0 -0
  161. data/test/samples/blank7.jpg +0 -0
  162. data/test/samples/blank8.jpg +0 -0
  163. data/test/samples/blank9.jpg +0 -0
  164. data/test/samples/cat.jpg +0 -0
  165. data/test/samples/chessboard.jpg +0 -0
  166. data/test/samples/contours.jpg +0 -0
  167. data/test/samples/fruits.jpg +0 -0
  168. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  169. data/test/samples/inpaint-mask.bmp +0 -0
  170. data/test/samples/lena-256x256.jpg +0 -0
  171. data/test/samples/lena-32x32.jpg +0 -0
  172. data/test/samples/lena-eyes.jpg +0 -0
  173. data/test/samples/lena-inpaint.jpg +0 -0
  174. data/test/samples/lena.jpg +0 -0
  175. data/test/samples/lines.jpg +0 -0
  176. data/test/samples/messy0.jpg +0 -0
  177. data/test/samples/messy1.jpg +0 -0
  178. data/test/samples/movie_sample.avi +0 -0
  179. data/test/samples/one_way_train_0000.jpg +0 -0
  180. data/test/samples/one_way_train_0001.jpg +0 -0
  181. data/test/samples/partially_blank0.jpg +0 -0
  182. data/test/samples/partially_blank1.jpg +0 -0
  183. data/test/samples/smooth0.jpg +0 -0
  184. data/test/samples/smooth1.jpg +0 -0
  185. data/test/samples/smooth2.jpg +0 -0
  186. data/test/samples/smooth3.jpg +0 -0
  187. data/test/samples/smooth4.jpg +0 -0
  188. data/test/samples/smooth5.jpg +0 -0
  189. data/test/samples/smooth6.jpg +0 -0
  190. data/test/samples/str-cv-rotated.jpg +0 -0
  191. data/test/samples/str-cv.jpg +0 -0
  192. data/test/samples/str-ov.jpg +0 -0
  193. data/test/samples/stuff.jpg +0 -0
  194. data/test/test_curve.rb +43 -0
  195. data/test/test_cvavgcomp.rb +24 -0
  196. data/test/test_cvbox2d.rb +76 -0
  197. data/test/test_cvcapture.rb +191 -0
  198. data/test/test_cvchain.rb +108 -0
  199. data/test/test_cvcircle32f.rb +41 -0
  200. data/test/test_cvconnectedcomp.rb +61 -0
  201. data/test/test_cvcontour.rb +171 -0
  202. data/test/test_cvcontourtree.rb +43 -0
  203. data/test/test_cverror.rb +50 -0
  204. data/test/test_cvfeaturetree.rb +65 -0
  205. data/test/test_cvfont.rb +58 -0
  206. data/test/test_cvhaarclassifiercascade.rb +63 -0
  207. data/test/test_cvhistogram.rb +271 -0
  208. data/test/test_cvhumoments.rb +83 -0
  209. data/test/test_cvline.rb +50 -0
  210. data/test/test_cvmat.rb +3036 -0
  211. data/test/test_cvmat_drawing.rb +349 -0
  212. data/test/test_cvmat_dxt.rb +150 -0
  213. data/test/test_cvmat_imageprocessing.rb +2085 -0
  214. data/test/test_cvmoments.rb +180 -0
  215. data/test/test_cvpoint.rb +75 -0
  216. data/test/test_cvpoint2d32f.rb +75 -0
  217. data/test/test_cvpoint3d32f.rb +93 -0
  218. data/test/test_cvrect.rb +144 -0
  219. data/test/test_cvscalar.rb +113 -0
  220. data/test/test_cvseq.rb +311 -0
  221. data/test/test_cvsize.rb +75 -0
  222. data/test/test_cvsize2d32f.rb +75 -0
  223. data/test/test_cvslice.rb +31 -0
  224. data/test/test_cvsurfparams.rb +57 -0
  225. data/test/test_cvsurfpoint.rb +66 -0
  226. data/test/test_cvtermcriteria.rb +56 -0
  227. data/test/test_cvtwopoints.rb +40 -0
  228. data/test/test_cvvideowriter.rb +58 -0
  229. data/test/test_eigenfaces.rb +93 -0
  230. data/test/test_fisherfaces.rb +93 -0
  231. data/test/test_iplconvkernel.rb +54 -0
  232. data/test/test_iplimage.rb +232 -0
  233. data/test/test_lbph.rb +166 -0
  234. data/test/test_mouseevent.rb +17 -0
  235. data/test/test_opencv.rb +360 -0
  236. data/test/test_pointset.rb +128 -0
  237. data/test/test_preliminary.rb +130 -0
  238. data/test/test_trackbar.rb +47 -0
  239. data/test/test_window.rb +115 -0
  240. data/yard_extension.rb +5 -0
  241. metadata +352 -0
@@ -0,0 +1,34 @@
1
+ /************************************************************
2
+
3
+ curve.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVSEQ_CURVE_H
11
+ #define RUBY_OPENCV_CVSEQ_CURVE_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CURVE namespace mCurve {
16
+ #define __NAMESPACE_END_CURVE }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CURVE
20
+
21
+ VALUE rb_module();
22
+
23
+ void init_ruby_module();
24
+
25
+ VALUE rb_closed_q(VALUE self);
26
+ VALUE rb_convex_q(VALUE self);
27
+ VALUE rb_hole_q(VALUE self);
28
+ VALUE rb_simple_q(VALUE self);
29
+ VALUE rb_arc_length(int argc, VALUE *argv, VALUE self);
30
+
31
+ __NAMESPACE_END_CURVE
32
+ __NAMESPACE_END_OPENCV
33
+
34
+ #endif // RUBY_OPENCV_CVSEQ_CURVE_H
@@ -0,0 +1,64 @@
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
+ */
16
+ __NAMESPACE_BEGIN_OPENCV
17
+ __NAMESPACE_BEGIN_AVGCOMP
18
+
19
+ VALUE rb_klass;
20
+
21
+ VALUE
22
+ rb_class()
23
+ {
24
+ return rb_klass;
25
+ }
26
+
27
+ VALUE
28
+ rb_allocate(VALUE klass)
29
+ {
30
+ CvAvgComp *ptr;
31
+ return Data_Make_Struct(klass, CvAvgComp, 0, -1, ptr);
32
+ }
33
+
34
+ /*
35
+ * Return neighbors
36
+ * @overload neighbors
37
+ * @return [Integer] neighbors
38
+ */
39
+ VALUE
40
+ rb_neighbors(VALUE self)
41
+ {
42
+ return INT2NUM(CVAVGCOMP(self)->neighbors);
43
+ }
44
+
45
+ void
46
+ init_ruby_class()
47
+ {
48
+ #if 0
49
+ // For documentation using YARD
50
+ VALUE opencv = rb_define_module("OpenCV");
51
+ VALUE cvrect = rb_define_class_under(opencv, "CvRect", rb_cObject);
52
+ #endif
53
+
54
+ if (rb_klass)
55
+ return;
56
+
57
+ VALUE opencv = rb_module_opencv(), cvrect = cCvRect::rb_class();
58
+ rb_klass = rb_define_class_under(opencv, "CvAvgComp", cvrect);
59
+ rb_define_alloc_func(rb_klass, rb_allocate);
60
+ rb_define_method(rb_klass, "neighbors", RUBY_METHOD_FUNC(rb_neighbors), 0);
61
+ }
62
+
63
+ __NAMESPACE_END_AVGCOMP
64
+ __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 init_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,195 @@
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
+ * Stores coordinates of a rotated rectangle.
15
+ */
16
+ __NAMESPACE_BEGIN_OPENCV
17
+ __NAMESPACE_BEGIN_CVBOX2D
18
+
19
+ VALUE rb_klass;
20
+
21
+ VALUE
22
+ rb_class()
23
+ {
24
+ return rb_klass;
25
+ }
26
+
27
+ VALUE
28
+ rb_allocate(VALUE klass)
29
+ {
30
+ CvBox2D *ptr;
31
+ return Data_Make_Struct(klass, CvBox2D, 0, -1, ptr);
32
+ }
33
+
34
+ /*
35
+ * Create a box
36
+ * @overload new(center=nil, size=nil, angle=nil)
37
+ * @param center [CvPoint2D32f,nil] Center of the box
38
+ * @param size [CvSize,nil] Size of the box
39
+ * @param angle [Number,nil] Angle between the horizontal axis and the first side in degrees
40
+ * @return [CvBox2D] New box
41
+ */
42
+ VALUE
43
+ rb_initialize(int argc, VALUE *argv, VALUE self)
44
+ {
45
+ VALUE center, size, angle;
46
+ CvBox2D* self_ptr = CVBOX2D(self);
47
+ rb_scan_args(argc, argv, "03", &center, &size, &angle);
48
+
49
+ if (!NIL_P(center)) {
50
+ self_ptr->center = VALUE_TO_CVPOINT2D32F(center);
51
+ }
52
+ if (!NIL_P(size)) {
53
+ self_ptr->size = VALUE_TO_CVSIZE2D32F(size);
54
+ self_ptr->angle = NUM2DBL(angle);
55
+ }
56
+
57
+ return self;
58
+ }
59
+
60
+ /*
61
+ * Returns center point of the box
62
+ * @overload center
63
+ * @return [CvPoint2D32f] Center of the box
64
+ */
65
+ VALUE
66
+ rb_center(VALUE self)
67
+ {
68
+ return REFER_OBJECT(cCvPoint2D32f::rb_class(), &CVBOX2D(self)->center, self);
69
+ }
70
+
71
+ /*
72
+ * Set center point of the box
73
+ * @overload center=value
74
+ * @param value [CvPoint2D32f] Center of the box
75
+ * @return [CvBox2D] self
76
+ */
77
+ VALUE
78
+ rb_set_center(VALUE self, VALUE value)
79
+ {
80
+ CVBOX2D(self)->center = VALUE_TO_CVPOINT2D32F(value);
81
+ return self;
82
+ }
83
+
84
+ /*
85
+ * Returns size of the box
86
+ * @overload size
87
+ * @return [CvSize2D32f] Size of the box
88
+ */
89
+ VALUE
90
+ rb_size(VALUE self)
91
+ {
92
+ return REFER_OBJECT(cCvSize2D32f::rb_class(), &CVBOX2D(self)->size, self);
93
+ }
94
+
95
+ /*
96
+ * Set size of the box
97
+ * @overload size=value
98
+ * @param value [CvSize2D32f] Size of the box
99
+ * @return [CvBox2D] self
100
+ */
101
+ VALUE
102
+ rb_set_size(VALUE self, VALUE value)
103
+ {
104
+ CVBOX2D(self)->size = VALUE_TO_CVSIZE2D32F(value);
105
+ return self;
106
+ }
107
+
108
+ /*
109
+ * Returns angle of the box
110
+ * @overload angle
111
+ * @return [Float] Angle of the box
112
+ */
113
+ VALUE
114
+ rb_angle(VALUE self)
115
+ {
116
+ return rb_float_new(CVBOX2D(self)->angle);
117
+ }
118
+
119
+ /*
120
+ * Set angle of the box
121
+ * @overload angle=value
122
+ * @param value [Number] Angle of the box
123
+ * @return [CvBox2D] self
124
+ */
125
+ VALUE
126
+ rb_set_angle(VALUE self, VALUE value)
127
+ {
128
+ CVBOX2D(self)->angle = NUM2DBL(value);
129
+ return self;
130
+ }
131
+
132
+ /*
133
+ * Find box vertices
134
+ * @overload points
135
+ * @return [Array<CvPoint2D32f>] Vertices of the box
136
+ * @opencv_func cvBoxPoints
137
+ */
138
+ VALUE
139
+ rb_points(VALUE self)
140
+ {
141
+ const int n = 4;
142
+ CvPoint2D32f p[n];
143
+ try {
144
+ cvBoxPoints(*CVBOX2D(self), p);
145
+ }
146
+ catch (cv::Exception& e) {
147
+ raise_cverror(e);
148
+ }
149
+ VALUE points = rb_ary_new2(n);
150
+ for (int i = 0; i < n; ++i) {
151
+ rb_ary_store(points, i, cCvPoint2D32f::new_object(p[i]));
152
+ }
153
+ return points;
154
+ }
155
+
156
+ VALUE
157
+ new_object()
158
+ {
159
+ return rb_allocate(cCvBox2D::rb_class());
160
+ }
161
+
162
+ VALUE
163
+ new_object(CvBox2D box)
164
+ {
165
+ VALUE object = rb_allocate(rb_klass);
166
+ *CVBOX2D(object) = box;
167
+ return object;
168
+ }
169
+
170
+ void
171
+ init_ruby_class()
172
+ {
173
+ #if 0
174
+ // For documentation using YARD
175
+ VALUE opencv = rb_define_module("OpenCV");
176
+ #endif
177
+
178
+ if (rb_klass)
179
+ return;
180
+
181
+ VALUE opencv = rb_module_opencv();
182
+ rb_klass = rb_define_class_under(opencv, "CvBox2D", rb_cObject);
183
+ rb_define_alloc_func(rb_klass, rb_allocate);
184
+ rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
185
+ rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
186
+ rb_define_method(rb_klass, "center=", RUBY_METHOD_FUNC(rb_set_center), 1);
187
+ rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
188
+ rb_define_method(rb_klass, "size=", RUBY_METHOD_FUNC(rb_set_size), 1);
189
+ rb_define_method(rb_klass, "angle", RUBY_METHOD_FUNC(rb_angle), 0);
190
+ rb_define_method(rb_klass, "angle=", RUBY_METHOD_FUNC(rb_set_angle), 1);
191
+ rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
192
+ }
193
+
194
+ __NAMESPACE_END_CVBOX2D
195
+ __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 init_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,633 @@
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
+ * Class for video capturing from video files or cameras
15
+ */
16
+ __NAMESPACE_BEGIN_OPENCV
17
+ __NAMESPACE_BEGIN_CVCAPTURE
18
+
19
+ VALUE rb_klass;
20
+
21
+ VALUE
22
+ rb_class()
23
+ {
24
+ return rb_klass;
25
+ }
26
+
27
+ void
28
+ cvcapture_free(void *ptr)
29
+ {
30
+ if (ptr) {
31
+ sCvCapture* scap = (sCvCapture*)ptr;
32
+ if (scap->opened)
33
+ cvReleaseCapture(&scap->ptr);
34
+ delete scap;
35
+ }
36
+ }
37
+
38
+ /*
39
+ * Open video file or a capturing device for video capturing
40
+ * @scope class
41
+ * @overload open(dev = nil)
42
+ * @param dev [String,Integer,Simbol,nil] Video capturing device
43
+ * * If dev is a string (i.e "stream.avi"), reads video stream from a file.
44
+ * * If dev is a number or symbol (included in CvCapture::INTERFACE), reads video stream from a device.
45
+ * * If dev is a nil, same as CvCapture.open(:any)
46
+ * @return [CvCapture] Opened CvCapture instance
47
+ * @opencv_func cvCaptureFromCAM
48
+ * @opencv_func cvCaptureFromFile
49
+ */
50
+ VALUE
51
+ rb_open(int argc, VALUE *argv, VALUE self)
52
+ {
53
+ VALUE device;
54
+ rb_scan_args(argc, argv, "01", &device);
55
+ CvCapture *capture = 0;
56
+ sCvCapture *scap = new sCvCapture();
57
+ try {
58
+ switch (TYPE(device)) {
59
+ case T_STRING:
60
+ capture = cvCaptureFromFile(StringValueCStr(device));
61
+ break;
62
+ case T_FIXNUM:
63
+ capture = cvCaptureFromCAM(FIX2INT(device));
64
+ break;
65
+ case T_SYMBOL: {
66
+ VALUE cap_index = rb_hash_lookup(rb_const_get(rb_class(), rb_intern("INTERFACE")), device);
67
+ if (NIL_P(cap_index))
68
+ rb_raise(rb_eArgError, "undefined interface.");
69
+ capture = cvCaptureFromCAM(NUM2INT(cap_index));
70
+ break;
71
+ }
72
+ case T_NIL:
73
+ capture = cvCaptureFromCAM(CV_CAP_ANY);
74
+ break;
75
+ }
76
+ }
77
+ catch (cv::Exception& e) {
78
+ raise_cverror(e);
79
+ }
80
+ if (!capture)
81
+ rb_raise(rb_eStandardError, "Invalid capture format.");
82
+ scap->ptr = capture;
83
+ scap->opened = true;
84
+ return Data_Wrap_Struct(rb_klass, 0, cvcapture_free, scap);
85
+ }
86
+
87
+ /*
88
+ * Releases an opened video file or a capturing device
89
+ * @return [boolean] False if the device was already closed
90
+ */
91
+
92
+ VALUE
93
+ rb_close(VALUE self)
94
+ {
95
+ sCvCapture *scap;
96
+ Data_Get_Struct(self, sCvCapture, scap);
97
+ if (scap->opened) {
98
+ scap->opened = false;
99
+ cvReleaseCapture(&scap->ptr);
100
+ return true;
101
+ } else
102
+ return false;
103
+ }
104
+
105
+ /*
106
+ * Grabs the next frame from video file or capturing device.
107
+ * @overload grab
108
+ * @return [Boolean] If grabbing a frame successed, returns true, otherwise returns false.
109
+ * @opencv_func cvGrabFrame
110
+ */
111
+ VALUE
112
+ rb_grab(VALUE self)
113
+ {
114
+ int grab = 0;
115
+ try {
116
+ grab = cvGrabFrame(CVCAPTURE(self));
117
+ }
118
+ catch (cv::Exception& e) {
119
+ raise_cverror(e);
120
+ }
121
+ return grab ? Qtrue : Qfalse;
122
+ }
123
+
124
+ /*
125
+ * Decodes and returns the grabbed video frame.
126
+ * @overload retrieve
127
+ * @return [IplImage] Grabbed video frame
128
+ * @return [nil] Failed to grabbing a frame
129
+ * @opencv_func cvRetrieveFrame
130
+ */
131
+ VALUE
132
+ rb_retrieve(VALUE self)
133
+ {
134
+ VALUE image = Qnil;
135
+ IplImage *frame = NULL;
136
+ try {
137
+ if (!(frame = cvRetrieveFrame(CVCAPTURE(self)))) {
138
+ return Qnil;
139
+ }
140
+ image = cIplImage::new_object(frame->width, frame->height,
141
+ CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
142
+ if (frame->origin == IPL_ORIGIN_TL) {
143
+ cvCopy(frame, CVARR(image));
144
+ }
145
+ else {
146
+ cvFlip(frame, CVARR(image));
147
+ }
148
+ }
149
+ catch (cv::Exception& e) {
150
+ raise_cverror(e);
151
+ }
152
+ return image;
153
+
154
+ }
155
+
156
+ /*
157
+ * Grabs, decodes and returns the next video frame.
158
+ * @overload query
159
+ * @return [IplImage] Next video frame
160
+ * @return [nil] Failed to read next video frame
161
+ * @opencv_func cvQueryFrame
162
+ */
163
+ VALUE
164
+ rb_query(VALUE self)
165
+ {
166
+ VALUE image = Qnil;
167
+ IplImage *frame = NULL;
168
+ try {
169
+ if (!(frame = cvQueryFrame(CVCAPTURE(self)))) {
170
+ return Qnil;
171
+ }
172
+ image = cIplImage::new_object(frame->width, frame->height,
173
+ CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
174
+ if (frame->origin == IPL_ORIGIN_TL) {
175
+ cvCopy(frame, CVARR(image));
176
+ }
177
+ else {
178
+ cvFlip(frame, CVARR(image));
179
+ }
180
+ }
181
+ catch (cv::Exception& e) {
182
+ raise_cverror(e);
183
+ }
184
+ return image;
185
+ }
186
+
187
+ VALUE
188
+ rb_get_capture_property(VALUE self, int id)
189
+ {
190
+ double result = 0;
191
+ try {
192
+ result = cvGetCaptureProperty(CVCAPTURE(self), id);
193
+ }
194
+ catch (cv::Exception& e) {
195
+ raise_cverror(e);
196
+ }
197
+ return rb_float_new(result);
198
+ }
199
+
200
+ VALUE
201
+ rb_set_capture_property(VALUE self, int id, VALUE value)
202
+ {
203
+ double result = 0;
204
+ try {
205
+ result = cvSetCaptureProperty(CVCAPTURE(self), id, NUM2DBL(value));
206
+ }
207
+ catch (cv::Exception& e) {
208
+ raise_cverror(e);
209
+ }
210
+ return rb_float_new(result);
211
+ }
212
+
213
+ /*
214
+ * Get film current position in milliseconds or video capture timestamp.
215
+ * @overload millisecond
216
+ * @return [Number] Current position of the video file in milliseconds or video capture timestamp
217
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_POS_MSEC)
218
+ */
219
+ VALUE
220
+ rb_get_millisecond(VALUE self)
221
+ {
222
+ return rb_get_capture_property(self, CV_CAP_PROP_POS_MSEC);
223
+ }
224
+
225
+ /*
226
+ * Set film current position in milliseconds or video capture timestamp.
227
+ * @overload millisecond=value
228
+ * @param value [Number] Position in milliseconds or video capture timestamp.
229
+ * @return [Number]
230
+ * @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_POS_MSEC)
231
+ */
232
+ VALUE
233
+ rb_set_millisecond(VALUE self, VALUE value)
234
+ {
235
+ return rb_set_capture_property(self, CV_CAP_PROP_POS_MSEC, value);
236
+ }
237
+
238
+ /*
239
+ * Get 0-based index of the frame to be decoded/captured next
240
+ * @overload frames
241
+ * @return [Number] 0-based index of the frame to be decoded/captured next
242
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_POS_FRAMES)
243
+ */
244
+ VALUE
245
+ rb_get_frames(VALUE self)
246
+ {
247
+ return rb_get_capture_property(self, CV_CAP_PROP_POS_FRAMES);
248
+ }
249
+
250
+ /*
251
+ * Set 0-based index of the frame to be decoded/captured next
252
+ * @overload frames=value
253
+ * @param value [Number] 0-based index of the frame to be decoded/captured next
254
+ * @return [Number]
255
+ * @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_POS_FRAMES)
256
+ */
257
+ VALUE
258
+ rb_set_frames(VALUE self, VALUE value)
259
+ {
260
+ return rb_set_capture_property(self, CV_CAP_PROP_POS_FRAMES, value);
261
+ }
262
+ /*
263
+ * Get relative position of video file
264
+ * @overload avi_ratio
265
+ * @return [Number] Relative position of video file (0: Start of the film, 1: End of the film)
266
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_POS_AVI_RATIO)
267
+ */
268
+ VALUE
269
+ rb_get_avi_ratio(VALUE self)
270
+ {
271
+ return rb_get_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO);
272
+ }
273
+ /*
274
+ * Set relative position of video file
275
+ * @overload avi_ratio=value
276
+ * @param value [Number] Relative position of video file (0: Start of the film, 1: End of the film)
277
+ * @return [Number]
278
+ * @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_POS_AVI_RATIO)
279
+ */
280
+ VALUE
281
+ rb_set_avi_ratio(VALUE self, VALUE value)
282
+ {
283
+ return rb_set_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO, value);
284
+ }
285
+
286
+ /*
287
+ * Get size of frames in the video stream.
288
+ * @overload size
289
+ * @return [Size] Size of frames in the video stream.
290
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FRAME_WIDTH,CV_CAP_PROP_FRAME_HEIGHT)
291
+ */
292
+ VALUE
293
+ rb_get_size(VALUE self)
294
+ {
295
+ CvSize size;
296
+ try {
297
+ CvCapture* self_ptr = CVCAPTURE(self);
298
+ size = cvSize((int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH),
299
+ (int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT));
300
+ }
301
+ catch (cv::Exception& e) {
302
+ raise_cverror(e);
303
+ }
304
+ return cCvSize::new_object(size);
305
+ }
306
+
307
+ /*
308
+ * Set size of frames in the video stream.
309
+ * @overload size=value
310
+ * @param value [CvSize] Size of frames
311
+ * @return [Number]
312
+ * @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_FRAME_WIDTH,CV_CAP_PROP_FRAME_HEIGHT)
313
+ */
314
+ VALUE
315
+ rb_set_size(VALUE self, VALUE value)
316
+ {
317
+ double result = 0;
318
+ CvSize size = VALUE_TO_CVSIZE(value);
319
+ try {
320
+ CvCapture* self_ptr = CVCAPTURE(self);
321
+ cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH, size.width);
322
+ result = cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT, size.height);
323
+ }
324
+ catch (cv::Exception& e) {
325
+ raise_cverror(e);
326
+ }
327
+ return DBL2NUM(result);
328
+ }
329
+
330
+ /*
331
+ * Get width of frames in the video stream.
332
+ * @overload width
333
+ * @return [Number] Width of frames in the video stream.
334
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_FRAME_WIDTH)
335
+ */
336
+ VALUE
337
+ rb_get_width(VALUE self)
338
+ {
339
+ return rb_get_capture_property(self, CV_CAP_PROP_FRAME_WIDTH);
340
+ }
341
+
342
+ /*
343
+ * Set width of frames in the video stream.
344
+ * @overload width=value
345
+ * @param value [Number] Width of frames
346
+ * @return [Number]
347
+ * @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_FRAME_WIDTH)
348
+ */
349
+ VALUE
350
+ rb_set_width(VALUE self, VALUE value)
351
+ {
352
+ return rb_set_capture_property(self, CV_CAP_PROP_FRAME_WIDTH, value);
353
+ }
354
+
355
+ /*
356
+ * Get height of frames in the video stream.
357
+ * @overload height
358
+ * @return [Number] Height of frames in the video stream.
359
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FRAME_HEIGHT)
360
+ */
361
+ VALUE
362
+ rb_get_height(VALUE self)
363
+ {
364
+ return rb_get_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT);
365
+ }
366
+
367
+ /*
368
+ * Set height of frames in the video stream.
369
+ * @overload height=value
370
+ * @param value [Number] Height of frames
371
+ * @return [Number]
372
+ * @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_FRAME_HEIGHT)
373
+ */
374
+ VALUE
375
+ rb_set_height(VALUE self, VALUE value)
376
+ {
377
+ return rb_set_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT, value);
378
+ }
379
+
380
+ /*
381
+ * Get frame rate
382
+ * @overload fps
383
+ * @return [Number] Frame rate
384
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FPS)
385
+ */
386
+ VALUE
387
+ rb_get_fps(VALUE self)
388
+ {
389
+ return rb_get_capture_property(self, CV_CAP_PROP_FPS);
390
+ }
391
+
392
+ /*
393
+ * Set frame rate
394
+ * @overload fps=value
395
+ * @param value [Number] Frame rate
396
+ * @return [Number]
397
+ * @opencv_func cvSetCaptureProperty (propId=CV_CAP_PROP_FPS)
398
+ */
399
+ VALUE
400
+ rb_set_fps(VALUE self, VALUE value)
401
+ {
402
+ return rb_set_capture_property(self, CV_CAP_PROP_FPS, value);
403
+ }
404
+
405
+ /*
406
+ * Get 4 character code of codec. see http://www.fourcc.org/
407
+ * @overload fourcc
408
+ * @return [Number] Codec code
409
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FOURCC)
410
+ */
411
+ VALUE
412
+ rb_get_fourcc(VALUE self)
413
+ {
414
+ char str[4];
415
+ double fourcc = cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FOURCC);
416
+ sprintf(str, "%s", (char*)&fourcc);
417
+ return rb_str_new2(str);
418
+ }
419
+
420
+ /*
421
+ * Get number of frames in video file.
422
+ * @overload frame_count
423
+ * @return [Number] Number of frames
424
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FRAME_COUNT)
425
+ */
426
+ VALUE
427
+ rb_get_frame_count(VALUE self)
428
+ {
429
+ return rb_get_capture_property(self, CV_CAP_PROP_FRAME_COUNT);
430
+ }
431
+
432
+ /*
433
+ * Get format of images returned by CvCapture#retrieve
434
+ * @overload format
435
+ * @return [Number] format
436
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_FORMAT)
437
+ */
438
+ VALUE
439
+ rb_get_format(VALUE self)
440
+ {
441
+ return rb_get_capture_property(self, CV_CAP_PROP_FORMAT);
442
+ }
443
+
444
+ /*
445
+ * Get a backend-specific value indicating the current capture mode
446
+ * @overload mode
447
+ * @return [Number] Backend-specific value indicating the current capture mode
448
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_MODE)
449
+ */
450
+ VALUE
451
+ rb_get_mode(VALUE self)
452
+ {
453
+ return rb_get_capture_property(self, CV_CAP_PROP_MODE);
454
+ }
455
+
456
+ /*
457
+ * Get brightness of the image (only for cameras)
458
+ * @overload brightness
459
+ * @return [Number] Brightness
460
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_BRIGHTNESS)
461
+ */
462
+ VALUE
463
+ rb_get_brightness(VALUE self)
464
+ {
465
+ return rb_get_capture_property(self, CV_CAP_PROP_BRIGHTNESS);
466
+ }
467
+
468
+ /*
469
+ * Get contrast of the image (only for cameras)
470
+ * @overload contrast
471
+ * @return [Number] Contrast
472
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_CONTRAST)
473
+ */
474
+ VALUE
475
+ rb_get_contrast(VALUE self)
476
+ {
477
+ return rb_get_capture_property(self, CV_CAP_PROP_CONTRAST);
478
+ }
479
+
480
+ /*
481
+ * Get saturation of the image (only for cameras)
482
+ * @overload saturation
483
+ * @return [Number] Saturation
484
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_SATURATION)
485
+ */
486
+ VALUE
487
+ rb_get_saturation(VALUE self)
488
+ {
489
+ return rb_get_capture_property(self, CV_CAP_PROP_SATURATION);
490
+ }
491
+ /*
492
+ * Get hue of the image (only for cameras)
493
+ * @overload hue
494
+ * @return [Number] Hue
495
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_HUE)
496
+ */
497
+ VALUE
498
+ rb_get_hue(VALUE self)
499
+ {
500
+ return rb_get_capture_property(self, CV_CAP_PROP_HUE);
501
+ }
502
+
503
+ /*
504
+ * Get gain of the image (only for cameras)
505
+ * @overload gain
506
+ * @return [Number] Gain
507
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_GAIN)
508
+ */
509
+ VALUE
510
+ rb_get_gain(VALUE self)
511
+ {
512
+ return rb_get_capture_property(self, CV_CAP_PROP_GAIN);
513
+ }
514
+
515
+ /*
516
+ * Get exposure (only for cameras)
517
+ * @overload exposure
518
+ * @return [Number] Exposure
519
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_EXPOSURE)
520
+ */
521
+ VALUE
522
+ rb_get_exposure(VALUE self)
523
+ {
524
+ return rb_get_capture_property(self, CV_CAP_PROP_EXPOSURE);
525
+ }
526
+
527
+ /*
528
+ * Get boolean flags indicating whether images should be converted to RGB
529
+ * @overload convert_rgb
530
+ * @return [Boolean] Whether images should be converted to RGB
531
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_CONVERT_RGB)
532
+ */
533
+ VALUE
534
+ rb_get_convert_rgb(VALUE self)
535
+ {
536
+ int flag = 0;
537
+ try {
538
+ flag = (int)cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_CONVERT_RGB);
539
+ }
540
+ catch (cv::Exception& e) {
541
+ raise_cverror(e);
542
+ }
543
+ return flag ? Qtrue : Qfalse;
544
+ }
545
+
546
+ /*
547
+ * Get rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)
548
+ * @overload rectification
549
+ * @return [Number] Rectification flag
550
+ * @opencv_func cvGetCaptureProperty (propId=CV_CAP_PROP_RECTIFICATION)
551
+ */
552
+ VALUE
553
+ rb_get_rectification(VALUE self)
554
+ {
555
+ return rb_get_capture_property(self, CV_CAP_PROP_RECTIFICATION);
556
+ }
557
+
558
+ void
559
+ init_ruby_class()
560
+ {
561
+ #if 0
562
+ // For documentation using YARD
563
+ VALUE opencv = rb_define_module("OpenCV");
564
+ #endif
565
+
566
+ if (rb_klass)
567
+ return;
568
+
569
+ VALUE opencv = rb_module_opencv();
570
+
571
+ rb_klass = rb_define_class_under(opencv, "CvCapture", rb_cData);
572
+
573
+ VALUE video_interface = rb_hash_new();
574
+ /*
575
+ * :any, :mil, :vfw, :v4l, :v4l2, :fireware, :ieee1394, :dc1394, :cmu1394,
576
+ * :stereo, :tyzx, :tyzx_left, :tyzx_right, :tyzx_color, :tyzx_z, :qt, :qtuicktime
577
+ */
578
+ rb_define_const(rb_klass, "INTERFACE", video_interface);
579
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("any")), INT2FIX(CV_CAP_ANY));
580
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("mil")), INT2FIX(CV_CAP_MIL));
581
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("vfw")), INT2FIX(CV_CAP_VFW));
582
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l")), INT2FIX(CV_CAP_V4L));
583
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l2")), INT2FIX(CV_CAP_V4L2));
584
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("fireware")), INT2FIX(CV_CAP_FIREWARE));
585
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("ieee1394")), INT2FIX(CV_CAP_IEEE1394));
586
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("dc1394")), INT2FIX(CV_CAP_DC1394));
587
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("cmu1394")), INT2FIX(CV_CAP_CMU1394));
588
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("stereo")), INT2FIX(CV_CAP_STEREO));
589
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx")), INT2FIX(CV_CAP_TYZX));
590
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_left")), INT2FIX(CV_TYZX_LEFT));
591
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_right")), INT2FIX(CV_TYZX_RIGHT));
592
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_color")), INT2FIX(CV_TYZX_COLOR));
593
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_z")), INT2FIX(CV_TYZX_Z));
594
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("qt")), INT2FIX(CV_CAP_QT));
595
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("quicktime")), INT2FIX(CV_CAP_QT));
596
+
597
+ rb_define_singleton_method(rb_klass, "open", RUBY_METHOD_FUNC(rb_open), -1);
598
+ rb_define_method(rb_klass, "close", RUBY_METHOD_FUNC(rb_close), 0);
599
+
600
+ rb_define_method(rb_klass, "grab", RUBY_METHOD_FUNC(rb_grab), 0);
601
+ rb_define_method(rb_klass, "retrieve", RUBY_METHOD_FUNC(rb_retrieve), 0);
602
+ rb_define_method(rb_klass, "query", RUBY_METHOD_FUNC(rb_query), 0);
603
+ rb_define_method(rb_klass, "millisecond", RUBY_METHOD_FUNC(rb_get_millisecond), 0);
604
+ rb_define_method(rb_klass, "millisecond=", RUBY_METHOD_FUNC(rb_set_millisecond), 1);
605
+ rb_define_method(rb_klass, "frames", RUBY_METHOD_FUNC(rb_get_frames), 0);
606
+ rb_define_method(rb_klass, "frames=", RUBY_METHOD_FUNC(rb_set_frames), 1);
607
+ rb_define_method(rb_klass, "avi_ratio", RUBY_METHOD_FUNC(rb_get_avi_ratio), 0);
608
+ rb_define_method(rb_klass, "avi_ratio=", RUBY_METHOD_FUNC(rb_set_avi_ratio), 1);
609
+ rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_get_size), 0);
610
+ rb_define_method(rb_klass, "size=", RUBY_METHOD_FUNC(rb_set_size), 1);
611
+ rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_get_width), 0);
612
+ rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
613
+ rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_get_height), 0);
614
+ rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
615
+ rb_define_method(rb_klass, "fps", RUBY_METHOD_FUNC(rb_get_fps), 0);
616
+ rb_define_method(rb_klass, "fps=", RUBY_METHOD_FUNC(rb_set_fps), 1);
617
+ rb_define_method(rb_klass, "fourcc", RUBY_METHOD_FUNC(rb_get_fourcc), 0);
618
+ rb_define_method(rb_klass, "frame_count", RUBY_METHOD_FUNC(rb_get_frame_count), 0);
619
+ rb_define_method(rb_klass, "format", RUBY_METHOD_FUNC(rb_get_format), 0);
620
+ rb_define_method(rb_klass, "mode", RUBY_METHOD_FUNC(rb_get_mode), 0);
621
+ rb_define_method(rb_klass, "brightness", RUBY_METHOD_FUNC(rb_get_brightness), 0);
622
+ rb_define_method(rb_klass, "contrast", RUBY_METHOD_FUNC(rb_get_contrast), 0);
623
+ rb_define_method(rb_klass, "saturation", RUBY_METHOD_FUNC(rb_get_saturation), 0);
624
+ rb_define_method(rb_klass, "hue", RUBY_METHOD_FUNC(rb_get_hue), 0);
625
+ rb_define_method(rb_klass, "gain", RUBY_METHOD_FUNC(rb_get_gain), 0);
626
+ rb_define_method(rb_klass, "exposure", RUBY_METHOD_FUNC(rb_get_exposure), 0);
627
+ rb_define_method(rb_klass, "convert_rgb", RUBY_METHOD_FUNC(rb_get_convert_rgb), 0);
628
+ rb_define_method(rb_klass, "rectification", RUBY_METHOD_FUNC(rb_get_rectification), 0);
629
+ }
630
+
631
+ __NAMESPACE_END_CVCAPTURE
632
+ __NAMESPACE_END_OPENCV
633
+