afeld-opencv 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. data/.gitignore +23 -0
  2. data/Gemfile +6 -0
  3. data/History.txt +5 -0
  4. data/License.txt +30 -0
  5. data/Manifest.txt +217 -0
  6. data/README.rdoc +161 -0
  7. data/Rakefile +52 -0
  8. data/examples/alpha_blend.rb +21 -0
  9. data/examples/box.png +0 -0
  10. data/examples/box_in_scene.png +0 -0
  11. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  12. data/examples/contours/bitmap-contours.png +0 -0
  13. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  14. data/examples/contours/contour_retrieval_modes.rb +139 -0
  15. data/examples/contours/rotated-boxes.jpg +0 -0
  16. data/examples/convexhull.rb +47 -0
  17. data/examples/face_detect.rb +20 -0
  18. data/examples/find_obj.rb +169 -0
  19. data/examples/houghcircle.rb +22 -0
  20. data/examples/inpaint.png +0 -0
  21. data/examples/inpaint.rb +57 -0
  22. data/examples/lenna-rotated.jpg +0 -0
  23. data/examples/lenna.jpg +0 -0
  24. data/examples/match_kdtree.rb +88 -0
  25. data/examples/paint.rb +70 -0
  26. data/examples/snake.rb +43 -0
  27. data/examples/stuff.jpg +0 -0
  28. data/examples/tiffany.jpg +0 -0
  29. data/ext/opencv/curve.cpp +112 -0
  30. data/ext/opencv/curve.h +34 -0
  31. data/ext/opencv/cvavgcomp.cpp +67 -0
  32. data/ext/opencv/cvavgcomp.h +39 -0
  33. data/ext/opencv/cvbox2d.cpp +197 -0
  34. data/ext/opencv/cvbox2d.h +61 -0
  35. data/ext/opencv/cvcapture.cpp +499 -0
  36. data/ext/opencv/cvcapture.h +72 -0
  37. data/ext/opencv/cvchain.cpp +230 -0
  38. data/ext/opencv/cvchain.h +46 -0
  39. data/ext/opencv/cvcircle32f.cpp +116 -0
  40. data/ext/opencv/cvcircle32f.h +52 -0
  41. data/ext/opencv/cvcondensation.cpp +282 -0
  42. data/ext/opencv/cvcondensation.h +49 -0
  43. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  44. data/ext/opencv/cvconnectedcomp.h +49 -0
  45. data/ext/opencv/cvcontour.cpp +297 -0
  46. data/ext/opencv/cvcontour.h +48 -0
  47. data/ext/opencv/cvcontourtree.cpp +91 -0
  48. data/ext/opencv/cvcontourtree.h +41 -0
  49. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  50. data/ext/opencv/cvconvexitydefect.h +42 -0
  51. data/ext/opencv/cverror.cpp +159 -0
  52. data/ext/opencv/cverror.h +28 -0
  53. data/ext/opencv/cvfeaturetree.cpp +125 -0
  54. data/ext/opencv/cvfeaturetree.h +55 -0
  55. data/ext/opencv/cvfont.cpp +208 -0
  56. data/ext/opencv/cvfont.h +64 -0
  57. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  58. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  59. data/ext/opencv/cvhistogram.cpp +546 -0
  60. data/ext/opencv/cvhistogram.h +73 -0
  61. data/ext/opencv/cvhumoments.cpp +139 -0
  62. data/ext/opencv/cvhumoments.h +51 -0
  63. data/ext/opencv/cvline.cpp +154 -0
  64. data/ext/opencv/cvline.h +54 -0
  65. data/ext/opencv/cvmat.cpp +5627 -0
  66. data/ext/opencv/cvmat.h +280 -0
  67. data/ext/opencv/cvmatnd.cpp +44 -0
  68. data/ext/opencv/cvmatnd.h +28 -0
  69. data/ext/opencv/cvmemstorage.cpp +68 -0
  70. data/ext/opencv/cvmemstorage.h +53 -0
  71. data/ext/opencv/cvmoments.cpp +287 -0
  72. data/ext/opencv/cvmoments.h +75 -0
  73. data/ext/opencv/cvpoint.cpp +228 -0
  74. data/ext/opencv/cvpoint.h +64 -0
  75. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  76. data/ext/opencv/cvpoint2d32f.h +63 -0
  77. data/ext/opencv/cvpoint3d32f.cpp +246 -0
  78. data/ext/opencv/cvpoint3d32f.h +66 -0
  79. data/ext/opencv/cvrect.cpp +333 -0
  80. data/ext/opencv/cvrect.h +79 -0
  81. data/ext/opencv/cvscalar.cpp +236 -0
  82. data/ext/opencv/cvscalar.h +71 -0
  83. data/ext/opencv/cvseq.cpp +599 -0
  84. data/ext/opencv/cvseq.h +72 -0
  85. data/ext/opencv/cvsize.cpp +221 -0
  86. data/ext/opencv/cvsize.h +65 -0
  87. data/ext/opencv/cvsize2d32f.cpp +209 -0
  88. data/ext/opencv/cvsize2d32f.h +64 -0
  89. data/ext/opencv/cvslice.cpp +120 -0
  90. data/ext/opencv/cvslice.h +61 -0
  91. data/ext/opencv/cvsparsemat.cpp +44 -0
  92. data/ext/opencv/cvsparsemat.h +28 -0
  93. data/ext/opencv/cvsurfparams.cpp +199 -0
  94. data/ext/opencv/cvsurfparams.h +58 -0
  95. data/ext/opencv/cvsurfpoint.cpp +223 -0
  96. data/ext/opencv/cvsurfpoint.h +52 -0
  97. data/ext/opencv/cvtermcriteria.cpp +192 -0
  98. data/ext/opencv/cvtermcriteria.h +71 -0
  99. data/ext/opencv/cvtwopoints.cpp +116 -0
  100. data/ext/opencv/cvtwopoints.h +51 -0
  101. data/ext/opencv/cvutils.cpp +194 -0
  102. data/ext/opencv/cvutils.h +29 -0
  103. data/ext/opencv/cvvideowriter.cpp +137 -0
  104. data/ext/opencv/cvvideowriter.h +43 -0
  105. data/ext/opencv/gui.cpp +68 -0
  106. data/ext/opencv/gui.h +30 -0
  107. data/ext/opencv/iplconvkernel.cpp +192 -0
  108. data/ext/opencv/iplconvkernel.h +71 -0
  109. data/ext/opencv/iplimage.cpp +576 -0
  110. data/ext/opencv/iplimage.h +70 -0
  111. data/ext/opencv/lib/opencv.rb +3 -0
  112. data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
  113. data/ext/opencv/lib/opencv/version.rb +3 -0
  114. data/ext/opencv/mouseevent.cpp +181 -0
  115. data/ext/opencv/mouseevent.h +56 -0
  116. data/ext/opencv/opencv.cpp +710 -0
  117. data/ext/opencv/opencv.h +400 -0
  118. data/ext/opencv/pointset.cpp +284 -0
  119. data/ext/opencv/pointset.h +69 -0
  120. data/ext/opencv/trackbar.cpp +121 -0
  121. data/ext/opencv/trackbar.h +69 -0
  122. data/ext/opencv/window.cpp +357 -0
  123. data/ext/opencv/window.h +66 -0
  124. data/extconf.rb +65 -0
  125. data/images/CvMat_sobel.png +0 -0
  126. data/images/CvMat_sub_rect.png +0 -0
  127. data/images/CvSeq_relationmap.png +0 -0
  128. data/images/face_detect_from_lena.jpg +0 -0
  129. data/test/helper.rb +146 -0
  130. data/test/runner.rb +30 -0
  131. data/test/samples/airplane.jpg +0 -0
  132. data/test/samples/baboon.jpg +0 -0
  133. data/test/samples/baboon200.jpg +0 -0
  134. data/test/samples/baboon200_rotated.jpg +0 -0
  135. data/test/samples/blank0.jpg +0 -0
  136. data/test/samples/blank1.jpg +0 -0
  137. data/test/samples/blank2.jpg +0 -0
  138. data/test/samples/blank3.jpg +0 -0
  139. data/test/samples/blank4.jpg +0 -0
  140. data/test/samples/blank5.jpg +0 -0
  141. data/test/samples/blank6.jpg +0 -0
  142. data/test/samples/blank7.jpg +0 -0
  143. data/test/samples/blank8.jpg +0 -0
  144. data/test/samples/blank9.jpg +0 -0
  145. data/test/samples/cat.jpg +0 -0
  146. data/test/samples/contours.jpg +0 -0
  147. data/test/samples/fruits.jpg +0 -0
  148. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  149. data/test/samples/inpaint-mask.bmp +0 -0
  150. data/test/samples/lena-256x256.jpg +0 -0
  151. data/test/samples/lena-32x32.jpg +0 -0
  152. data/test/samples/lena-eyes.jpg +0 -0
  153. data/test/samples/lena-inpaint.jpg +0 -0
  154. data/test/samples/lena.jpg +0 -0
  155. data/test/samples/lines.jpg +0 -0
  156. data/test/samples/messy0.jpg +0 -0
  157. data/test/samples/messy1.jpg +0 -0
  158. data/test/samples/movie_sample.avi +0 -0
  159. data/test/samples/one_way_train_0000.jpg +0 -0
  160. data/test/samples/one_way_train_0001.jpg +0 -0
  161. data/test/samples/partially_blank0.jpg +0 -0
  162. data/test/samples/partially_blank1.jpg +0 -0
  163. data/test/samples/smooth0.jpg +0 -0
  164. data/test/samples/smooth1.jpg +0 -0
  165. data/test/samples/smooth2.jpg +0 -0
  166. data/test/samples/smooth3.jpg +0 -0
  167. data/test/samples/smooth4.jpg +0 -0
  168. data/test/samples/smooth5.jpg +0 -0
  169. data/test/samples/smooth6.jpg +0 -0
  170. data/test/samples/str-cv-rotated.jpg +0 -0
  171. data/test/samples/str-cv.jpg +0 -0
  172. data/test/samples/str-ov.jpg +0 -0
  173. data/test/samples/stuff.jpg +0 -0
  174. data/test/test_curve.rb +43 -0
  175. data/test/test_cvavgcomp.rb +24 -0
  176. data/test/test_cvbox2d.rb +76 -0
  177. data/test/test_cvcapture.rb +183 -0
  178. data/test/test_cvchain.rb +108 -0
  179. data/test/test_cvcircle32f.rb +41 -0
  180. data/test/test_cvconnectedcomp.rb +61 -0
  181. data/test/test_cvcontour.rb +150 -0
  182. data/test/test_cvcontourtree.rb +43 -0
  183. data/test/test_cverror.rb +50 -0
  184. data/test/test_cvfeaturetree.rb +65 -0
  185. data/test/test_cvfont.rb +58 -0
  186. data/test/test_cvhaarclassifiercascade.rb +63 -0
  187. data/test/test_cvhistogram.rb +271 -0
  188. data/test/test_cvhumoments.rb +83 -0
  189. data/test/test_cvline.rb +50 -0
  190. data/test/test_cvmat.rb +2752 -0
  191. data/test/test_cvmat_drawing.rb +318 -0
  192. data/test/test_cvmat_dxt.rb +147 -0
  193. data/test/test_cvmat_imageprocessing.rb +1943 -0
  194. data/test/test_cvmoments.rb +180 -0
  195. data/test/test_cvpoint.rb +75 -0
  196. data/test/test_cvpoint2d32f.rb +75 -0
  197. data/test/test_cvpoint3d32f.rb +93 -0
  198. data/test/test_cvrect.rb +144 -0
  199. data/test/test_cvscalar.rb +113 -0
  200. data/test/test_cvseq.rb +295 -0
  201. data/test/test_cvsize.rb +75 -0
  202. data/test/test_cvsize2d32f.rb +75 -0
  203. data/test/test_cvslice.rb +31 -0
  204. data/test/test_cvsurfparams.rb +57 -0
  205. data/test/test_cvsurfpoint.rb +66 -0
  206. data/test/test_cvtermcriteria.rb +56 -0
  207. data/test/test_cvtwopoints.rb +40 -0
  208. data/test/test_cvvideowriter.rb +58 -0
  209. data/test/test_iplconvkernel.rb +54 -0
  210. data/test/test_iplimage.rb +156 -0
  211. data/test/test_mouseevent.rb +17 -0
  212. data/test/test_opencv.rb +340 -0
  213. data/test/test_pointset.rb +130 -0
  214. data/test/test_preliminary.rb +130 -0
  215. data/test/test_trackbar.rb +47 -0
  216. data/test/test_window.rb +115 -0
  217. metadata +399 -0
@@ -0,0 +1,72 @@
1
+ /************************************************************
2
+
3
+ cvcapture.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVCAPTURE_H
11
+ #define RUBY_OPENCV_CVCAPTURE_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVCAPTURE namespace cCvCapture {
16
+ #define __NAMESPACE_END_CVCAPTURE }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVCAPTURE
20
+
21
+
22
+ VALUE rb_class();
23
+
24
+ void define_ruby_class();
25
+
26
+ void cvcapture_free(void *ptr);
27
+ VALUE rb_open(int argc, VALUE *argv, VALUE klass);
28
+
29
+ VALUE rb_grab(VALUE self);
30
+ VALUE rb_retrieve(VALUE self);
31
+ VALUE rb_query(VALUE self);
32
+
33
+ VALUE rb_get_millisecond(VALUE self);
34
+ VALUE rb_set_millisecond(VALUE self, VALUE value);
35
+ VALUE rb_get_frames(VALUE self);
36
+ VALUE rb_set_frames(VALUE self, VALUE value);
37
+ VALUE rb_get_avi_ratio(VALUE self);
38
+ VALUE rb_set_avi_ratio(VALUE self, VALUE value);
39
+ VALUE rb_get_size(VALUE self);
40
+ VALUE rb_set_size(VALUE self, VALUE value);
41
+ VALUE rb_get_width(VALUE self);
42
+ VALUE rb_set_width(VALUE self, VALUE value);
43
+ VALUE rb_get_height(VALUE self);
44
+ VALUE rb_set_height(VALUE self, VALUE value);
45
+ VALUE rb_get_fps(VALUE self);
46
+ VALUE rb_set_fps(VALUE self, VALUE value);
47
+ VALUE rb_get_fourcc(VALUE self);
48
+ VALUE rb_get_frame_count(VALUE self);
49
+ VALUE rb_get_format(VALUE self);
50
+ VALUE rb_get_mode(VALUE self);
51
+ VALUE rb_get_brightness(VALUE self);
52
+ VALUE rb_get_contrast(VALUE self);
53
+ VALUE rb_get_saturation(VALUE self);
54
+ VALUE rb_get_hue(VALUE self);
55
+ VALUE rb_get_gain(VALUE self);
56
+ VALUE rb_get_exposure(VALUE self);
57
+ VALUE rb_get_convert_rgb(VALUE self);
58
+ VALUE rb_get_rectification(VALUE self);
59
+
60
+ __NAMESPACE_END_CVCAPTURE
61
+
62
+
63
+ inline CvCapture*
64
+ CVCAPTURE(VALUE object) {
65
+ CvCapture *ptr;
66
+ Data_Get_Struct(object, CvCapture, ptr);
67
+ return ptr;
68
+ }
69
+
70
+ __NAMESPACE_END_OPENCV
71
+
72
+ #endif // RUBY_OPENCV_CVCAPTURE_H
@@ -0,0 +1,230 @@
1
+ /************************************************************
2
+
3
+ cvchain.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvchain.h"
11
+ /*
12
+ * Document-class: OpenCV::CvChain
13
+ *
14
+ * Freeman chain code.
15
+ * CvMat#find_contours(:method => :code)
16
+ */
17
+ __NAMESPACE_BEGIN_OPENCV
18
+ __NAMESPACE_BEGIN_CVCHAIN
19
+
20
+ #define APPROX_CHAIN_OPTION(op) rb_get_option_table(rb_klass, "APPROX_CHAIN_OPTION", op)
21
+ #define APPROX_CHAIN_METHOD(op) CVMETHOD("APPROX_CHAIN_METHOD", LOOKUP_CVMETHOD(op, "method"), CV_CHAIN_APPROX_SIMPLE)
22
+ #define APPROX_CHAIN_PARAMETER(op) NUM2INT(LOOKUP_CVMETHOD(op, "parameter"))
23
+ #define APPROX_CHAIN_MINIMAL_PERIMETER(op) NUM2INT(LOOKUP_CVMETHOD(op, "minimal_perimeter"))
24
+ #define APPROX_CHAIN_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_CVMETHOD(op, "recursive"))
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
+ * cvseq = rb_define_class_under(opencv, "CvSeq");
42
+ * curve = rb_define_module_under(opencv, "Curve");
43
+ * note: this comment is used by rdoc.
44
+ */
45
+ VALUE opencv = rb_module_opencv();
46
+ VALUE cvseq = cCvSeq::rb_class();
47
+ VALUE curve = mCurve::rb_module();
48
+
49
+ rb_klass = rb_define_class_under(opencv, "CvChain", cvseq);
50
+ rb_include_module(rb_klass, curve);
51
+ VALUE approx_chain_option = rb_hash_new();
52
+ rb_define_const(rb_klass, "APPROX_CHAIN_OPTION", approx_chain_option);
53
+ rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("method")), ID2SYM(rb_intern("approx_simple")));
54
+ rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("parameter")), rb_float_new(0));
55
+ rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("minimal_perimeter")), INT2FIX(0));
56
+ rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("recursive")), Qfalse);
57
+
58
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
59
+ rb_define_method(rb_klass, "origin", RUBY_METHOD_FUNC(rb_origin), 0);
60
+ rb_define_method(rb_klass, "origin=", RUBY_METHOD_FUNC(rb_set_origin), 1);
61
+ rb_define_method(rb_klass, "codes", RUBY_METHOD_FUNC(rb_codes), 0);
62
+ rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
63
+ rb_define_method(rb_klass, "approx_chains", RUBY_METHOD_FUNC(rb_approx_chains), -1);
64
+ rb_define_alias(rb_klass, "approx", "approx_chains");
65
+ }
66
+
67
+ VALUE
68
+ rb_allocate(VALUE klass)
69
+ {
70
+ CvChain *ptr;
71
+ return Data_Make_Struct(klass, CvChain, 0, 0, ptr);
72
+ }
73
+
74
+ VALUE
75
+ rb_initialize(int argc, VALUE *argv, VALUE self)
76
+ {
77
+ CvMemStorage *storage;
78
+ VALUE storage_value;
79
+ if (rb_scan_args(argc, argv, "01", &storage_value) > 0) {
80
+ storage_value = CHECK_CVMEMSTORAGE(storage_value);
81
+ storage = CVMEMSTORAGE(storage_value);
82
+ }
83
+ else
84
+ storage = rb_cvCreateMemStorage(0);
85
+ try {
86
+ DATA_PTR(self) = (CvChain*)cvCreateSeq(CV_SEQ_ELTYPE_CODE, sizeof(CvChain),
87
+ sizeof(char), storage);
88
+ }
89
+ catch (cv::Exception& e) {
90
+ raise_cverror(e);
91
+ }
92
+ return self;
93
+ }
94
+
95
+ /*
96
+ * call-seq:
97
+ * origin -> cvpoint
98
+ *
99
+ * Return Freeman chain code origin.
100
+ */
101
+ VALUE
102
+ rb_origin(VALUE self)
103
+ {
104
+ return cCvPoint::new_object(CVCHAIN(self)->origin);
105
+ }
106
+
107
+ /*
108
+ * call-seq:
109
+ * origin = point -> self
110
+ *
111
+ * Set Freeman chain code origin.
112
+ */
113
+ VALUE
114
+ rb_set_origin(VALUE self, VALUE origin)
115
+ {
116
+ CVCHAIN(self)->origin = VALUE_TO_CVPOINT(origin);
117
+ return self;
118
+ }
119
+
120
+ /*
121
+ * call-seq:
122
+ * codes -> array(contain fixnum)
123
+ *
124
+ * Return Freeman chain codes.
125
+ */
126
+ VALUE
127
+ rb_codes(VALUE self)
128
+ {
129
+ CvChain *chain = CVCHAIN(self);
130
+ CvChainPtReader reader;
131
+ int total = chain->total;
132
+ VALUE ary = rb_ary_new2(total);
133
+ try {
134
+ cvStartReadChainPoints(chain, &reader);
135
+ for (int i = 0; i < total; ++i) {
136
+ CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
137
+ rb_ary_store(ary, i, CHR2FIX(reader.code));
138
+ }
139
+ }
140
+ catch (cv::Exception& e) {
141
+ raise_cverror(e);
142
+ }
143
+ return ary;
144
+ }
145
+
146
+ /*
147
+ * call-seq:
148
+ * points -> array(contain cvpoint)
149
+ *
150
+ * Return points that represent by Freeman chain code.
151
+ */
152
+ VALUE
153
+ rb_points(VALUE self)
154
+ {
155
+ CvChain *chain = CVCHAIN(self);
156
+ CvChainPtReader reader;
157
+ CvPoint p = chain->origin;
158
+ int total = chain->total;
159
+ VALUE ary = rb_ary_new2(total);
160
+ try {
161
+ cvStartReadChainPoints(chain, &reader);
162
+ for (int i = 0; i < total; ++i) {
163
+ CV_READ_CHAIN_POINT(p, reader);
164
+ rb_ary_store(ary, i, cCvPoint::new_object(p));
165
+ }
166
+ }
167
+ catch (cv::Exception& e) {
168
+ raise_cverror(e);
169
+ }
170
+ return ary;
171
+ }
172
+
173
+ /*
174
+ * call-seq:
175
+ * approx_chains(<i>[approx_chain_option]</i>) -> cvcontour
176
+ *
177
+ * Approximates Freeman chain(s) with polygonal curve.
178
+ * <i>approx_chain_option</i> should be Hash include these keys.
179
+ * :method - Approximation method.
180
+ * :approx_none - translate all the points from the chain code into points;
181
+ * :approx_simple(default) - compress horizontal, vertical, and diagonal segments, that is,
182
+ * the function leaves only their ending points.
183
+ * :approx_tc89_l1
184
+ * :approx_tc89_kcos - apply one of the flavors of Teh-Chin chain approximation algorithm.
185
+ * If set the difference between the current pixel and seed pixel is considered,
186
+ * otherwise difference between neighbor pixels is considered (the range is floating).
187
+ * :parameter - Method parameter (not used now).
188
+ * :minimal_perimeter (default 0)
189
+ * Approximates only those contours whose perimeters are not less than minimal_perimeter. Other chains are removed from the resulting structure.
190
+ * :recursive (default false)
191
+ * If not nil or false, the function approximates all chains that access can be obtained to
192
+ * from self by h_next or v_next links. If 0, the single chain is approximated.
193
+ *
194
+ */
195
+ VALUE
196
+ rb_approx_chains(int argc, VALUE *argv, VALUE self)
197
+ {
198
+ VALUE approx_chain_option;
199
+ rb_scan_args(argc, argv, "01", &approx_chain_option);
200
+
201
+ approx_chain_option = APPROX_CHAIN_OPTION(approx_chain_option);
202
+ VALUE storage = cCvMemStorage::new_object();
203
+ CvSeq *seq = cvApproxChains(CVSEQ(self), CVMEMSTORAGE(storage),
204
+ APPROX_CHAIN_METHOD(approx_chain_option),
205
+ APPROX_CHAIN_PARAMETER(approx_chain_option),
206
+ APPROX_CHAIN_MINIMAL_PERIMETER(approx_chain_option),
207
+ APPROX_CHAIN_RECURSIVE(approx_chain_option));
208
+
209
+ if (seq && seq->total > 0) {
210
+ return cCvSeq::new_sequence(cCvChain::rb_class(), seq, cCvPoint::rb_class(), storage);
211
+ }
212
+ return Qnil;
213
+ }
214
+
215
+ VALUE
216
+ new_object()
217
+ {
218
+ VALUE storage = cCvMemStorage::new_object();
219
+ CvSeq *seq = NULL;
220
+ try {
221
+ seq = cvCreateSeq(CV_SEQ_CHAIN_CONTOUR, sizeof(CvChain), sizeof(char), CVMEMSTORAGE(storage));
222
+ }
223
+ catch (cv::Exception& e) {
224
+ raise_cverror(e);
225
+ }
226
+ return cCvSeq::new_sequence(cCvChain::rb_class(), seq, T_FIXNUM, storage);
227
+ }
228
+
229
+ __NAMESPACE_END_CVCHAIN
230
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,46 @@
1
+ /************************************************************
2
+
3
+ cvchain.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVCHAIN_H
11
+ #define RUBY_OPENCV_CVCHAIN_H
12
+ #include "opencv.h"
13
+
14
+ #define __NAMESPACE_BEGIN_CVCHAIN namespace cCvChain {
15
+ #define __NAMESPACE_END_CVCHAIN }
16
+
17
+ __NAMESPACE_BEGIN_OPENCV
18
+ __NAMESPACE_BEGIN_CVCHAIN
19
+
20
+ VALUE rb_class();
21
+
22
+ void define_ruby_class();
23
+
24
+ VALUE rb_allocate(VALUE klass);
25
+
26
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
27
+ VALUE rb_origin(VALUE self);
28
+ VALUE rb_set_origin(VALUE self, VALUE origin);
29
+ VALUE rb_codes(VALUE self);
30
+ VALUE rb_points(VALUE self);
31
+ VALUE rb_approx_chains(int argc, VALUE *argv, VALUE self);
32
+
33
+ VALUE new_object();
34
+
35
+ __NAMESPACE_END_CVCHAIN
36
+
37
+ inline CvChain*
38
+ CVCHAIN(VALUE object){
39
+ CvChain *ptr;
40
+ Data_Get_Struct(object, CvChain, ptr);
41
+ return ptr;
42
+ }
43
+
44
+ __NAMESPACE_END_OPENCV
45
+
46
+ #endif // RUBY_OPENCV_CVCHAIN_H
@@ -0,0 +1,116 @@
1
+ /************************************************************
2
+
3
+ cvcircle32f.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvcircle32f.h"
11
+ /*
12
+ * Document-class: OpenCV::CvCircle32f
13
+ *
14
+ * Combination of center and radius.
15
+ *
16
+ * see CvMat#hough_circles
17
+ */
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVCIRCLE32F
20
+
21
+ VALUE rb_klass;
22
+
23
+ VALUE
24
+ rb_class()
25
+ {
26
+ return rb_klass;
27
+ }
28
+
29
+ void
30
+ define_ruby_class()
31
+ {
32
+ if (rb_klass)
33
+ return;
34
+ /*
35
+ * opencv = rb_define_module("OpenCV");
36
+ *
37
+ * note: this comment is used by rdoc.
38
+ */
39
+ VALUE opencv = rb_module_opencv();
40
+
41
+ rb_klass = rb_define_class_under(opencv, "CvCircle32f", rb_cObject);
42
+ rb_define_alloc_func(rb_klass, rb_allocate);
43
+ rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
44
+ rb_define_method(rb_klass, "radius", RUBY_METHOD_FUNC(rb_radius), 0);
45
+ rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
46
+ rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
47
+ rb_define_alias(rb_klass, "to_a", "to_ary");
48
+ }
49
+
50
+ VALUE
51
+ rb_allocate(VALUE klass)
52
+ {
53
+ CvCircle32f *ptr;
54
+ return Data_Make_Struct(klass, CvCircle32f, 0, -1, ptr);
55
+ }
56
+
57
+ /*
58
+ * Return parameter on center.
59
+ */
60
+ VALUE
61
+ rb_center(VALUE self)
62
+ {
63
+ return cCvPoint2D32f::new_object(CVCIRCLE32F(self)->center);
64
+ }
65
+
66
+ /*
67
+ * Return parameter on radius.
68
+ */
69
+ VALUE
70
+ rb_radius(VALUE self)
71
+ {
72
+ return rb_float_new(CVCIRCLE32F(self)->radius);
73
+ }
74
+
75
+ /*
76
+ * call-seq:
77
+ * [<i>index</i>]
78
+ *
79
+ * Return value of <i>index</i> dimension.
80
+ */
81
+ VALUE
82
+ rb_aref(VALUE self, VALUE index)
83
+ {
84
+ switch (NUM2INT(index)) {
85
+ case 0:
86
+ return DBL2NUM(CVCIRCLE32F(self)->center.x);
87
+ break;
88
+ case 1:
89
+ return DBL2NUM(CVCIRCLE32F(self)->center.y);
90
+ break;
91
+ case 2:
92
+ return DBL2NUM(CVCIRCLE32F(self)->radius);
93
+ break;
94
+ default:
95
+ rb_raise(rb_eIndexError, "index should be 0...3");
96
+ break;
97
+ }
98
+ return Qnil;
99
+ }
100
+
101
+ VALUE
102
+ rb_to_ary(VALUE self)
103
+ {
104
+ return rb_ary_new3(2, rb_center(self), rb_radius(self));
105
+ }
106
+
107
+ VALUE
108
+ new_object(CvCircle32f circle32f)
109
+ {
110
+ VALUE object = rb_allocate(rb_klass);
111
+ *CVCIRCLE32F(object) = circle32f;
112
+ return object;
113
+ }
114
+
115
+ __NAMESPACE_END_CVCIRCLE32F
116
+ __NAMESPACE_END_OPENCV