ruby-opencv 0.0.10-i386-mingw32

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 (231) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +26 -0
  3. data/DEVELOPERS_NOTE.md +137 -0
  4. data/Gemfile +8 -0
  5. data/History.txt +5 -0
  6. data/License.txt +30 -0
  7. data/Manifest.txt +227 -0
  8. data/README.md +98 -0
  9. data/Rakefile +90 -0
  10. data/config.yml +7 -0
  11. data/examples/alpha_blend.rb +21 -0
  12. data/examples/box.png +0 -0
  13. data/examples/box_in_scene.png +0 -0
  14. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  15. data/examples/contours/bitmap-contours.png +0 -0
  16. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  17. data/examples/contours/contour_retrieval_modes.rb +139 -0
  18. data/examples/contours/rotated-boxes.jpg +0 -0
  19. data/examples/convexhull.rb +47 -0
  20. data/examples/face_detect.rb +20 -0
  21. data/examples/find_obj.rb +169 -0
  22. data/examples/houghcircle.rb +22 -0
  23. data/examples/inpaint.png +0 -0
  24. data/examples/inpaint.rb +57 -0
  25. data/examples/lenna-rotated.jpg +0 -0
  26. data/examples/lenna.jpg +0 -0
  27. data/examples/match_kdtree.rb +88 -0
  28. data/examples/matching_to_many_images.rb +16 -0
  29. data/examples/matching_to_many_images/query.png +0 -0
  30. data/examples/matching_to_many_images/train/1.png +0 -0
  31. data/examples/matching_to_many_images/train/2.png +0 -0
  32. data/examples/matching_to_many_images/train/3.png +0 -0
  33. data/examples/matching_to_many_images/train/trainImages.txt +3 -0
  34. data/examples/paint.rb +70 -0
  35. data/examples/snake.rb +43 -0
  36. data/examples/stuff.jpg +0 -0
  37. data/examples/tiffany.jpg +0 -0
  38. data/ext/opencv/curve.cpp +112 -0
  39. data/ext/opencv/curve.h +34 -0
  40. data/ext/opencv/cvavgcomp.cpp +67 -0
  41. data/ext/opencv/cvavgcomp.h +39 -0
  42. data/ext/opencv/cvbox2d.cpp +197 -0
  43. data/ext/opencv/cvbox2d.h +61 -0
  44. data/ext/opencv/cvcapture.cpp +506 -0
  45. data/ext/opencv/cvcapture.h +72 -0
  46. data/ext/opencv/cvchain.cpp +233 -0
  47. data/ext/opencv/cvchain.h +46 -0
  48. data/ext/opencv/cvcircle32f.cpp +116 -0
  49. data/ext/opencv/cvcircle32f.h +52 -0
  50. data/ext/opencv/cvcondensation.cpp +282 -0
  51. data/ext/opencv/cvcondensation.h +49 -0
  52. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  53. data/ext/opencv/cvconnectedcomp.h +49 -0
  54. data/ext/opencv/cvcontour.cpp +296 -0
  55. data/ext/opencv/cvcontour.h +48 -0
  56. data/ext/opencv/cvcontourtree.cpp +91 -0
  57. data/ext/opencv/cvcontourtree.h +41 -0
  58. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  59. data/ext/opencv/cvconvexitydefect.h +42 -0
  60. data/ext/opencv/cverror.cpp +159 -0
  61. data/ext/opencv/cverror.h +28 -0
  62. data/ext/opencv/cvfeaturetree.cpp +125 -0
  63. data/ext/opencv/cvfeaturetree.h +55 -0
  64. data/ext/opencv/cvfont.cpp +208 -0
  65. data/ext/opencv/cvfont.h +64 -0
  66. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  67. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  68. data/ext/opencv/cvhistogram.cpp +546 -0
  69. data/ext/opencv/cvhistogram.h +73 -0
  70. data/ext/opencv/cvhumoments.cpp +139 -0
  71. data/ext/opencv/cvhumoments.h +51 -0
  72. data/ext/opencv/cvline.cpp +154 -0
  73. data/ext/opencv/cvline.h +54 -0
  74. data/ext/opencv/cvmat.cpp +5848 -0
  75. data/ext/opencv/cvmat.h +284 -0
  76. data/ext/opencv/cvmatnd.cpp +44 -0
  77. data/ext/opencv/cvmatnd.h +28 -0
  78. data/ext/opencv/cvmemstorage.cpp +68 -0
  79. data/ext/opencv/cvmemstorage.h +53 -0
  80. data/ext/opencv/cvmoments.cpp +287 -0
  81. data/ext/opencv/cvmoments.h +75 -0
  82. data/ext/opencv/cvpoint.cpp +228 -0
  83. data/ext/opencv/cvpoint.h +64 -0
  84. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  85. data/ext/opencv/cvpoint2d32f.h +63 -0
  86. data/ext/opencv/cvpoint3d32f.cpp +245 -0
  87. data/ext/opencv/cvpoint3d32f.h +66 -0
  88. data/ext/opencv/cvrect.cpp +333 -0
  89. data/ext/opencv/cvrect.h +79 -0
  90. data/ext/opencv/cvscalar.cpp +236 -0
  91. data/ext/opencv/cvscalar.h +71 -0
  92. data/ext/opencv/cvseq.cpp +599 -0
  93. data/ext/opencv/cvseq.h +74 -0
  94. data/ext/opencv/cvsize.cpp +221 -0
  95. data/ext/opencv/cvsize.h +65 -0
  96. data/ext/opencv/cvsize2d32f.cpp +209 -0
  97. data/ext/opencv/cvsize2d32f.h +64 -0
  98. data/ext/opencv/cvslice.cpp +120 -0
  99. data/ext/opencv/cvslice.h +61 -0
  100. data/ext/opencv/cvsparsemat.cpp +44 -0
  101. data/ext/opencv/cvsparsemat.h +28 -0
  102. data/ext/opencv/cvsurfparams.cpp +199 -0
  103. data/ext/opencv/cvsurfparams.h +58 -0
  104. data/ext/opencv/cvsurfpoint.cpp +223 -0
  105. data/ext/opencv/cvsurfpoint.h +52 -0
  106. data/ext/opencv/cvtermcriteria.cpp +192 -0
  107. data/ext/opencv/cvtermcriteria.h +71 -0
  108. data/ext/opencv/cvtwopoints.cpp +116 -0
  109. data/ext/opencv/cvtwopoints.h +51 -0
  110. data/ext/opencv/cvutils.cpp +192 -0
  111. data/ext/opencv/cvutils.h +30 -0
  112. data/ext/opencv/cvvideowriter.cpp +137 -0
  113. data/ext/opencv/cvvideowriter.h +43 -0
  114. data/ext/opencv/extconf.rb +83 -0
  115. data/ext/opencv/gui.cpp +68 -0
  116. data/ext/opencv/gui.h +30 -0
  117. data/ext/opencv/iplconvkernel.cpp +192 -0
  118. data/ext/opencv/iplconvkernel.h +71 -0
  119. data/ext/opencv/iplimage.cpp +644 -0
  120. data/ext/opencv/iplimage.h +73 -0
  121. data/ext/opencv/mouseevent.cpp +181 -0
  122. data/ext/opencv/mouseevent.h +56 -0
  123. data/ext/opencv/opencv.cpp +727 -0
  124. data/ext/opencv/opencv.h +400 -0
  125. data/ext/opencv/pointset.cpp +274 -0
  126. data/ext/opencv/pointset.h +68 -0
  127. data/ext/opencv/trackbar.cpp +121 -0
  128. data/ext/opencv/trackbar.h +69 -0
  129. data/ext/opencv/window.cpp +357 -0
  130. data/ext/opencv/window.h +66 -0
  131. data/images/CvMat_sobel.png +0 -0
  132. data/images/CvMat_sub_rect.png +0 -0
  133. data/images/CvSeq_relationmap.png +0 -0
  134. data/images/face_detect_from_lena.jpg +0 -0
  135. data/lib/1.9/opencv.so +0 -0
  136. data/lib/2.0/opencv.so +0 -0
  137. data/lib/opencv.rb +12 -0
  138. data/lib/opencv/psyched_yaml.rb +22 -0
  139. data/lib/opencv/version.rb +3 -0
  140. data/ruby-opencv.gemspec +44 -0
  141. data/test/helper.rb +166 -0
  142. data/test/runner.rb +30 -0
  143. data/test/samples/airplane.jpg +0 -0
  144. data/test/samples/baboon.jpg +0 -0
  145. data/test/samples/baboon200.jpg +0 -0
  146. data/test/samples/baboon200_rotated.jpg +0 -0
  147. data/test/samples/blank0.jpg +0 -0
  148. data/test/samples/blank1.jpg +0 -0
  149. data/test/samples/blank2.jpg +0 -0
  150. data/test/samples/blank3.jpg +0 -0
  151. data/test/samples/blank4.jpg +0 -0
  152. data/test/samples/blank5.jpg +0 -0
  153. data/test/samples/blank6.jpg +0 -0
  154. data/test/samples/blank7.jpg +0 -0
  155. data/test/samples/blank8.jpg +0 -0
  156. data/test/samples/blank9.jpg +0 -0
  157. data/test/samples/cat.jpg +0 -0
  158. data/test/samples/chessboard.jpg +0 -0
  159. data/test/samples/contours.jpg +0 -0
  160. data/test/samples/fruits.jpg +0 -0
  161. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  162. data/test/samples/inpaint-mask.bmp +0 -0
  163. data/test/samples/lena-256x256.jpg +0 -0
  164. data/test/samples/lena-32x32.jpg +0 -0
  165. data/test/samples/lena-eyes.jpg +0 -0
  166. data/test/samples/lena-inpaint.jpg +0 -0
  167. data/test/samples/lena.jpg +0 -0
  168. data/test/samples/lines.jpg +0 -0
  169. data/test/samples/messy0.jpg +0 -0
  170. data/test/samples/messy1.jpg +0 -0
  171. data/test/samples/movie_sample.avi +0 -0
  172. data/test/samples/one_way_train_0000.jpg +0 -0
  173. data/test/samples/one_way_train_0001.jpg +0 -0
  174. data/test/samples/partially_blank0.jpg +0 -0
  175. data/test/samples/partially_blank1.jpg +0 -0
  176. data/test/samples/smooth0.jpg +0 -0
  177. data/test/samples/smooth1.jpg +0 -0
  178. data/test/samples/smooth2.jpg +0 -0
  179. data/test/samples/smooth3.jpg +0 -0
  180. data/test/samples/smooth4.jpg +0 -0
  181. data/test/samples/smooth5.jpg +0 -0
  182. data/test/samples/smooth6.jpg +0 -0
  183. data/test/samples/str-cv-rotated.jpg +0 -0
  184. data/test/samples/str-cv.jpg +0 -0
  185. data/test/samples/str-ov.jpg +0 -0
  186. data/test/samples/stuff.jpg +0 -0
  187. data/test/test_curve.rb +43 -0
  188. data/test/test_cvavgcomp.rb +24 -0
  189. data/test/test_cvbox2d.rb +76 -0
  190. data/test/test_cvcapture.rb +183 -0
  191. data/test/test_cvchain.rb +108 -0
  192. data/test/test_cvcircle32f.rb +41 -0
  193. data/test/test_cvconnectedcomp.rb +61 -0
  194. data/test/test_cvcontour.rb +150 -0
  195. data/test/test_cvcontourtree.rb +43 -0
  196. data/test/test_cverror.rb +50 -0
  197. data/test/test_cvfeaturetree.rb +65 -0
  198. data/test/test_cvfont.rb +58 -0
  199. data/test/test_cvhaarclassifiercascade.rb +63 -0
  200. data/test/test_cvhistogram.rb +271 -0
  201. data/test/test_cvhumoments.rb +83 -0
  202. data/test/test_cvline.rb +50 -0
  203. data/test/test_cvmat.rb +2947 -0
  204. data/test/test_cvmat_drawing.rb +349 -0
  205. data/test/test_cvmat_dxt.rb +150 -0
  206. data/test/test_cvmat_imageprocessing.rb +2015 -0
  207. data/test/test_cvmat_matching.rb +57 -0
  208. data/test/test_cvmoments.rb +180 -0
  209. data/test/test_cvpoint.rb +75 -0
  210. data/test/test_cvpoint2d32f.rb +75 -0
  211. data/test/test_cvpoint3d32f.rb +93 -0
  212. data/test/test_cvrect.rb +144 -0
  213. data/test/test_cvscalar.rb +113 -0
  214. data/test/test_cvseq.rb +295 -0
  215. data/test/test_cvsize.rb +75 -0
  216. data/test/test_cvsize2d32f.rb +75 -0
  217. data/test/test_cvslice.rb +31 -0
  218. data/test/test_cvsurfparams.rb +57 -0
  219. data/test/test_cvsurfpoint.rb +66 -0
  220. data/test/test_cvtermcriteria.rb +56 -0
  221. data/test/test_cvtwopoints.rb +40 -0
  222. data/test/test_cvvideowriter.rb +58 -0
  223. data/test/test_iplconvkernel.rb +54 -0
  224. data/test/test_iplimage.rb +236 -0
  225. data/test/test_mouseevent.rb +17 -0
  226. data/test/test_opencv.rb +329 -0
  227. data/test/test_pointset.rb +126 -0
  228. data/test/test_preliminary.rb +130 -0
  229. data/test/test_trackbar.rb +47 -0
  230. data/test/test_window.rb +115 -0
  231. metadata +386 -0
@@ -0,0 +1,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,506 @@
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
+ IplImage *frame = NULL;
191
+ try {
192
+ if (!(frame = cvRetrieveFrame(CVCAPTURE(self)))) {
193
+ return Qnil;
194
+ }
195
+ image = cIplImage::new_object(frame->width, frame->height,
196
+ CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
197
+ if (frame->origin == IPL_ORIGIN_TL) {
198
+ cvCopy(frame, CVARR(image));
199
+ }
200
+ else {
201
+ cvFlip(frame, CVARR(image));
202
+ }
203
+ }
204
+ catch (cv::Exception& e) {
205
+ raise_cverror(e);
206
+ }
207
+ return image;
208
+
209
+ }
210
+
211
+ /*
212
+ * call-seq:
213
+ * query -> IplImage or nil
214
+ *
215
+ * Grabs and returns a frame camera or file. Just a combination of grab and retrieve in one call.
216
+ */
217
+ VALUE
218
+ rb_query(VALUE self)
219
+ {
220
+ VALUE image = Qnil;
221
+ IplImage *frame = NULL;
222
+ try {
223
+ if (!(frame = cvQueryFrame(CVCAPTURE(self)))) {
224
+ return Qnil;
225
+ }
226
+ image = cIplImage::new_object(frame->width, frame->height,
227
+ CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
228
+ if (frame->origin == IPL_ORIGIN_TL) {
229
+ cvCopy(frame, CVARR(image));
230
+ }
231
+ else {
232
+ cvFlip(frame, CVARR(image));
233
+ }
234
+ }
235
+ catch (cv::Exception& e) {
236
+ raise_cverror(e);
237
+ }
238
+ return image;
239
+ }
240
+
241
+ VALUE
242
+ rb_get_capture_property(VALUE self, int id)
243
+ {
244
+ double result = 0;
245
+ try {
246
+ result = cvGetCaptureProperty(CVCAPTURE(self), id);
247
+ }
248
+ catch (cv::Exception& e) {
249
+ raise_cverror(e);
250
+ }
251
+ return rb_float_new(result);
252
+ }
253
+
254
+ VALUE
255
+ rb_set_capture_property(VALUE self, int id, VALUE value)
256
+ {
257
+ double result = 0;
258
+ try {
259
+ result = cvSetCaptureProperty(CVCAPTURE(self), id, NUM2DBL(value));
260
+ }
261
+ catch (cv::Exception& e) {
262
+ raise_cverror(e);
263
+ }
264
+ return rb_float_new(result);
265
+ }
266
+
267
+ /*
268
+ * Get film current position in milliseconds or video capture timestamp.
269
+ */
270
+ VALUE
271
+ rb_get_millisecond(VALUE self)
272
+ {
273
+ return rb_get_capture_property(self, CV_CAP_PROP_POS_MSEC);
274
+ }
275
+ /*
276
+ * Set film current position in milliseconds or video capture timestamp.
277
+ */
278
+ VALUE
279
+ rb_set_millisecond(VALUE self, VALUE value)
280
+ {
281
+ return rb_set_capture_property(self, CV_CAP_PROP_POS_MSEC, value);
282
+ }
283
+ /*
284
+ * Get 0-based index of the frame to be decoded/captured next
285
+ */
286
+ VALUE
287
+ rb_get_frames(VALUE self)
288
+ {
289
+ return rb_get_capture_property(self, CV_CAP_PROP_POS_FRAMES);
290
+ }
291
+ /*
292
+ * Set 0-based index of the frame to be decoded/captured next
293
+ */
294
+ VALUE
295
+ rb_set_frames(VALUE self, VALUE value)
296
+ {
297
+ return rb_set_capture_property(self, CV_CAP_PROP_POS_FRAMES, value);
298
+ }
299
+ /*
300
+ * Get relative position of video file (0 - start of the film, 1 - end of the film)
301
+ */
302
+ VALUE
303
+ rb_get_avi_ratio(VALUE self)
304
+ {
305
+ return rb_get_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO);
306
+ }
307
+ /*
308
+ * Set relative position of video file (0 - start of the film, 1 - end of the film)
309
+ */
310
+ VALUE
311
+ rb_set_avi_ratio(VALUE self, VALUE value)
312
+ {
313
+ return rb_set_capture_property(self, CV_CAP_PROP_POS_AVI_RATIO, value);
314
+ }
315
+ /*
316
+ * Get size of frames in the video stream.
317
+ */
318
+ VALUE
319
+ rb_get_size(VALUE self)
320
+ {
321
+ CvSize size;
322
+ try {
323
+ CvCapture* self_ptr = CVCAPTURE(self);
324
+ size = cvSize((int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH),
325
+ (int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT));
326
+ }
327
+ catch (cv::Exception& e) {
328
+ raise_cverror(e);
329
+ }
330
+ return cCvSize::new_object(size);
331
+ }
332
+ /*
333
+ * Set size of frames in the video stream.
334
+ */
335
+ VALUE
336
+ rb_set_size(VALUE self, VALUE value)
337
+ {
338
+ double result = 0;
339
+ CvSize size = VALUE_TO_CVSIZE(value);
340
+ try {
341
+ CvCapture* self_ptr = CVCAPTURE(self);
342
+ cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH, size.width);
343
+ result = cvSetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT, size.height);
344
+ }
345
+ catch (cv::Exception& e) {
346
+ raise_cverror(e);
347
+ }
348
+ return DBL2NUM(result);
349
+ }
350
+ /*
351
+ * Get width of frames in the video stream.
352
+ */
353
+ VALUE
354
+ rb_get_width(VALUE self)
355
+ {
356
+ return rb_get_capture_property(self, CV_CAP_PROP_FRAME_WIDTH);
357
+ }
358
+ /*
359
+ * Set width of frames in the video stream.
360
+ */
361
+ VALUE
362
+ rb_set_width(VALUE self, VALUE value)
363
+ {
364
+ return rb_set_capture_property(self, CV_CAP_PROP_FRAME_WIDTH, value);
365
+ }
366
+ /*
367
+ * Get height of frames in the video stream.
368
+ */
369
+ VALUE
370
+ rb_get_height(VALUE self)
371
+ {
372
+ return rb_get_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT);
373
+ }
374
+ /*
375
+ * Set height of frames in the video stream.
376
+ */
377
+ VALUE
378
+ rb_set_height(VALUE self, VALUE value)
379
+ {
380
+ return rb_set_capture_property(self, CV_CAP_PROP_FRAME_HEIGHT, value);
381
+ }
382
+ /*
383
+ * Get frame rate
384
+ */
385
+ VALUE
386
+ rb_get_fps(VALUE self)
387
+ {
388
+ return rb_get_capture_property(self, CV_CAP_PROP_FPS);
389
+ }
390
+ /*
391
+ * Set frame rate
392
+ */
393
+ VALUE
394
+ rb_set_fps(VALUE self, VALUE value)
395
+ {
396
+ return rb_set_capture_property(self, CV_CAP_PROP_FPS, value);
397
+ }
398
+ /*
399
+ * Get 4character code of codec. see http://www.fourcc.org/
400
+ */
401
+ VALUE
402
+ rb_get_fourcc(VALUE self)
403
+ {
404
+ char str[4];
405
+ double fourcc = cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FOURCC);
406
+ sprintf(str, "%s", (char*)&fourcc);
407
+ return rb_str_new2(str);
408
+ }
409
+ /*
410
+ * Get number of frames in video file.
411
+ */
412
+ VALUE
413
+ rb_get_frame_count(VALUE self)
414
+ {
415
+ return rb_get_capture_property(self, CV_CAP_PROP_FRAME_COUNT);
416
+ }
417
+ /*
418
+ * Get the format of the Mat objects returned by CvCapture#retrieve
419
+ */
420
+ VALUE
421
+ rb_get_format(VALUE self)
422
+ {
423
+ return rb_get_capture_property(self, CV_CAP_PROP_FORMAT);
424
+ }
425
+ /*
426
+ * Get a backend-specific value indicating the current capture mode
427
+ */
428
+ VALUE
429
+ rb_get_mode(VALUE self)
430
+ {
431
+ return rb_get_capture_property(self, CV_CAP_PROP_MODE);
432
+ }
433
+ /*
434
+ * Get brightness of the image (only for cameras)
435
+ */
436
+ VALUE
437
+ rb_get_brightness(VALUE self)
438
+ {
439
+ return rb_get_capture_property(self, CV_CAP_PROP_BRIGHTNESS);
440
+ }
441
+ /*
442
+ * Get contrast of the image (only for cameras)
443
+ */
444
+ VALUE
445
+ rb_get_contrast(VALUE self)
446
+ {
447
+ return rb_get_capture_property(self, CV_CAP_PROP_CONTRAST);
448
+ }
449
+ /*
450
+ * Get saturation of the image (only for cameras)
451
+ */
452
+ VALUE
453
+ rb_get_saturation(VALUE self)
454
+ {
455
+ return rb_get_capture_property(self, CV_CAP_PROP_SATURATION);
456
+ }
457
+ /*
458
+ * Get hue of the image (only for cameras)
459
+ */
460
+ VALUE
461
+ rb_get_hue(VALUE self)
462
+ {
463
+ return rb_get_capture_property(self, CV_CAP_PROP_HUE);
464
+ }
465
+ /*
466
+ * Get gain of the image (only for cameras)
467
+ */
468
+ VALUE
469
+ rb_get_gain(VALUE self)
470
+ {
471
+ return rb_get_capture_property(self, CV_CAP_PROP_GAIN);
472
+ }
473
+ /*
474
+ * Get exposure (only for cameras)
475
+ */
476
+ VALUE
477
+ rb_get_exposure(VALUE self)
478
+ {
479
+ return rb_get_capture_property(self, CV_CAP_PROP_EXPOSURE);
480
+ }
481
+ /*
482
+ * Get boolean flags indicating whether images should be converted to RGB
483
+ */
484
+ VALUE
485
+ rb_get_convert_rgb(VALUE self)
486
+ {
487
+ int flag = 0;
488
+ try {
489
+ flag = (int)cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_CONVERT_RGB);
490
+ }
491
+ catch (cv::Exception& e) {
492
+ raise_cverror(e);
493
+ }
494
+ return flag ? Qtrue : Qfalse;
495
+ }
496
+ /*
497
+ * Get TOWRITE (note: only supported by DC1394 v 2.x backend currently)
498
+ */
499
+ VALUE
500
+ rb_get_rectification(VALUE self)
501
+ {
502
+ return rb_get_capture_property(self, CV_CAP_PROP_RECTIFICATION);
503
+ }
504
+ __NAMESPACE_END_CVCAPTURE
505
+ __NAMESPACE_END_OPENCV
506
+