opencv 0.0.6

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 (117) hide show
  1. data/History.txt +5 -0
  2. data/License.txt +30 -0
  3. data/Manifest.txt +115 -0
  4. data/README.txt +47 -0
  5. data/Rakefile +34 -0
  6. data/examples/convexhull.rb +41 -0
  7. data/examples/face_detect.rb +25 -0
  8. data/examples/houghcircle.rb +23 -0
  9. data/examples/inpaint.png +0 -0
  10. data/examples/inpaint.rb +43 -0
  11. data/examples/paint.rb +72 -0
  12. data/examples/snake.rb +43 -0
  13. data/examples/stuff.jpg +0 -0
  14. data/ext/curve.cpp +103 -0
  15. data/ext/curve.h +34 -0
  16. data/ext/cvavgcomp.cpp +67 -0
  17. data/ext/cvavgcomp.h +39 -0
  18. data/ext/cvbox2d.cpp +114 -0
  19. data/ext/cvbox2d.h +53 -0
  20. data/ext/cvcapture.cpp +276 -0
  21. data/ext/cvcapture.h +54 -0
  22. data/ext/cvchain.cpp +184 -0
  23. data/ext/cvchain.h +43 -0
  24. data/ext/cvchaincode.cpp +49 -0
  25. data/ext/cvchaincode.h +43 -0
  26. data/ext/cvcircle32f.cpp +90 -0
  27. data/ext/cvcircle32f.h +53 -0
  28. data/ext/cvcondensation.cpp +230 -0
  29. data/ext/cvcondensation.h +49 -0
  30. data/ext/cvconnectedcomp.cpp +115 -0
  31. data/ext/cvconnectedcomp.h +46 -0
  32. data/ext/cvcontour.cpp +219 -0
  33. data/ext/cvcontour.h +47 -0
  34. data/ext/cvcontourtree.cpp +86 -0
  35. data/ext/cvcontourtree.h +41 -0
  36. data/ext/cvconvexitydefect.cpp +103 -0
  37. data/ext/cvconvexitydefect.h +42 -0
  38. data/ext/cverror.cpp +140 -0
  39. data/ext/cverror.h +79 -0
  40. data/ext/cvfont.cpp +173 -0
  41. data/ext/cvfont.h +56 -0
  42. data/ext/cvhaarclassifiercascade.cpp +159 -0
  43. data/ext/cvhaarclassifiercascade.h +41 -0
  44. data/ext/cvhistogram.cpp +200 -0
  45. data/ext/cvhistogram.h +51 -0
  46. data/ext/cvindex.cpp +73 -0
  47. data/ext/cvindex.h +40 -0
  48. data/ext/cvline.cpp +106 -0
  49. data/ext/cvline.h +52 -0
  50. data/ext/cvmat.cpp +4809 -0
  51. data/ext/cvmat.h +286 -0
  52. data/ext/cvmatnd.cpp +44 -0
  53. data/ext/cvmatnd.h +28 -0
  54. data/ext/cvmemstorage.cpp +64 -0
  55. data/ext/cvmemstorage.h +53 -0
  56. data/ext/cvmoments.cpp +204 -0
  57. data/ext/cvmoments.h +48 -0
  58. data/ext/cvpoint.cpp +229 -0
  59. data/ext/cvpoint.h +59 -0
  60. data/ext/cvpoint2d32f.cpp +213 -0
  61. data/ext/cvpoint2d32f.h +61 -0
  62. data/ext/cvpoint3d32f.cpp +245 -0
  63. data/ext/cvpoint3d32f.h +64 -0
  64. data/ext/cvrect.cpp +340 -0
  65. data/ext/cvrect.h +79 -0
  66. data/ext/cvscalar.cpp +227 -0
  67. data/ext/cvscalar.h +63 -0
  68. data/ext/cvseq.cpp +583 -0
  69. data/ext/cvseq.h +71 -0
  70. data/ext/cvset.cpp +63 -0
  71. data/ext/cvset.h +39 -0
  72. data/ext/cvsize.cpp +223 -0
  73. data/ext/cvsize.h +63 -0
  74. data/ext/cvsize2d32f.cpp +180 -0
  75. data/ext/cvsize2d32f.h +59 -0
  76. data/ext/cvslice.cpp +82 -0
  77. data/ext/cvslice.h +53 -0
  78. data/ext/cvsparsemat.cpp +44 -0
  79. data/ext/cvsparsemat.h +28 -0
  80. data/ext/cvtermcriteria.cpp +183 -0
  81. data/ext/cvtermcriteria.h +71 -0
  82. data/ext/cvtwopoints.cpp +98 -0
  83. data/ext/cvtwopoints.h +50 -0
  84. data/ext/cvvector.cpp +206 -0
  85. data/ext/cvvector.h +54 -0
  86. data/ext/cvvideowriter.cpp +116 -0
  87. data/ext/cvvideowriter.h +41 -0
  88. data/ext/extconf.rb +61 -0
  89. data/ext/gui.cpp +65 -0
  90. data/ext/gui.h +33 -0
  91. data/ext/iplconvkernel.cpp +177 -0
  92. data/ext/iplconvkernel.h +52 -0
  93. data/ext/iplimage.cpp +238 -0
  94. data/ext/iplimage.h +54 -0
  95. data/ext/mouseevent.cpp +184 -0
  96. data/ext/mouseevent.h +59 -0
  97. data/ext/opencv.cpp +481 -0
  98. data/ext/opencv.h +356 -0
  99. data/ext/point3dset.cpp +41 -0
  100. data/ext/point3dset.h +31 -0
  101. data/ext/pointset.cpp +238 -0
  102. data/ext/pointset.h +69 -0
  103. data/ext/trackbar.cpp +122 -0
  104. data/ext/trackbar.h +65 -0
  105. data/ext/window.cpp +368 -0
  106. data/ext/window.h +56 -0
  107. data/images/CvMat_sobel.png +0 -0
  108. data/images/CvMat_sub_rect.png +0 -0
  109. data/images/CvSeq_relationmap.png +0 -0
  110. data/images/face_detect_from_lena.jpg +0 -0
  111. data/lib/opencv.rb +3 -0
  112. data/lib/version.rb +3 -0
  113. data/setup/setup.cygwin.rb +120 -0
  114. data/setup/setup.mingw.rb +99 -0
  115. data/setup/setup.mswin32.rb +103 -0
  116. data/test/test_opencv.rb +4 -0
  117. metadata +191 -0
@@ -0,0 +1,183 @@
1
+ /************************************************************
2
+
3
+ cvtermcriteria.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include"cvtermcriteria.h"
11
+ /*
12
+ * Document-class: OpenCV::CvTermCriteria
13
+ *
14
+ * CvTermCriteria has parameter "max" and "eps".
15
+ * "max" is the maximum repetition frequency.
16
+ * "eps" is a minimum difference value during current and previous state
17
+ * (It is different to which state "eps" refer depending on the method).
18
+ *
19
+ * Because the name of CvTermCriteria seems to be very long, it has alias named CvTerm.
20
+ */
21
+ __NAMESPACE_BEGIN_OPENCV
22
+ __NAMESPACE_BEGIN_CVTERMCRITERIA
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
+
44
+ rb_klass = rb_define_class_under(opencv, "CvTermCriteria", rb_cObject);
45
+ /* CvTermCriteria: class */
46
+ rb_define_const(opencv, "CvTerm", rb_klass);
47
+ rb_define_alloc_func(rb_klass, rb_allocate);
48
+ rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
49
+ rb_define_method(rb_klass, "max", RUBY_METHOD_FUNC(rb_max), 0);
50
+ rb_define_method(rb_klass, "max=", RUBY_METHOD_FUNC(rb_set_max), 1);
51
+ rb_define_method(rb_klass, "eps", RUBY_METHOD_FUNC(rb_eps), 0);
52
+ rb_define_method(rb_klass, "eps=", RUBY_METHOD_FUNC(rb_set_eps), 1);
53
+ rb_define_alias(rb_klass, "epsilon", "eps");
54
+ rb_define_alias(rb_klass, "epsilon=", "eps=");
55
+ rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
56
+ }
57
+
58
+ VALUE
59
+ rb_allocate(VALUE klass)
60
+ {
61
+ CvTermCriteria *ptr;
62
+ return Data_Make_Struct(klass, CvTermCriteria, 0, -1, ptr);
63
+ }
64
+
65
+ /*
66
+ * call-seq:
67
+ * CvTermCriteria.new([max = 0][,eps = 0.0]) -> obj
68
+ * CvTermCriteria.new(int) = CvTermCriteria.new(int, 0.0)
69
+ * CvTermCriteria.new(float) = CvTermCriteria.new(0, float)
70
+ *
71
+ * Create new term criteria.
72
+ */
73
+ VALUE
74
+ rb_initialize(int argc, VALUE *argv, VALUE self)
75
+ {
76
+ VALUE max, eps;
77
+ rb_scan_args(argc, argv, "02", &max, &eps);
78
+ int type = 0;
79
+ if (!NIL_P(max)) {type |= CV_TERMCRIT_ITER;}
80
+ if (!NIL_P(eps)) {type |= CV_TERMCRIT_EPS;}
81
+ *CVTERMCRITERIA(self) = cvTermCriteria(type, IF_INT(max, 0), IF_DBL(eps, 0.0));
82
+ return self;
83
+ }
84
+
85
+ /*
86
+ * call-seq:
87
+ * max -> int or nil
88
+ *
89
+ * Return the maximum repetition frequency.
90
+ */
91
+ VALUE
92
+ rb_max(VALUE self)
93
+ {
94
+ CvTermCriteria *ptr = CVTERMCRITERIA(self);
95
+ if (ptr->type & CV_TERMCRIT_ITER)
96
+ return INT2NUM(ptr->max_iter);
97
+ else
98
+ return Qnil;
99
+ }
100
+
101
+ /*
102
+ * call-seq:
103
+ * max = <i>val</i> -> self
104
+ *
105
+ * Set the maximum repetition frequency.
106
+ * If <i>val</i> is 0 (or negative value), repetition frequency is disregarded.
107
+ */
108
+ VALUE
109
+ rb_set_max(VALUE self, VALUE max_value)
110
+ {
111
+ CvTermCriteria *ptr = CVTERMCRITERIA(self);
112
+ int max = NUM2INT(max_value);
113
+ if (max > 0) {
114
+ ptr->type |= CV_TERMCRIT_ITER;
115
+ ptr->max_iter = max;
116
+ } else {
117
+ ptr->type ^= CV_TERMCRIT_ITER;
118
+ ptr->max_iter = 0;
119
+ }
120
+ return self;
121
+ }
122
+
123
+ /*
124
+ * call-seq:
125
+ * eps -> float or nil
126
+ *
127
+ * Return the minimum difference value during current and previous state.
128
+ */
129
+ VALUE
130
+ rb_eps(VALUE self)
131
+ {
132
+ CvTermCriteria *ptr = CVTERMCRITERIA(self);
133
+ if(ptr->type & CV_TERMCRIT_EPS)
134
+ return rb_float_new(ptr->epsilon);
135
+ else
136
+ return Qnil;
137
+ }
138
+
139
+ /*
140
+ * call-seq:
141
+ * eps = <i>val</i> -> self
142
+ *
143
+ * Set the minimum difference value during current and previous state.
144
+ * If <i>val</i> is 0.0 (or negative value), the minimum difference value
145
+ * during current and previous state is disregarded.
146
+ */
147
+ VALUE
148
+ rb_set_eps(VALUE self, VALUE eps_value)
149
+ {
150
+ CvTermCriteria *ptr = CVTERMCRITERIA(self);
151
+ double eps = NUM2DBL(eps_value);
152
+ if (eps > 0) {
153
+ ptr->type = ptr->type | CV_TERMCRIT_EPS;
154
+ ptr->epsilon = eps;
155
+ } else {
156
+ ptr->type = ptr->type ^ CV_TERMCRIT_EPS;
157
+ ptr->epsilon = 0;
158
+ }
159
+ return self;
160
+ }
161
+
162
+ VALUE
163
+ rb_to_ary(VALUE self)
164
+ {
165
+ CvTermCriteria *ptr = CVTERMCRITERIA(self);
166
+ VALUE ary = rb_ary_new();
167
+ if (ptr->type & CV_TERMCRIT_ITER)
168
+ rb_ary_push(ary, INT2FIX(ptr->max_iter));
169
+ if (ptr->type & CV_TERMCRIT_EPS)
170
+ rb_ary_push(ary, rb_float_new(ptr->epsilon));
171
+ return ary;
172
+ }
173
+
174
+ VALUE
175
+ new_object(CvTermCriteria criteria)
176
+ {
177
+ VALUE object = rb_allocate(rb_klass);
178
+ *CVTERMCRITERIA(object) = criteria;
179
+ return object;
180
+ }
181
+
182
+ __NAMESPACE_END_CVTERMCRITERIA
183
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,71 @@
1
+ /************************************************************
2
+
3
+ cvtermcriteria.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVTERMCRITERIA_H
11
+ #define RUBY_OPENCV_CVTERMCRITERIA_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVTERMCRITERIA namespace cCvTermCriteria{
16
+ #define __NAMESPACE_END_CVTERMCRITERIA }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVTERMCRITERIA
20
+
21
+ VALUE rb_class();
22
+
23
+ void define_ruby_class();
24
+
25
+ VALUE rb_allocate(VALUE klass);
26
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
27
+
28
+ VALUE rb_max(VALUE self);
29
+ VALUE rb_set_max(VALUE self, VALUE max_value);
30
+ VALUE rb_eps(VALUE self);
31
+ VALUE rb_set_eps(VALUE self, VALUE eps_value);
32
+ VALUE rb_to_ary(VALUE self);
33
+
34
+ VALUE new_object(CvTermCriteria criteria);
35
+
36
+ __NAMESPACE_END_CVTERMCRITERIA
37
+
38
+ inline CvTermCriteria*
39
+ CVTERMCRITERIA(VALUE object)
40
+ {
41
+ CvTermCriteria *ptr;
42
+ Data_Get_Struct(object, CvTermCriteria, ptr);
43
+ return ptr;
44
+ }
45
+
46
+ inline CvTermCriteria
47
+ VALUE_TO_CVTERMCRITERIA(VALUE object)
48
+ {
49
+ if (rb_obj_is_kind_of(object, cCvTermCriteria::rb_class())) {
50
+ return *CVTERMCRITERIA(object);
51
+ }
52
+ switch (TYPE(object)) {
53
+ case T_NIL:
54
+ return cvTermCriteria(CV_TERMCRIT_ITER, 0, 0);
55
+ case T_FIXNUM:
56
+ return cvTermCriteria(CV_TERMCRIT_ITER, NUM2INT(object), 0);
57
+ case T_FLOAT:
58
+ return cvTermCriteria(CV_TERMCRIT_EPS, 0, NUM2DBL(object));
59
+ case T_ARRAY:
60
+ if (RARRAY(object)->len == 2) {
61
+ return cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,
62
+ NUM2INT(rb_ary_entry(object, 0)),
63
+ NUM2DBL(rb_ary_entry(object, 1)));
64
+ }
65
+ }
66
+ rb_raise(rb_eTypeError, "");
67
+ }
68
+
69
+ __NAMESPACE_END_OPENCV
70
+
71
+ #endif // RUBY_OPENCV_CVTERMCRITERIA_H
@@ -0,0 +1,98 @@
1
+ /************************************************************
2
+
3
+ cvtwopoints.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvtwopoints.h"
11
+ /*
12
+ * Document-class: OpenCV::CvTwopoints
13
+ *
14
+ * This class means one twopoints on X axis Y axis.
15
+ * X and Y takes the value of the Fixnum. see also CvTwopoints2D32F
16
+ *
17
+ * C structure is here, very simple.
18
+ * typdef struct CvTwopoints{
19
+ * int x;
20
+ * int y;
21
+ * }
22
+ */
23
+ __NAMESPACE_BEGIN_OPENCV
24
+ __NAMESPACE_BEGIN_CVTWOPOINTS
25
+
26
+ VALUE rb_klass;
27
+
28
+ VALUE
29
+ rb_class()
30
+ {
31
+ return rb_klass;
32
+ }
33
+
34
+ void
35
+ define_ruby_class()
36
+ {
37
+ if (rb_klass)
38
+ return;
39
+ /*
40
+ * opencv = rb_define_module("OpenCV");
41
+ *
42
+ * note: this comment is used by rdoc.
43
+ */
44
+ VALUE opencv = rb_module_opencv();
45
+
46
+ rb_klass = rb_define_class_under(opencv, "CvTwoPoints", rb_cObject);
47
+ rb_define_alloc_func(rb_klass, rb_allocate);
48
+ rb_define_method(rb_klass, "point1", RUBY_METHOD_FUNC(rb_point1), 0);
49
+ rb_define_method(rb_klass, "point2", RUBY_METHOD_FUNC(rb_point2), 0);
50
+ rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
51
+ }
52
+
53
+ VALUE
54
+ rb_allocate(VALUE klass)
55
+ {
56
+ CvTwoPoints *ptr;
57
+ return Data_Make_Struct(klass, CvTwoPoints, 0, -1, ptr);
58
+ }
59
+
60
+ VALUE
61
+ rb_cvseqblock(VALUE self)
62
+ {
63
+ return Qnil;
64
+ }
65
+
66
+
67
+ /*
68
+ * Return point 1.
69
+ */
70
+ VALUE
71
+ rb_point1(VALUE self)
72
+ {
73
+ return cCvPoint::new_object(CVTWOPOINTS(self)->p1);
74
+ }
75
+
76
+ /*
77
+ * Return point2.
78
+ */
79
+ VALUE
80
+ rb_point2(VALUE self)
81
+ {
82
+ return cCvPoint::new_object(CVTWOPOINTS(self)->p2);
83
+ }
84
+
85
+ /*
86
+ * call-seq:
87
+ * to_ary -> [self.point1, self.point2]
88
+ *
89
+ * Return 2 point by Array.
90
+ */
91
+ VALUE
92
+ rb_to_ary(VALUE self)
93
+ {
94
+ return rb_ary_new3(2, rb_point1(self), rb_point2(self));
95
+ }
96
+
97
+ __NAMESPACE_END_CVTWOPOINTS
98
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,50 @@
1
+ /************************************************************
2
+
3
+ cvtwopoints.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVTWOPOINTS_H
11
+ #define RUBY_OPENCV_CVTWOPOINTS_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVTWOPOINTS namespace cCvTwoPoints{
16
+ #define __NAMESPACE_END_CVTWOPOINTS }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+
20
+ typedef struct CvTwoPoints{
21
+ CvPoint p1;
22
+ CvPoint p2;
23
+ } CvTwoPoints;
24
+
25
+ __NAMESPACE_BEGIN_CVTWOPOINTS
26
+
27
+ VALUE rb_class();
28
+
29
+ void define_ruby_class();
30
+
31
+ VALUE rb_allocate(VALUE klass);
32
+
33
+ VALUE rb_point1(VALUE self);
34
+ VALUE rb_point2(VALUE self);
35
+ VALUE rb_to_ary(VALUE self);
36
+
37
+ VALUE new_object(CvTwoPoints twopoints);
38
+
39
+ __NAMESPACE_END_CVTWOPOINTS
40
+
41
+ inline CvTwoPoints*
42
+ CVTWOPOINTS(VALUE object){
43
+ CvTwoPoints *ptr;
44
+ Data_Get_Struct(object, CvTwoPoints, ptr);
45
+ return ptr;
46
+ }
47
+
48
+ __NAMESPACE_END_OPENCV
49
+
50
+ #endif // RUBY_OPENCV_CVTWOPOINTS_H
@@ -0,0 +1,206 @@
1
+ /************************************************************
2
+
3
+ cvvector.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvvector.h"
11
+ /*
12
+ * Document-class: OpenCV::CvVector
13
+ *
14
+ * 2D vector (X axis and Y axis)
15
+ */
16
+ __NAMESPACE_BEGIN_OPENCV
17
+ __NAMESPACE_BEGIN_CVVECTOR
18
+
19
+ VALUE rb_klass;
20
+
21
+ VALUE
22
+ rb_class()
23
+ {
24
+ return rb_klass;
25
+ }
26
+
27
+ void
28
+ define_ruby_class()
29
+ {
30
+ if (rb_klass)
31
+ return;
32
+ /*
33
+ * opencv = rb_define_module("OpenCV");
34
+ *
35
+ * note: this comment is used by rdoc.
36
+ */
37
+ VALUE opencv = rb_module_opencv();
38
+
39
+ rb_klass = rb_define_class_under(opencv, "CvVector", rb_cObject);
40
+ rb_define_alloc_func(rb_klass, rb_allocate);
41
+ rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
42
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
43
+ rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
44
+ rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
45
+ rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
46
+ rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
47
+
48
+ rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
49
+ rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
50
+ }
51
+
52
+ /*
53
+ * call-seq:
54
+ * combatible?(obj)
55
+ *
56
+ * Return compatibility to CvVector. Return true if object have method #x and #y.
57
+ *
58
+ * For example.
59
+ * class MyVector
60
+ * def x
61
+ * 1.0
62
+ * end
63
+ * def y
64
+ * 2.0
65
+ * end
66
+ * end
67
+ * mv = MyVector.new
68
+ * CvVector.compatible?(mv) #=> true
69
+ * CvVector.new(mv) #=> same as CvVector(1.0, 2.0)
70
+ */
71
+ VALUE
72
+ rb_compatible_q(VALUE klass, VALUE object)
73
+ {
74
+ return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y"))) ? Qtrue : Qfalse;
75
+ }
76
+
77
+ VALUE
78
+ rb_allocate(VALUE klass)
79
+ {
80
+ CvVector *ptr;
81
+ return Data_Make_Struct(klass, CvVector, 0, -1, ptr);
82
+ }
83
+
84
+ /*
85
+ * call-seq:
86
+ * new -> CvVector.new(0.0, 0.0)
87
+ * new(obj) -> CvVector.new(obj.x.to_f, obj.y.to_f)
88
+ * new(x, y)
89
+ *
90
+ * Create new 2D-vector, (x, y).
91
+ *
92
+ * new() is same as new(0, 0)
93
+ *
94
+ * new(obj) is same as new(obj.x.to_f, obj.y.to_f)
95
+ */
96
+ VALUE
97
+ rb_initialize(int argc, VALUE *argv, VALUE self)
98
+ {
99
+ VALUE obj, x, y;
100
+ switch (argc) {
101
+ case 0:
102
+ break;
103
+ case 1:
104
+ obj = argv[0];
105
+ if (rb_compatible_q(rb_klass, obj)) {
106
+ CVVECTOR(self)->x = NUM2INT(rb_funcall(rb_funcall(obj, rb_intern("x"), 0), rb_intern("to_i"), 0));
107
+ CVVECTOR(self)->y = NUM2INT(rb_funcall(rb_funcall(obj, rb_intern("y"), 0), rb_intern("to_i"), 0));
108
+ }else{
109
+ rb_raise(rb_eArgError, "object is not compatible %s.", rb_class2name(rb_klass));
110
+ }
111
+ break;
112
+ case 2:
113
+ x = argv[0], y = argv[1];
114
+ CVVECTOR(self)->x = NUM2INT(x);
115
+ CVVECTOR(self)->y = NUM2INT(y);
116
+ break;
117
+ default:
118
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
119
+ }
120
+ return Qnil;
121
+ }
122
+
123
+ /*
124
+ * Return parameter on vector of x-axis.
125
+ */
126
+ VALUE
127
+ rb_x(VALUE self)
128
+ {
129
+ return INT2FIX(CVVECTOR(self)->x);
130
+ }
131
+
132
+ /*
133
+ * call-seq:
134
+ * x = val
135
+ *
136
+ * Set vector of x-axis, return self.
137
+ */
138
+ VALUE
139
+ rb_set_x(VALUE self, VALUE x)
140
+ {
141
+ CVVECTOR(self)->x = NUM2INT(x);
142
+ return self;
143
+ }
144
+
145
+ /*
146
+ * Return parameter on vector of y-axis.
147
+ */
148
+ VALUE
149
+ rb_y(VALUE self)
150
+ {
151
+ return INT2FIX(CVVECTOR(self)->y);
152
+ }
153
+
154
+ /*
155
+ * call-seq:
156
+ * y = val
157
+ *
158
+ * Set vector of y-axis, return self.
159
+ */
160
+ VALUE
161
+ rb_set_y(VALUE self, VALUE y)
162
+ {
163
+ CVVECTOR(self)->y = NUM2INT(y);
164
+ return self;
165
+ }
166
+
167
+ /*
168
+ * call-seq:
169
+ * to_s -> "<OpenCV::CvVector:(self.x,self.y)>"
170
+ *
171
+ * Return x and y by String.
172
+ */
173
+ VALUE
174
+ rb_to_s(VALUE self)
175
+ {
176
+ const int i = 4;
177
+ VALUE str[i];
178
+ str[0] = rb_str_new2("<%s:(%d,%d)>");
179
+ str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
180
+ str[2] = rb_x(self);
181
+ str[3] = rb_y(self);
182
+ return rb_f_sprintf(i, str);
183
+ }
184
+
185
+ /*
186
+ * call-seq:
187
+ * to_ary -> [x, y]
188
+ *
189
+ * Return x and y by Array.
190
+ */
191
+ VALUE
192
+ rb_to_ary(VALUE self)
193
+ {
194
+ return rb_ary_new3(2, rb_x(self), rb_y(self));
195
+ }
196
+
197
+ VALUE
198
+ new_object(CvVector point)
199
+ {
200
+ VALUE object = rb_allocate(rb_klass);
201
+ *CVVECTOR(object) = point;
202
+ return object;
203
+ }
204
+
205
+ __NAMESPACE_END_CVVECTOR
206
+ __NAMESPACE_END_OPENCV