adamb-ruby-opencv 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGELOG +2 -0
  2. data/License.txt +30 -0
  3. data/README.rdoc +47 -0
  4. data/Rakefile +15 -0
  5. data/examples/convexhull.rb +41 -0
  6. data/examples/face_detect.rb +25 -0
  7. data/examples/houghcircle.rb +23 -0
  8. data/examples/inpaint.png +0 -0
  9. data/examples/inpaint.rb +43 -0
  10. data/examples/paint.rb +72 -0
  11. data/examples/snake.rb +43 -0
  12. data/examples/stuff.jpg +0 -0
  13. data/ext/curve.cpp +103 -0
  14. data/ext/curve.h +34 -0
  15. data/ext/cvavgcomp.cpp +67 -0
  16. data/ext/cvavgcomp.h +39 -0
  17. data/ext/cvbox2d.cpp +114 -0
  18. data/ext/cvbox2d.h +53 -0
  19. data/ext/cvcapture.cpp +276 -0
  20. data/ext/cvcapture.h +54 -0
  21. data/ext/cvchain.cpp +184 -0
  22. data/ext/cvchain.h +43 -0
  23. data/ext/cvchaincode.cpp +49 -0
  24. data/ext/cvchaincode.h +43 -0
  25. data/ext/cvcircle32f.cpp +90 -0
  26. data/ext/cvcircle32f.h +53 -0
  27. data/ext/cvcondensation.cpp +230 -0
  28. data/ext/cvcondensation.h +49 -0
  29. data/ext/cvconnectedcomp.cpp +115 -0
  30. data/ext/cvconnectedcomp.h +46 -0
  31. data/ext/cvcontour.cpp +219 -0
  32. data/ext/cvcontour.h +47 -0
  33. data/ext/cvcontourtree.cpp +86 -0
  34. data/ext/cvcontourtree.h +41 -0
  35. data/ext/cvconvexitydefect.cpp +103 -0
  36. data/ext/cvconvexitydefect.h +42 -0
  37. data/ext/cverror.cpp +140 -0
  38. data/ext/cverror.h +79 -0
  39. data/ext/cvfont.cpp +173 -0
  40. data/ext/cvfont.h +56 -0
  41. data/ext/cvhaarclassifiercascade.cpp +159 -0
  42. data/ext/cvhaarclassifiercascade.h +41 -0
  43. data/ext/cvhistogram.cpp +200 -0
  44. data/ext/cvhistogram.h +51 -0
  45. data/ext/cvindex.cpp +73 -0
  46. data/ext/cvindex.h +40 -0
  47. data/ext/cvline.cpp +106 -0
  48. data/ext/cvline.h +52 -0
  49. data/ext/cvmat.cpp +4809 -0
  50. data/ext/cvmat.h +286 -0
  51. data/ext/cvmatnd.cpp +44 -0
  52. data/ext/cvmatnd.h +28 -0
  53. data/ext/cvmemstorage.cpp +64 -0
  54. data/ext/cvmemstorage.h +53 -0
  55. data/ext/cvmoments.cpp +204 -0
  56. data/ext/cvmoments.h +48 -0
  57. data/ext/cvpoint.cpp +229 -0
  58. data/ext/cvpoint.h +59 -0
  59. data/ext/cvpoint2d32f.cpp +213 -0
  60. data/ext/cvpoint2d32f.h +61 -0
  61. data/ext/cvpoint3d32f.cpp +245 -0
  62. data/ext/cvpoint3d32f.h +64 -0
  63. data/ext/cvrect.cpp +340 -0
  64. data/ext/cvrect.h +79 -0
  65. data/ext/cvscalar.cpp +227 -0
  66. data/ext/cvscalar.h +63 -0
  67. data/ext/cvseq.cpp +583 -0
  68. data/ext/cvseq.h +71 -0
  69. data/ext/cvset.cpp +63 -0
  70. data/ext/cvset.h +39 -0
  71. data/ext/cvsize.cpp +223 -0
  72. data/ext/cvsize.h +63 -0
  73. data/ext/cvsize2d32f.cpp +180 -0
  74. data/ext/cvsize2d32f.h +59 -0
  75. data/ext/cvslice.cpp +82 -0
  76. data/ext/cvslice.h +53 -0
  77. data/ext/cvsparsemat.cpp +44 -0
  78. data/ext/cvsparsemat.h +28 -0
  79. data/ext/cvtermcriteria.cpp +183 -0
  80. data/ext/cvtermcriteria.h +71 -0
  81. data/ext/cvtwopoints.cpp +98 -0
  82. data/ext/cvtwopoints.h +50 -0
  83. data/ext/cvvector.cpp +206 -0
  84. data/ext/cvvector.h +54 -0
  85. data/ext/cvvideowriter.cpp +116 -0
  86. data/ext/cvvideowriter.h +41 -0
  87. data/ext/extconf.rb +66 -0
  88. data/ext/gui.cpp +65 -0
  89. data/ext/gui.h +33 -0
  90. data/ext/iplconvkernel.cpp +177 -0
  91. data/ext/iplconvkernel.h +52 -0
  92. data/ext/iplimage.cpp +238 -0
  93. data/ext/iplimage.h +54 -0
  94. data/ext/mouseevent.cpp +184 -0
  95. data/ext/mouseevent.h +59 -0
  96. data/ext/opencv.cpp +481 -0
  97. data/ext/opencv.h +356 -0
  98. data/ext/point3dset.cpp +41 -0
  99. data/ext/point3dset.h +31 -0
  100. data/ext/pointset.cpp +238 -0
  101. data/ext/pointset.h +69 -0
  102. data/ext/trackbar.cpp +122 -0
  103. data/ext/trackbar.h +65 -0
  104. data/ext/window.cpp +368 -0
  105. data/ext/window.h +56 -0
  106. data/images/CvMat_sobel.png +0 -0
  107. data/images/CvMat_sub_rect.png +0 -0
  108. data/images/CvSeq_relationmap.png +0 -0
  109. data/images/face_detect_from_lena.jpg +0 -0
  110. data/lib/opencv.rb +3 -0
  111. data/lib/version.rb +3 -0
  112. data/metadata +191 -0
  113. data/ruby-opencv.gemspec +33 -0
  114. data/setup/setup.cygwin.rb +120 -0
  115. data/setup/setup.mingw.rb +99 -0
  116. data/setup/setup.mswin32.rb +103 -0
  117. data/test/test_opencv.rb +6 -0
  118. metadata +272 -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 define_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,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 INT2FIX(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,114 @@
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_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
45
+ rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
46
+ rb_define_method(rb_klass, "angle", RUBY_METHOD_FUNC(rb_angle), 0);
47
+ rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
48
+ }
49
+
50
+ VALUE
51
+ rb_allocate(VALUE klass)
52
+ {
53
+ CvBox2D *ptr;
54
+ return Data_Make_Struct(klass, CvBox2D, 0, -1, ptr);
55
+ }
56
+
57
+ /*
58
+ * Return center point of box as CvPoint2D32f.
59
+ */
60
+ VALUE
61
+ rb_center(VALUE self)
62
+ {
63
+ return REFER_OBJECT(cCvPoint2D32f::rb_class(), &CVBOX2D(self)->center, self);
64
+ }
65
+
66
+ /*
67
+ * Return size of box as CvSize2D32f.
68
+ */
69
+ VALUE
70
+ rb_size(VALUE self)
71
+ {
72
+ return REFER_OBJECT(cCvSize2D32f::rb_class(), &CVBOX2D(self)->size, self);
73
+ }
74
+
75
+ /*
76
+ * Return angle of box as Float.
77
+ */
78
+ VALUE
79
+ rb_angle(VALUE self)
80
+ {
81
+ return rb_float_new(CVBOX2D(self)->angle);
82
+ }
83
+
84
+ /*
85
+ * Find box vertices. Return Array contain 4 CvPoint2D32f.
86
+ */
87
+ VALUE
88
+ rb_points(VALUE self)
89
+ {
90
+ const int n = 4;
91
+ CvPoint2D32f p[n];
92
+ cvBoxPoints(*CVBOX2D(self), p);
93
+ VALUE points = rb_ary_new2(n);
94
+ for(int i = 0; i < n; i++)
95
+ rb_ary_store(points, i, cCvPoint2D32f::new_object(p[i]));
96
+ return points;
97
+ }
98
+
99
+ VALUE
100
+ new_object()
101
+ {
102
+ return rb_allocate(cCvBox2D::rb_class());
103
+ }
104
+
105
+ VALUE
106
+ new_object(CvBox2D box)
107
+ {
108
+ VALUE object = rb_allocate(rb_klass);
109
+ *CVBOX2D(object) = box;
110
+ return object;
111
+ }
112
+
113
+ __NAMESPACE_END_CVBOX2D
114
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,53 @@
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_center(VALUE self);
28
+ VALUE rb_size(VALUE self);
29
+ VALUE rb_angle(VALUE self);
30
+ VALUE rb_points(VALUE self);
31
+
32
+ VALUE new_object();
33
+ VALUE new_object(CvBox2D box);
34
+
35
+ __NAMESPACE_END_CVBOX2D
36
+
37
+ inline CvBox2D *CVBOX2D(VALUE object){
38
+ CvBox2D *ptr;
39
+ Data_Get_Struct(object, CvBox2D, ptr);
40
+ return ptr;
41
+ }
42
+
43
+ inline CvBox2D VALUE_TO_CVBOX2D(VALUE object){
44
+ if(rb_obj_is_kind_of(object, cCvBox2D::rb_class())) {
45
+ return *CVBOX2D(object);
46
+ }else{
47
+ rb_raise(rb_eTypeError, "require %s or compatible object.", rb_class2name(cCvBox2D::rb_class()));
48
+ }
49
+ }
50
+
51
+ __NAMESPACE_END_OPENCV
52
+
53
+ #endif // RUBY_OPENCV_CVBOX2D_H
@@ -0,0 +1,276 @@
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, :tyzx, :tyzx_left, :tyzx_right, :tyzx_color, :tyzx_z, :qt, :qtuicktime}: video source */
44
+ rb_define_const(rb_klass, "INTERFACE", video_interface);
45
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("any")), INT2FIX(CV_CAP_ANY));
46
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("mil")), INT2FIX(CV_CAP_MIL));
47
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("vfw")), INT2FIX(CV_CAP_VFW));
48
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l")), INT2FIX(CV_CAP_V4L));
49
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l2")), INT2FIX(CV_CAP_V4L2));
50
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("fireware")), INT2FIX(CV_CAP_FIREWARE));
51
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("ieee1394")), INT2FIX(CV_CAP_IEEE1394));
52
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("dc1394")), INT2FIX(CV_CAP_DC1394));
53
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("cmu1394")), INT2FIX(CV_CAP_CMU1394));
54
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("stereo")), INT2FIX(CV_CAP_STEREO));
55
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx")), INT2FIX(CV_CAP_TYZX));
56
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_left")), INT2FIX(CV_TYZX_LEFT));
57
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_right")), INT2FIX(CV_TYZX_RIGHT));
58
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_color")), INT2FIX(CV_TYZX_COLOR));
59
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_z")), INT2FIX(CV_TYZX_Z));
60
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("qt")), INT2FIX(CV_CAP_QT));
61
+ rb_hash_aset(video_interface, ID2SYM(rb_intern("quicktime")), INT2FIX(CV_CAP_QT));
62
+
63
+ rb_define_singleton_method(rb_klass, "open", RUBY_METHOD_FUNC(rb_open), -1);
64
+
65
+ rb_define_method(rb_klass, "grab", RUBY_METHOD_FUNC(rb_grab), 0);
66
+ rb_define_method(rb_klass, "retrieve", RUBY_METHOD_FUNC(rb_retrieve), 0);
67
+ rb_define_method(rb_klass, "query", RUBY_METHOD_FUNC(rb_query), 0);
68
+ rb_define_method(rb_klass, "millisecond", RUBY_METHOD_FUNC(rb_millisecond), 0);
69
+ rb_define_method(rb_klass, "frames", RUBY_METHOD_FUNC(rb_frames), 0);
70
+ rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
71
+ rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
72
+ rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
73
+ rb_define_method(rb_klass, "fps", RUBY_METHOD_FUNC(rb_fps), 0);
74
+ rb_define_method(rb_klass, "fourcc", RUBY_METHOD_FUNC(rb_fourcc), 0);
75
+ rb_define_method(rb_klass, "frame_count", RUBY_METHOD_FUNC(rb_frame_count), 0);
76
+ }
77
+
78
+ void
79
+ free(void *ptr)
80
+ {
81
+ if(ptr)
82
+ cvReleaseCapture((CvCapture**)&ptr);
83
+ }
84
+
85
+ /*
86
+ * call-seq:
87
+ * CvCapture.open(<i>[dev = -1]</i>)
88
+ *
89
+ * Reading video stream from the specified file or camera device.
90
+ * If <i>dev</i> is string (i.e "stream.avi"), reading video stream from file.
91
+ * If <i>dev</i> is number or symbol(include CvCapture::INTERFACE),
92
+ * reading video stream from camera.
93
+ * Currently two camera interfaces can be used on Windows:
94
+ * * Video for Windows(VFW)
95
+ * * Matrox Imaging Library(MIL)
96
+ * and two on Linux
97
+ * * V4L
98
+ * * FireWire(IEEE1394).
99
+ * If there is only one camera or it does not matter what camera to use <i>nil</i> may be passed.
100
+ */
101
+ VALUE
102
+ rb_open(int argc, VALUE *argv, VALUE self)
103
+ {
104
+ VALUE device, i;
105
+ rb_scan_args(argc, argv, "01", &device);
106
+ CvCapture *capture = 0;
107
+ switch (TYPE(device)) {
108
+ case T_STRING:
109
+ capture = cvCaptureFromFile(StringValueCStr(device));
110
+ break;
111
+ case T_FIXNUM:
112
+ capture = cvCaptureFromCAM(FIX2INT(device));
113
+ break;
114
+ case T_SYMBOL:
115
+ i = rb_hash_aref(rb_const_get(rb_class(), rb_intern("INTERFACE")), device);
116
+ if (NIL_P(i))
117
+ rb_raise(rb_eArgError, "undefined interface.");
118
+ capture = cvCaptureFromCAM(NUM2INT(i));
119
+ break;
120
+ case T_NIL:
121
+ capture = cvCaptureFromCAM(CV_CAP_ANY);
122
+ break;
123
+ }
124
+ if (!capture)
125
+ rb_raise(rb_eStandardError, "Invalid capture format.");
126
+ return Data_Wrap_Struct(rb_klass, 0, free, capture);
127
+ }
128
+
129
+
130
+ /*
131
+ * call-seq:
132
+ * grab -> true or false
133
+ *
134
+ * Grabbed frame is stored internally. To grab frame
135
+ * <i>fast</i> that is important for syncronization in case of reading from
136
+ * several cameras simultaneously. The grabbed frames are not exposed because
137
+ * they may be stored in compressed format (as defined by camera/driver).
138
+ * To retrieve the grabbed frame, retrieve should be used.
139
+ *
140
+ * If grabbed frame was success, return true. Otherwise return false.
141
+ */
142
+ VALUE
143
+ rb_grab(VALUE self)
144
+ {
145
+ return cvGrabFrame(CVCAPTURE(self)) ? Qtrue : Qfalse;
146
+ }
147
+
148
+ /*
149
+ * call-seq:
150
+ * retrieve -> CvMat or nil
151
+ *
152
+ * Gets the image grabbed with grab.
153
+ */
154
+ VALUE
155
+ rb_retrieve(VALUE self)
156
+ {
157
+ IplImage *frame = cvRetrieveFrame(CVCAPTURE(self));
158
+ if(!frame)
159
+ return Qnil;
160
+ VALUE image = cIplImage::new_object(cvSize(frame->width, frame->height), CV_MAKETYPE(CV_8U, frame->nChannels));
161
+ if (frame->origin == IPL_ORIGIN_TL) {
162
+ cvCopy(frame, CVARR(image));
163
+ } else {
164
+ cvFlip(frame, CVARR(image));
165
+ }
166
+ return image;
167
+ }
168
+
169
+ /*
170
+ * call-seq:
171
+ * query -> CvMat or nil
172
+ *
173
+ * Grabs and returns a frame camera or file. Just a combination of grab and retrieve in one call.
174
+ */
175
+ VALUE
176
+ rb_query(VALUE self)
177
+ {
178
+ IplImage *frame = cvQueryFrame(CVCAPTURE(self));
179
+ if(!frame)
180
+ return Qnil;
181
+ VALUE image = cIplImage::new_object(cvSize(frame->width, frame->height), CV_MAKETYPE(CV_8U, frame->nChannels));
182
+ if (frame->origin == IPL_ORIGIN_TL) {
183
+ cvCopy(frame, CVARR(image));
184
+ } else {
185
+ cvFlip(frame, CVARR(image));
186
+ }
187
+ return image;
188
+ }
189
+
190
+ /*
191
+ * Film current position in milliseconds or video capture timestamp.
192
+ */
193
+ VALUE
194
+ rb_millisecond(VALUE self)
195
+ {
196
+ return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_POS_MSEC));
197
+ }
198
+
199
+ /*
200
+ * 0-based index of the frame to be decoded/captured next
201
+ */
202
+ VALUE
203
+ rb_frames(VALUE self)
204
+ {
205
+ return rb_float_new(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_POS_FRAMES));
206
+ }
207
+
208
+ /*
209
+ * Relative position of video file (0 - start of the film, 1 - end of the film)
210
+ */
211
+ VALUE
212
+ rb_avi_ratio(VALUE self)
213
+ {
214
+ return rb_float_new(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_POS_AVI_RATIO));
215
+ }
216
+
217
+ /*
218
+ * Size of frames in the video stream.
219
+ */
220
+ VALUE
221
+ rb_size(VALUE self)
222
+ {
223
+ return cCvSize::new_object(cvSize((int)cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_WIDTH), (int)cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_HEIGHT)));
224
+ }
225
+
226
+ /*
227
+ * Width of frames in the video stream.
228
+ */
229
+ VALUE
230
+ rb_width(VALUE self)
231
+ {
232
+ return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_WIDTH));
233
+ }
234
+
235
+ /*
236
+ * Height of frames in the video stream.
237
+ */
238
+ VALUE
239
+ rb_height(VALUE self)
240
+ {
241
+ return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_HEIGHT));
242
+ }
243
+
244
+ /*
245
+ * Frame rate
246
+ */
247
+ VALUE
248
+ rb_fps(VALUE self)
249
+ {
250
+ return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FPS));
251
+ }
252
+
253
+ /*
254
+ * 4character code of codec. see http://www.fourcc.org/
255
+ */
256
+ VALUE
257
+ rb_fourcc(VALUE self)
258
+ {
259
+ char str[4];
260
+ double fourcc = cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FOURCC);
261
+ sprintf(str, "%s", (char*)&fourcc);
262
+ return rb_str_new2(str);
263
+ }
264
+
265
+ /*
266
+ * Number of frames in video file.
267
+ */
268
+ VALUE
269
+ rb_frame_count(VALUE self)
270
+ {
271
+ return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_COUNT));
272
+ }
273
+
274
+
275
+ __NAMESPACE_END_CVCAPTURE
276
+ __NAMESPACE_END_OPENCV