ruby-opencv 0.0.8.pre-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. data/.gitignore +25 -0
  2. data/Gemfile +8 -0
  3. data/History.txt +5 -0
  4. data/License.txt +30 -0
  5. data/Manifest.txt +225 -0
  6. data/README.rdoc +149 -0
  7. data/Rakefile +32 -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/matching_to_many_images.rb +16 -0
  26. data/examples/matching_to_many_images/query.png +0 -0
  27. data/examples/matching_to_many_images/train/1.png +0 -0
  28. data/examples/matching_to_many_images/train/2.png +0 -0
  29. data/examples/matching_to_many_images/train/3.png +0 -0
  30. data/examples/matching_to_many_images/train/trainImages.txt +3 -0
  31. data/examples/paint.rb +70 -0
  32. data/examples/snake.rb +43 -0
  33. data/examples/stuff.jpg +0 -0
  34. data/examples/tiffany.jpg +0 -0
  35. data/ext/opencv/curve.cpp +112 -0
  36. data/ext/opencv/curve.h +34 -0
  37. data/ext/opencv/cvavgcomp.cpp +67 -0
  38. data/ext/opencv/cvavgcomp.h +39 -0
  39. data/ext/opencv/cvbox2d.cpp +197 -0
  40. data/ext/opencv/cvbox2d.h +61 -0
  41. data/ext/opencv/cvcapture.cpp +499 -0
  42. data/ext/opencv/cvcapture.h +72 -0
  43. data/ext/opencv/cvchain.cpp +233 -0
  44. data/ext/opencv/cvchain.h +46 -0
  45. data/ext/opencv/cvcircle32f.cpp +116 -0
  46. data/ext/opencv/cvcircle32f.h +52 -0
  47. data/ext/opencv/cvcondensation.cpp +282 -0
  48. data/ext/opencv/cvcondensation.h +49 -0
  49. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  50. data/ext/opencv/cvconnectedcomp.h +49 -0
  51. data/ext/opencv/cvcontour.cpp +296 -0
  52. data/ext/opencv/cvcontour.h +48 -0
  53. data/ext/opencv/cvcontourtree.cpp +91 -0
  54. data/ext/opencv/cvcontourtree.h +41 -0
  55. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  56. data/ext/opencv/cvconvexitydefect.h +42 -0
  57. data/ext/opencv/cverror.cpp +159 -0
  58. data/ext/opencv/cverror.h +28 -0
  59. data/ext/opencv/cvfeaturetree.cpp +125 -0
  60. data/ext/opencv/cvfeaturetree.h +55 -0
  61. data/ext/opencv/cvfont.cpp +208 -0
  62. data/ext/opencv/cvfont.h +64 -0
  63. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  64. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  65. data/ext/opencv/cvhistogram.cpp +546 -0
  66. data/ext/opencv/cvhistogram.h +73 -0
  67. data/ext/opencv/cvhumoments.cpp +139 -0
  68. data/ext/opencv/cvhumoments.h +51 -0
  69. data/ext/opencv/cvline.cpp +154 -0
  70. data/ext/opencv/cvline.h +54 -0
  71. data/ext/opencv/cvmat.cpp +5848 -0
  72. data/ext/opencv/cvmat.h +284 -0
  73. data/ext/opencv/cvmatnd.cpp +44 -0
  74. data/ext/opencv/cvmatnd.h +28 -0
  75. data/ext/opencv/cvmemstorage.cpp +68 -0
  76. data/ext/opencv/cvmemstorage.h +53 -0
  77. data/ext/opencv/cvmoments.cpp +287 -0
  78. data/ext/opencv/cvmoments.h +75 -0
  79. data/ext/opencv/cvpoint.cpp +228 -0
  80. data/ext/opencv/cvpoint.h +64 -0
  81. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  82. data/ext/opencv/cvpoint2d32f.h +63 -0
  83. data/ext/opencv/cvpoint3d32f.cpp +245 -0
  84. data/ext/opencv/cvpoint3d32f.h +66 -0
  85. data/ext/opencv/cvrect.cpp +333 -0
  86. data/ext/opencv/cvrect.h +79 -0
  87. data/ext/opencv/cvscalar.cpp +236 -0
  88. data/ext/opencv/cvscalar.h +71 -0
  89. data/ext/opencv/cvseq.cpp +599 -0
  90. data/ext/opencv/cvseq.h +74 -0
  91. data/ext/opencv/cvsize.cpp +221 -0
  92. data/ext/opencv/cvsize.h +65 -0
  93. data/ext/opencv/cvsize2d32f.cpp +209 -0
  94. data/ext/opencv/cvsize2d32f.h +64 -0
  95. data/ext/opencv/cvslice.cpp +120 -0
  96. data/ext/opencv/cvslice.h +61 -0
  97. data/ext/opencv/cvsparsemat.cpp +44 -0
  98. data/ext/opencv/cvsparsemat.h +28 -0
  99. data/ext/opencv/cvsurfparams.cpp +199 -0
  100. data/ext/opencv/cvsurfparams.h +58 -0
  101. data/ext/opencv/cvsurfpoint.cpp +223 -0
  102. data/ext/opencv/cvsurfpoint.h +52 -0
  103. data/ext/opencv/cvtermcriteria.cpp +192 -0
  104. data/ext/opencv/cvtermcriteria.h +71 -0
  105. data/ext/opencv/cvtwopoints.cpp +116 -0
  106. data/ext/opencv/cvtwopoints.h +51 -0
  107. data/ext/opencv/cvutils.cpp +194 -0
  108. data/ext/opencv/cvutils.h +29 -0
  109. data/ext/opencv/cvvideowriter.cpp +137 -0
  110. data/ext/opencv/cvvideowriter.h +43 -0
  111. data/ext/opencv/gui.cpp +68 -0
  112. data/ext/opencv/gui.h +30 -0
  113. data/ext/opencv/iplconvkernel.cpp +192 -0
  114. data/ext/opencv/iplconvkernel.h +71 -0
  115. data/ext/opencv/iplimage.cpp +644 -0
  116. data/ext/opencv/iplimage.h +73 -0
  117. data/ext/opencv/lib/opencv.rb +3 -0
  118. data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
  119. data/ext/opencv/lib/opencv/version.rb +3 -0
  120. data/ext/opencv/mouseevent.cpp +181 -0
  121. data/ext/opencv/mouseevent.h +56 -0
  122. data/ext/opencv/opencv.cpp +722 -0
  123. data/ext/opencv/opencv.h +400 -0
  124. data/ext/opencv/pointset.cpp +274 -0
  125. data/ext/opencv/pointset.h +68 -0
  126. data/ext/opencv/trackbar.cpp +121 -0
  127. data/ext/opencv/trackbar.h +69 -0
  128. data/ext/opencv/window.cpp +357 -0
  129. data/ext/opencv/window.h +66 -0
  130. data/extconf.rb +75 -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/opencv.rb +3 -0
  136. data/lib/opencv/psyched_yaml.rb +22 -0
  137. data/lib/opencv/version.rb +3 -0
  138. data/ruby-opencv.gemspec +43 -0
  139. data/test/helper.rb +166 -0
  140. data/test/runner.rb +30 -0
  141. data/test/samples/airplane.jpg +0 -0
  142. data/test/samples/baboon.jpg +0 -0
  143. data/test/samples/baboon200.jpg +0 -0
  144. data/test/samples/baboon200_rotated.jpg +0 -0
  145. data/test/samples/blank0.jpg +0 -0
  146. data/test/samples/blank1.jpg +0 -0
  147. data/test/samples/blank2.jpg +0 -0
  148. data/test/samples/blank3.jpg +0 -0
  149. data/test/samples/blank4.jpg +0 -0
  150. data/test/samples/blank5.jpg +0 -0
  151. data/test/samples/blank6.jpg +0 -0
  152. data/test/samples/blank7.jpg +0 -0
  153. data/test/samples/blank8.jpg +0 -0
  154. data/test/samples/blank9.jpg +0 -0
  155. data/test/samples/cat.jpg +0 -0
  156. data/test/samples/chessboard.jpg +0 -0
  157. data/test/samples/contours.jpg +0 -0
  158. data/test/samples/fruits.jpg +0 -0
  159. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  160. data/test/samples/inpaint-mask.bmp +0 -0
  161. data/test/samples/lena-256x256.jpg +0 -0
  162. data/test/samples/lena-32x32.jpg +0 -0
  163. data/test/samples/lena-eyes.jpg +0 -0
  164. data/test/samples/lena-inpaint.jpg +0 -0
  165. data/test/samples/lena.jpg +0 -0
  166. data/test/samples/lines.jpg +0 -0
  167. data/test/samples/messy0.jpg +0 -0
  168. data/test/samples/messy1.jpg +0 -0
  169. data/test/samples/movie_sample.avi +0 -0
  170. data/test/samples/one_way_train_0000.jpg +0 -0
  171. data/test/samples/one_way_train_0001.jpg +0 -0
  172. data/test/samples/partially_blank0.jpg +0 -0
  173. data/test/samples/partially_blank1.jpg +0 -0
  174. data/test/samples/smooth0.jpg +0 -0
  175. data/test/samples/smooth1.jpg +0 -0
  176. data/test/samples/smooth2.jpg +0 -0
  177. data/test/samples/smooth3.jpg +0 -0
  178. data/test/samples/smooth4.jpg +0 -0
  179. data/test/samples/smooth5.jpg +0 -0
  180. data/test/samples/smooth6.jpg +0 -0
  181. data/test/samples/str-cv-rotated.jpg +0 -0
  182. data/test/samples/str-cv.jpg +0 -0
  183. data/test/samples/str-ov.jpg +0 -0
  184. data/test/samples/stuff.jpg +0 -0
  185. data/test/test_curve.rb +43 -0
  186. data/test/test_cvavgcomp.rb +24 -0
  187. data/test/test_cvbox2d.rb +76 -0
  188. data/test/test_cvcapture.rb +183 -0
  189. data/test/test_cvchain.rb +108 -0
  190. data/test/test_cvcircle32f.rb +41 -0
  191. data/test/test_cvconnectedcomp.rb +61 -0
  192. data/test/test_cvcontour.rb +150 -0
  193. data/test/test_cvcontourtree.rb +43 -0
  194. data/test/test_cverror.rb +50 -0
  195. data/test/test_cvfeaturetree.rb +65 -0
  196. data/test/test_cvfont.rb +58 -0
  197. data/test/test_cvhaarclassifiercascade.rb +63 -0
  198. data/test/test_cvhistogram.rb +271 -0
  199. data/test/test_cvhumoments.rb +83 -0
  200. data/test/test_cvline.rb +50 -0
  201. data/test/test_cvmat.rb +2947 -0
  202. data/test/test_cvmat_drawing.rb +349 -0
  203. data/test/test_cvmat_dxt.rb +150 -0
  204. data/test/test_cvmat_imageprocessing.rb +2025 -0
  205. data/test/test_cvmat_matching.rb +57 -0
  206. data/test/test_cvmoments.rb +180 -0
  207. data/test/test_cvpoint.rb +75 -0
  208. data/test/test_cvpoint2d32f.rb +75 -0
  209. data/test/test_cvpoint3d32f.rb +93 -0
  210. data/test/test_cvrect.rb +144 -0
  211. data/test/test_cvscalar.rb +113 -0
  212. data/test/test_cvseq.rb +295 -0
  213. data/test/test_cvsize.rb +75 -0
  214. data/test/test_cvsize2d32f.rb +75 -0
  215. data/test/test_cvslice.rb +31 -0
  216. data/test/test_cvsurfparams.rb +57 -0
  217. data/test/test_cvsurfpoint.rb +66 -0
  218. data/test/test_cvtermcriteria.rb +56 -0
  219. data/test/test_cvtwopoints.rb +40 -0
  220. data/test/test_cvvideowriter.rb +58 -0
  221. data/test/test_iplconvkernel.rb +54 -0
  222. data/test/test_iplimage.rb +236 -0
  223. data/test/test_mouseevent.rb +17 -0
  224. data/test/test_opencv.rb +324 -0
  225. data/test/test_pointset.rb +126 -0
  226. data/test/test_preliminary.rb +130 -0
  227. data/test/test_trackbar.rb +47 -0
  228. data/test/test_window.rb +115 -0
  229. metadata +414 -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,296 @@
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_HASH(op, "method"), CV_POLY_APPROX_DP)
22
+ #define APPROX_POLY_ACCURACY(op) NUM2DBL(LOOKUP_HASH(op, "accuracy"))
23
+ #define APPROX_POLY_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_HASH(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
+ return Data_Wrap_Struct(klass, mark_root_object, unregister_object, NULL);
84
+ }
85
+
86
+ VALUE
87
+ rb_initialize(int argc, VALUE *argv, VALUE self)
88
+ {
89
+ VALUE storage;
90
+ rb_scan_args(argc, argv, "01", &storage);
91
+
92
+ if (NIL_P(storage))
93
+ storage = cCvMemStorage::new_object(0);
94
+ else
95
+ storage = CHECK_CVMEMSTORAGE(storage);
96
+
97
+ try {
98
+ DATA_PTR(self) = (CvContour*)cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvContour),
99
+ sizeof(CvPoint), CVMEMSTORAGE(storage));
100
+ }
101
+ catch (cv::Exception& e) {
102
+ raise_cverror(e);
103
+ }
104
+ cCvSeq::register_elem_class(CVSEQ(self), cCvPoint::rb_class());
105
+ register_root_object(CVSEQ(self), storage);
106
+
107
+ return self;
108
+ }
109
+
110
+ VALUE
111
+ rb_rect(VALUE self)
112
+ {
113
+ return cCvRect::new_object(CVCONTOUR(self)->rect);
114
+ }
115
+
116
+ VALUE
117
+ rb_color(VALUE self)
118
+ {
119
+ return INT2NUM(CVCONTOUR(self)->color);
120
+ }
121
+
122
+ VALUE
123
+ rb_set_color(VALUE self, VALUE color)
124
+ {
125
+ CVCONTOUR(self)->color = NUM2INT(color);
126
+ return self;
127
+ }
128
+
129
+ VALUE
130
+ rb_reserved(VALUE self)
131
+ {
132
+ return rb_ary_new3(3,
133
+ INT2NUM(CVCONTOUR(self)->reserved[0]),
134
+ INT2NUM(CVCONTOUR(self)->reserved[1]),
135
+ INT2NUM(CVCONTOUR(self)->reserved[2]));
136
+ }
137
+
138
+ /*
139
+ * call-seq:
140
+ * approx_poly(<i>approx_poly_option</i>) -> cvcontour
141
+ *
142
+ * Approximates polygonal curve(s) with desired precision.
143
+ * <i>approx_poly_option</i> should be Hash include these keys.
144
+ * :method - Approximation method.
145
+ * :dp - corresponds to Douglas-Peucker algorithm.
146
+ * :accuracy - approximation accuracy. (high-accuracy will create more simple contours)
147
+ * :recursive - (default false)
148
+ * If not nil or false, the function approximates all chains that access can be obtained to
149
+ * from self by h_next or v_next links. If 0, approximated this one.
150
+ */
151
+ VALUE
152
+ rb_approx_poly(int argc, VALUE *argv, VALUE self)
153
+ {
154
+ VALUE approx_poly_option;
155
+ rb_scan_args(argc, argv, "01", &approx_poly_option);
156
+ approx_poly_option = APPROX_POLY_OPTION(approx_poly_option);
157
+ VALUE storage = cCvMemStorage::new_object();
158
+ CvSeq *contour = cvApproxPoly(CVCONTOUR(self), sizeof(CvContour), CVMEMSTORAGE(storage),
159
+ APPROX_POLY_METHOD(approx_poly_option),
160
+ APPROX_POLY_ACCURACY(approx_poly_option),
161
+ APPROX_POLY_RECURSIVE(approx_poly_option));
162
+
163
+ if (contour && contour->total > 0) {
164
+ return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
165
+ }
166
+ return Qnil;
167
+ }
168
+
169
+ /*
170
+ * call-seq:
171
+ * bounding_rect -> rect
172
+ *
173
+ * Calculates up-right bounding rectangle of point set.
174
+ *
175
+ */
176
+ VALUE
177
+ rb_bounding_rect(VALUE self)
178
+ {
179
+ CvRect rect;
180
+ try {
181
+ rect = cvBoundingRect(CVCONTOUR(self), 1);
182
+ }
183
+ catch (cv::Exception& e) {
184
+ raise_cverror(e);
185
+ }
186
+ return cCvRect::new_object(rect);
187
+ }
188
+
189
+ /*
190
+ * call-seq:
191
+ * create_tree([threshold = 0.0]) -> cvcontourtree
192
+ *
193
+ * Creates hierarchical representation of contour.
194
+ * If the parameter <i>threshold</i> is less than or equal to 0,
195
+ * the method creates full binary tree representation.
196
+ * If the threshold is greater than 0, the function creates
197
+ * representation with the precision threshold:
198
+ */
199
+ VALUE
200
+ rb_create_tree(int argc, VALUE *argv, VALUE self)
201
+ {
202
+ VALUE threshold, storage;
203
+ rb_scan_args(argc, argv, "01", &threshold);
204
+ storage = cCvMemStorage::new_object();
205
+ CvContourTree *tree = NULL;
206
+ try {
207
+ tree = cvCreateContourTree(CVSEQ(self), CVMEMSTORAGE(storage), IF_DBL(threshold, 0.0));
208
+ }
209
+ catch (cv::Exception& e) {
210
+ raise_cverror(e);
211
+ }
212
+ return cCvSeq::new_sequence(cCvContourTree::rb_class(), (CvSeq*)tree, cCvPoint::rb_class(), storage);
213
+ }
214
+
215
+ /*
216
+ * call-seq:
217
+ * in?(<i>point</i>) -> true or nil or false
218
+ *
219
+ * Determines whether the <i>point</i> is inside contour(true), outside(false) or lies on an edge(nil).
220
+ */
221
+ VALUE
222
+ rb_in_q(VALUE self, VALUE point)
223
+ {
224
+ double n = 0;
225
+ try {
226
+ n = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 0);
227
+ }
228
+ catch (cv::Exception& e) {
229
+ raise_cverror(e);
230
+ }
231
+ return n == 0 ? Qnil : n > 0 ? Qtrue : Qfalse;
232
+ }
233
+
234
+ /*
235
+ * call-seq:
236
+ * measure_distance(<i>point</i>) -> float
237
+ *
238
+ * Return distance between the point and the nearest contour edge.
239
+ */
240
+ VALUE
241
+ rb_measure_distance(VALUE self, VALUE point)
242
+ {
243
+ double distance = 0;
244
+ try {
245
+ distance = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 1);
246
+ }
247
+ catch (cv::Exception& e) {
248
+ raise_cverror(e);
249
+ }
250
+ return rb_float_new(distance);
251
+ }
252
+
253
+ /*
254
+ * call-seq:
255
+ * point_polygon_test(<i>point, measure_dist</i>) -> float
256
+ *
257
+ * Determines whether the point is inside a contour, outside, or lies on an edge (or coinsides with a vertex).
258
+ * 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.
259
+ */
260
+ VALUE
261
+ rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist)
262
+ {
263
+ int measure_dist_flag;
264
+
265
+ if (measure_dist == Qtrue)
266
+ measure_dist_flag = 1;
267
+ else if (measure_dist == Qfalse)
268
+ measure_dist_flag = 0;
269
+ else
270
+ measure_dist_flag = NUM2INT(measure_dist);
271
+
272
+ double dist = Qnil;
273
+ try {
274
+ dist = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), measure_dist_flag);
275
+ }
276
+ catch (cv::Exception& e) {
277
+ raise_cverror(e);
278
+ }
279
+
280
+ /* cvPointPolygonTest returns 100, -100 or 0 when measure_dist = 0 */
281
+ if ((!measure_dist_flag) && ((int)dist) != 0)
282
+ dist = (dist > 0) ? 1 : -1;
283
+
284
+ return rb_float_new(dist);
285
+ }
286
+
287
+ VALUE new_object()
288
+ {
289
+ VALUE object = rb_allocate(rb_klass);
290
+ rb_initialize(0, NULL, object);
291
+ return object;
292
+ }
293
+
294
+ __NAMESPACE_END_CVCONTOUR
295
+ __NAMESPACE_END_OPENCV
296
+
@@ -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