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,49 @@
1
+ /************************************************************
2
+
3
+ cvconnectedcomp.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVCONNECTEDCOMP_H
11
+ #define RUBY_OPENCV_CVCONNECTEDCOMP_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVCONNECTEDCOMP namespace cCvConnectedComp {
16
+ #define __NAMESPACE_END_CVCONNECTEDCOMP }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVCONNECTEDCOMP
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_area(VALUE self);
29
+ VALUE rb_value(VALUE self);
30
+ VALUE rb_rect(VALUE self);
31
+ VALUE rb_set_rect(VALUE self, VALUE rect);
32
+ VALUE rb_contour(VALUE self);
33
+
34
+ VALUE new_object();
35
+ VALUE new_object(CvConnectedComp comp);
36
+
37
+ __NAMESPACE_END_CVCONNECTEDCOMP
38
+
39
+ inline CvConnectedComp*
40
+ CVCONNECTEDCOMP(VALUE object)
41
+ {
42
+ CvConnectedComp *ptr;
43
+ Data_Get_Struct(object, CvConnectedComp, ptr);
44
+ return ptr;
45
+ }
46
+
47
+ __NAMESPACE_END_OPENCV
48
+
49
+ #endif // RUBY_OPENCV_CVCONNECTEDCOMP_H
@@ -0,0 +1,297 @@
1
+ /************************************************************
2
+
3
+ cvcontour.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvcontour.h"
11
+ /*
12
+ * Document-class: OpenCV::CvContour
13
+ *
14
+ * Contour.
15
+ * CvMat#find_contours
16
+ */
17
+ __NAMESPACE_BEGIN_OPENCV
18
+ __NAMESPACE_BEGIN_CVCONTOUR
19
+
20
+ #define APPROX_POLY_OPTION(op) rb_get_option_table(rb_klass, "APPROX_OPTION", op)
21
+ #define APPROX_POLY_METHOD(op) CVMETHOD("APPROX_POLY_METHOD", LOOKUP_CVMETHOD(op, "method"), CV_POLY_APPROX_DP)
22
+ #define APPROX_POLY_ACCURACY(op) NUM2DBL(LOOKUP_CVMETHOD(op, "accuracy"))
23
+ #define APPROX_POLY_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_CVMETHOD(op, "recursive"))
24
+
25
+ VALUE rb_allocate(VALUE klass);
26
+ void cvcontour_free(void *ptr);
27
+
28
+ VALUE rb_klass;
29
+
30
+ VALUE
31
+ rb_class()
32
+ {
33
+ return rb_klass;
34
+ }
35
+
36
+ void
37
+ define_ruby_class()
38
+ {
39
+ if (rb_klass)
40
+ return;
41
+ /*
42
+ * opencv = rb_define_module("OpenCV");
43
+ * cvseq = rb_define_class_under(opencv, "CvSeq");
44
+ * curve = rb_define_module_under(opencv, "Curve");
45
+ * pointset = rb_define_module_under(opencv, "PointSet");
46
+ *
47
+ * note: this comment is used by rdoc.
48
+ */
49
+ VALUE opencv = rb_module_opencv();
50
+ VALUE cvseq = cCvSeq::rb_class();
51
+ VALUE curve = mCurve::rb_module();
52
+ VALUE pointset = mPointSet::rb_module();
53
+
54
+ rb_klass = rb_define_class_under(opencv, "CvContour", cvseq);
55
+ rb_include_module(rb_klass, curve);
56
+ rb_include_module(rb_klass, pointset);
57
+
58
+ rb_define_alloc_func(rb_klass, rb_allocate);
59
+
60
+ VALUE approx_option = rb_hash_new();
61
+ rb_define_const(rb_klass, "APPROX_OPTION", approx_option);
62
+ rb_hash_aset(approx_option, ID2SYM(rb_intern("method")), INT2FIX(CV_POLY_APPROX_DP));
63
+ rb_hash_aset(approx_option, ID2SYM(rb_intern("accuracy")), rb_float_new(1.0));
64
+ rb_hash_aset(approx_option, ID2SYM(rb_intern("recursive")), Qfalse);
65
+
66
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
67
+ rb_define_method(rb_klass, "rect", RUBY_METHOD_FUNC(rb_rect), 0);
68
+ rb_define_method(rb_klass, "color", RUBY_METHOD_FUNC(rb_color), 0);
69
+ rb_define_method(rb_klass, "color=", RUBY_METHOD_FUNC(rb_set_color), 1);
70
+ rb_define_method(rb_klass, "reserved", RUBY_METHOD_FUNC(rb_reserved), 0);
71
+ rb_define_method(rb_klass, "approx_poly", RUBY_METHOD_FUNC(rb_approx_poly), -1);
72
+ rb_define_alias(rb_klass, "approx", "approx_poly");
73
+ rb_define_method(rb_klass, "bounding_rect", RUBY_METHOD_FUNC(rb_bounding_rect), 0);
74
+ rb_define_method(rb_klass, "create_tree", RUBY_METHOD_FUNC(rb_create_tree), -1);
75
+ rb_define_method(rb_klass, "in?", RUBY_METHOD_FUNC(rb_in_q), 1);
76
+ rb_define_method(rb_klass, "measure_distance", RUBY_METHOD_FUNC(rb_measure_distance), 1);
77
+ rb_define_method(rb_klass, "point_polygon_test", RUBY_METHOD_FUNC(rb_point_polygon_test), 2);
78
+ }
79
+
80
+ VALUE
81
+ rb_allocate(VALUE klass)
82
+ {
83
+ CvContour *ptr;
84
+ return Data_Make_Struct(klass, CvContour, mark_root_object, unregister_object, ptr);
85
+ }
86
+
87
+ VALUE
88
+ rb_initialize(int argc, VALUE *argv, VALUE self)
89
+ {
90
+ VALUE storage;
91
+ rb_scan_args(argc, argv, "01", &storage);
92
+
93
+ if (NIL_P(storage))
94
+ storage = cCvMemStorage::new_object(0);
95
+ else
96
+ storage = CHECK_CVMEMSTORAGE(storage);
97
+
98
+ CvContour* contour = (CvContour*)DATA_PTR(self);
99
+ try {
100
+ contour = (CvContour*)cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvContour),
101
+ sizeof(CvPoint), CVMEMSTORAGE(storage));
102
+ }
103
+ catch (cv::Exception& e) {
104
+ raise_cverror(e);
105
+ }
106
+ register_root_object((CvSeq*)contour, storage);
107
+
108
+ return self;
109
+ }
110
+
111
+ VALUE
112
+ rb_rect(VALUE self)
113
+ {
114
+ return cCvRect::new_object(CVCONTOUR(self)->rect);
115
+ }
116
+
117
+ VALUE
118
+ rb_color(VALUE self)
119
+ {
120
+ return INT2NUM(CVCONTOUR(self)->color);
121
+ }
122
+
123
+ VALUE
124
+ rb_set_color(VALUE self, VALUE color)
125
+ {
126
+ CVCONTOUR(self)->color = NUM2INT(color);
127
+ return self;
128
+ }
129
+
130
+ VALUE
131
+ rb_reserved(VALUE self)
132
+ {
133
+ return rb_ary_new3(3,
134
+ INT2NUM(CVCONTOUR(self)->reserved[0]),
135
+ INT2NUM(CVCONTOUR(self)->reserved[1]),
136
+ INT2NUM(CVCONTOUR(self)->reserved[2]));
137
+ }
138
+
139
+ /*
140
+ * call-seq:
141
+ * approx_poly(<i>approx_poly_option</i>) -> cvcontour
142
+ *
143
+ * Approximates polygonal curve(s) with desired precision.
144
+ * <i>approx_poly_option</i> should be Hash include these keys.
145
+ * :method - Approximation method.
146
+ * :dp - corresponds to Douglas-Peucker algorithm.
147
+ * :accuracy - approximation accuracy. (high-accuracy will create more simple contours)
148
+ * :recursive - (default false)
149
+ * If not nil or false, the function approximates all chains that access can be obtained to
150
+ * from self by h_next or v_next links. If 0, approximated this one.
151
+ */
152
+ VALUE
153
+ rb_approx_poly(int argc, VALUE *argv, VALUE self)
154
+ {
155
+ VALUE approx_poly_option;
156
+ rb_scan_args(argc, argv, "01", &approx_poly_option);
157
+ approx_poly_option = APPROX_POLY_OPTION(approx_poly_option);
158
+ VALUE storage = cCvMemStorage::new_object();
159
+ CvSeq *contour = cvApproxPoly(CVCONTOUR(self), sizeof(CvContour), CVMEMSTORAGE(storage),
160
+ APPROX_POLY_METHOD(approx_poly_option),
161
+ APPROX_POLY_ACCURACY(approx_poly_option),
162
+ APPROX_POLY_RECURSIVE(approx_poly_option));
163
+
164
+ if (contour && contour->total > 0) {
165
+ return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
166
+ }
167
+ return Qnil;
168
+ }
169
+
170
+ /*
171
+ * call-seq:
172
+ * bounding_rect -> rect
173
+ *
174
+ * Calculates up-right bounding rectangle of point set.
175
+ *
176
+ */
177
+ VALUE
178
+ rb_bounding_rect(VALUE self)
179
+ {
180
+ CvRect rect;
181
+ try {
182
+ rect = cvBoundingRect(CVCONTOUR(self), 1);
183
+ }
184
+ catch (cv::Exception& e) {
185
+ raise_cverror(e);
186
+ }
187
+ return cCvRect::new_object(rect);
188
+ }
189
+
190
+ /*
191
+ * call-seq:
192
+ * create_tree([threshold = 0.0]) -> cvcontourtree
193
+ *
194
+ * Creates hierarchical representation of contour.
195
+ * If the parameter <i>threshold</i> is less than or equal to 0,
196
+ * the method creates full binary tree representation.
197
+ * If the threshold is greater than 0, the function creates
198
+ * representation with the precision threshold:
199
+ */
200
+ VALUE
201
+ rb_create_tree(int argc, VALUE *argv, VALUE self)
202
+ {
203
+ VALUE threshold, storage;
204
+ rb_scan_args(argc, argv, "01", &threshold);
205
+ storage = cCvMemStorage::new_object();
206
+ CvContourTree *tree = NULL;
207
+ try {
208
+ tree = cvCreateContourTree(CVSEQ(self), CVMEMSTORAGE(storage), IF_DBL(threshold, 0.0));
209
+ }
210
+ catch (cv::Exception& e) {
211
+ raise_cverror(e);
212
+ }
213
+ return cCvSeq::new_sequence(cCvContourTree::rb_class(), (CvSeq*)tree, cCvPoint::rb_class(), storage);
214
+ }
215
+
216
+ /*
217
+ * call-seq:
218
+ * in?(<i>point</i>) -> true or nil or false
219
+ *
220
+ * Determines whether the <i>point</i> is inside contour(true), outside(false) or lies on an edge(nil).
221
+ */
222
+ VALUE
223
+ rb_in_q(VALUE self, VALUE point)
224
+ {
225
+ double n = 0;
226
+ try {
227
+ n = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 0);
228
+ }
229
+ catch (cv::Exception& e) {
230
+ raise_cverror(e);
231
+ }
232
+ return n == 0 ? Qnil : n > 0 ? Qtrue : Qfalse;
233
+ }
234
+
235
+ /*
236
+ * call-seq:
237
+ * measure_distance(<i>point</i>) -> float
238
+ *
239
+ * Return distance between the point and the nearest contour edge.
240
+ */
241
+ VALUE
242
+ rb_measure_distance(VALUE self, VALUE point)
243
+ {
244
+ double distance = 0;
245
+ try {
246
+ distance = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 1);
247
+ }
248
+ catch (cv::Exception& e) {
249
+ raise_cverror(e);
250
+ }
251
+ return rb_float_new(distance);
252
+ }
253
+
254
+ /*
255
+ * call-seq:
256
+ * point_polygon_test(<i>point, measure_dist</i>) -> float
257
+ *
258
+ * Determines whether the point is inside a contour, outside, or lies on an edge (or coinsides with a vertex).
259
+ * It returns positive, negative or zero value, correspondingly. When measure_dist = false or 0, the return value is +1, -1 and 0, respectively. When measure_dist = true or 1, it is a signed distance between the point and the nearest contour edge.
260
+ */
261
+ VALUE
262
+ rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist)
263
+ {
264
+ int measure_dist_flag;
265
+
266
+ if (measure_dist == Qtrue)
267
+ measure_dist_flag = 1;
268
+ else if (measure_dist == Qfalse)
269
+ measure_dist_flag = 0;
270
+ else
271
+ measure_dist_flag = NUM2INT(measure_dist);
272
+
273
+ double dist = Qnil;
274
+ try {
275
+ dist = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), measure_dist_flag);
276
+ }
277
+ catch (cv::Exception& e) {
278
+ raise_cverror(e);
279
+ }
280
+
281
+ /* cvPointPolygonTest returns 100, -100 or 0 when measure_dist = 0 */
282
+ if ((!measure_dist_flag) && ((int)dist) != 0)
283
+ dist = (dist > 0) ? 1 : -1;
284
+
285
+ return rb_float_new(dist);
286
+ }
287
+
288
+ VALUE new_object()
289
+ {
290
+ VALUE object = rb_allocate(rb_klass);
291
+ rb_initialize(0, NULL, object);
292
+ return object;
293
+ }
294
+
295
+ __NAMESPACE_END_CVCONTOUR
296
+ __NAMESPACE_END_OPENCV
297
+
@@ -0,0 +1,48 @@
1
+ /************************************************************
2
+
3
+ cvcontour.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVCONTOUR_H
11
+ #define RUBY_OPENCV_CVCONTOUR_H
12
+ #include "opencv.h"
13
+
14
+ #define __NAMESPACE_BEGIN_CVCONTOUR namespace cCvContour {
15
+ #define __NAMESPACE_END_CVCONTOUR }
16
+
17
+ __NAMESPACE_BEGIN_OPENCV
18
+ __NAMESPACE_BEGIN_CVCONTOUR
19
+
20
+ VALUE rb_class();
21
+
22
+ void define_ruby_class();
23
+
24
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
25
+ VALUE rb_rect(VALUE self);
26
+ VALUE rb_color(VALUE self);
27
+ VALUE rb_set_color(VALUE self, VALUE color);
28
+ VALUE rb_reserved(VALUE self);
29
+ VALUE rb_approx_poly(int argc, VALUE *argv, VALUE self);
30
+ VALUE rb_bounding_rect(VALUE self);
31
+ VALUE rb_create_tree(int argc, VALUE *argv, VALUE self);
32
+ VALUE rb_in_q(VALUE self, VALUE point);
33
+ VALUE rb_measure_distance(VALUE self, VALUE point);
34
+ VALUE rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist);
35
+
36
+ VALUE new_object();
37
+ __NAMESPACE_END_CVCONTOUR
38
+
39
+ inline CvContour*
40
+ CVCONTOUR(VALUE object){
41
+ CvContour *ptr;
42
+ Data_Get_Struct(object, CvContour, ptr);
43
+ return ptr;
44
+ }
45
+
46
+ __NAMESPACE_END_OPENCV
47
+
48
+ #endif // RUBY_OPENCV_CVCONTOUR_H
@@ -0,0 +1,91 @@
1
+ /************************************************************
2
+
3
+ cvcontourtree.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvcontour.h"
11
+ /*
12
+ * Document-class: OpenCV::CvContourTree
13
+ *
14
+ * Contour tree. CvContour#create_tree
15
+ *
16
+ * C structure is here.
17
+ * typedef struct CvContourTree {
18
+ * CV_SEQUENCE_FIELDS()
19
+ * CvPoint p1;
20
+ * CvPoint p2;
21
+ * } CvContourTree;
22
+ *
23
+ */
24
+ __NAMESPACE_BEGIN_OPENCV
25
+ __NAMESPACE_BEGIN_CVCONTOURTREE
26
+
27
+ VALUE rb_klass;
28
+
29
+ VALUE
30
+ rb_class()
31
+ {
32
+ return rb_klass;
33
+ }
34
+
35
+ void
36
+ define_ruby_class()
37
+ {
38
+ if (rb_klass)
39
+ return;
40
+ /*
41
+ * opencv = rb_define_module("OpenCV");
42
+ * cvseq = rb_define_class_under(opencv, "CvSeq");
43
+ *
44
+ * note: this comment is used by rdoc.
45
+ */
46
+ VALUE opencv = rb_module_opencv();
47
+ VALUE cvseq = cCvSeq::rb_class();
48
+
49
+ rb_klass = rb_define_class_under(opencv, "CvContourTree", cvseq);
50
+ rb_define_method(rb_klass, "p1", RUBY_METHOD_FUNC(rb_p1), 0);
51
+ rb_define_method(rb_klass, "p2", RUBY_METHOD_FUNC(rb_p2), 0);
52
+ rb_define_method(rb_klass, "contour", RUBY_METHOD_FUNC(rb_contour), 1);
53
+ }
54
+
55
+ VALUE
56
+ rb_p1(VALUE self)
57
+ {
58
+ return REFER_OBJECT(cCvPoint::rb_class(), &CVCONTOURTREE(self)->p1, self);
59
+ }
60
+
61
+ VALUE
62
+ rb_p2(VALUE self)
63
+ {
64
+ return REFER_OBJECT(cCvPoint::rb_class(), &CVCONTOURTREE(self)->p2, self);
65
+ }
66
+
67
+ /*
68
+ * call-seq:
69
+ * contour(<i>[criteria = 0]</i>) -> cvcontour
70
+ *
71
+ * Restores the contour from its binary tree representation.
72
+ * The parameter criteria determines the accuracy and/or the number of tree levels
73
+ * used for reconstruction, so it is possible to build approximated contour.
74
+ */
75
+ VALUE
76
+ rb_contour(VALUE self, VALUE criteria)
77
+ {
78
+ VALUE storage = cCvMemStorage::new_object();
79
+ CvSeq *contour = NULL;
80
+ try {
81
+ contour = cvContourFromContourTree(CVCONTOURTREE(self), CVMEMSTORAGE(storage),
82
+ VALUE_TO_CVTERMCRITERIA(criteria));
83
+ }
84
+ catch (cv::Exception& e) {
85
+ raise_cverror(e);
86
+ }
87
+ return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
88
+ }
89
+
90
+ __NAMESPACE_END_CVCONTOURTREE
91
+ __NAMESPACE_END_OPENCV