ruby-opencv 0.0.8.pre-x86-mingw32

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 (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,55 @@
1
+ /************************************************************
2
+
3
+ cvfeaturetree.h -
4
+
5
+ $Author: ser1zw $
6
+
7
+ Copyright (C) 2011 ser1zw
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVFEATURETREE_H
11
+ #define RUBY_OPENCV_CVFEATURETREE_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVFEATURETREE namespace cCvFeatureTree {
16
+ #define __NAMESPACE_END_CVFEATURETREE }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVFEATURETREE
20
+
21
+ VALUE rb_class();
22
+ void define_ruby_class();
23
+ VALUE rb_allocate(VALUE klass);
24
+ VALUE rb_initialize(VALUE self, VALUE desc);
25
+ VALUE rb_find_features(VALUE self, VALUE desc, VALUE k, VALUE emax);
26
+
27
+ __NAMESPACE_END_CVFEATURETREE
28
+
29
+ typedef struct _CvFeatureTreeWrap {
30
+ CvFeatureTree* feature_tree;
31
+ VALUE desc;
32
+ } CvFeatureTreeWrap;
33
+
34
+ inline CvFeatureTree*
35
+ CVFEATURETREE(VALUE object)
36
+ {
37
+ CvFeatureTreeWrap* ptr;
38
+ Data_Get_Struct(object, CvFeatureTreeWrap, ptr);
39
+ return ptr->feature_tree;
40
+ }
41
+
42
+ inline CvFeatureTree*
43
+ CVFEATURETREE_WITH_CHECK(VALUE object)
44
+ {
45
+ if (!rb_obj_is_kind_of(object, cCvFeatureTree::rb_class()))
46
+ raise_typeerror(object, cCvFeatureTree::rb_class());
47
+ return CVFEATURETREE(object);
48
+ }
49
+
50
+ __NAMESPACE_END_OPENCV
51
+
52
+ #endif // RUBY_OPENCV_CVFEATURETREE
53
+
54
+
55
+
@@ -0,0 +1,208 @@
1
+ /************************************************************
2
+
3
+ cvfont.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvfont.h"
11
+ /*
12
+ * Document-class: OpenCV::CvFont
13
+ *
14
+ * Font structure that can be passed to text rendering functions.
15
+ * see CvMat#put_text, CvMat#put_text!
16
+ */
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVFONT
20
+
21
+ VALUE rb_klass;
22
+
23
+ int
24
+ rb_font_option_line_type(VALUE font_option)
25
+ {
26
+ VALUE line_type = LOOKUP_HASH(font_option, "line_type");
27
+ if (FIXNUM_P(line_type)) {
28
+ return FIX2INT(line_type);
29
+ }
30
+ else if (line_type == ID2SYM(rb_intern("aa"))) {
31
+ return CV_AA;
32
+ }
33
+ return 0;
34
+ }
35
+
36
+ VALUE
37
+ rb_class()
38
+ {
39
+ return rb_klass;
40
+ }
41
+
42
+ void
43
+ define_ruby_class()
44
+ {
45
+ if (rb_klass)
46
+ return;
47
+ /*
48
+ * opencv = rb_define_module("OpenCV");
49
+ *
50
+ * note: this comment is used by rdoc.
51
+ */
52
+ VALUE opencv = rb_module_opencv();
53
+
54
+ rb_klass = rb_define_class_under(opencv, "CvFont", rb_cObject);
55
+ rb_define_alloc_func(rb_klass, rb_allocate);
56
+ VALUE face = rb_hash_new();
57
+ rb_define_const(rb_klass, "FACE", face);
58
+ rb_hash_aset(face, ID2SYM(rb_intern("simplex")), INT2FIX(CV_FONT_HERSHEY_SIMPLEX));
59
+ rb_hash_aset(face, ID2SYM(rb_intern("plain")), INT2FIX(CV_FONT_HERSHEY_PLAIN));
60
+ rb_hash_aset(face, ID2SYM(rb_intern("duplex")), INT2FIX(CV_FONT_HERSHEY_DUPLEX));
61
+ rb_hash_aset(face, ID2SYM(rb_intern("triplex")), INT2FIX(CV_FONT_HERSHEY_TRIPLEX));
62
+ rb_hash_aset(face, ID2SYM(rb_intern("complex_small")), INT2FIX(CV_FONT_HERSHEY_COMPLEX_SMALL));
63
+ rb_hash_aset(face, ID2SYM(rb_intern("script_simplex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_SIMPLEX));
64
+ rb_hash_aset(face, ID2SYM(rb_intern("script_complex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_COMPLEX));
65
+
66
+ VALUE default_option = rb_hash_new();
67
+ rb_define_const(rb_klass, "FONT_OPTION", default_option);
68
+ rb_hash_aset(default_option, ID2SYM(rb_intern("hscale")), rb_float_new(1.0));
69
+ rb_hash_aset(default_option, ID2SYM(rb_intern("vscale")), rb_float_new(1.0));
70
+ rb_hash_aset(default_option, ID2SYM(rb_intern("shear")), INT2FIX(0));
71
+ rb_hash_aset(default_option, ID2SYM(rb_intern("thickness")), INT2FIX(1));
72
+ rb_hash_aset(default_option, ID2SYM(rb_intern("line_type")), INT2FIX(8));
73
+
74
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
75
+ rb_define_method(rb_klass, "face", RUBY_METHOD_FUNC(rb_face), 0);
76
+ rb_define_method(rb_klass, "hscale", RUBY_METHOD_FUNC(rb_hscale), 0);
77
+ rb_define_method(rb_klass, "vscale", RUBY_METHOD_FUNC(rb_vscale), 0);
78
+ rb_define_method(rb_klass, "shear", RUBY_METHOD_FUNC(rb_shear), 0);
79
+ rb_define_method(rb_klass, "thickness", RUBY_METHOD_FUNC(rb_thickness), 0);
80
+ rb_define_method(rb_klass, "line_type", RUBY_METHOD_FUNC(rb_line_type), 0);
81
+ rb_define_method(rb_klass, "italic", RUBY_METHOD_FUNC(rb_italic), 0);
82
+ }
83
+
84
+ VALUE
85
+ rb_allocate(VALUE klass)
86
+ {
87
+ CvFont *ptr;
88
+ return Data_Make_Struct(klass, CvFont, 0, -1, ptr);
89
+ }
90
+
91
+
92
+ /*
93
+ * call-seq:
94
+ * CvFont.new(<i>face[,font_option]</i>) -> font
95
+ *
96
+ * Create font object.
97
+ * <i>face</i> is font name identifier.
98
+ *
99
+ * Only a subset of Hershey fonts (http://sources.isc.org/utils/misc/hershey-font.txt) are supported now:
100
+ * * :simplex - normal size sans-serif font
101
+ * * :plain - small size sans-serif font
102
+ * * :duplex - normal size sans-serif font (more complex than :simplex)
103
+ * * :complex - normal size serif font
104
+ * * :triplex - normal size serif font (more complex than :complex)
105
+ * * :complex_small - smaller version of :complex
106
+ * * :script_simplex - hand-writing style font
107
+ * * :script_complex - more complex variant of :script_simplex
108
+ *
109
+ * <i>font_option</i> should be Hash include these keys.
110
+ * :hscale
111
+ * Horizontal scale. If equal to 1.0, the characters have the original width depending on the font type.
112
+ * If equal to 0.5, the characters are of half the original width.
113
+ * :vscale
114
+ * Vertical scale. If equal to 1.0, the characters have the original height depending on the font type.
115
+ * If equal to 0.5, the characters are of half the original height.
116
+ * :shear
117
+ * Approximate tangent of the character slope relative to the vertical line.
118
+ * Zero value means a non-italic font, 1.0f means ~45degree slope, etc.
119
+ * :thickness
120
+ * Thickness of the text strokes.
121
+ * :line_type
122
+ * Type of the strokes, see CvMat#Line description.
123
+ * :italic
124
+ * If value is not nil or false that means italic or oblique font.
125
+ *
126
+ * note: <i>font_option</i>'s default value is CvFont::FONT_OPTION.
127
+ *
128
+ * e.g. Create Font
129
+ * OpenCV::CvFont.new(:simplex, :hscale => 2, :vslace => 2, :italic => true)
130
+ * # create 2x bigger than normal, italic type font.
131
+ */
132
+ VALUE
133
+ rb_initialize(int argc, VALUE *argv, VALUE self)
134
+ {
135
+ VALUE face, font_option;
136
+ rb_scan_args(argc, argv, "11", &face, &font_option);
137
+ Check_Type(face, T_SYMBOL);
138
+ face = rb_hash_lookup(rb_const_get(cCvFont::rb_class(), rb_intern("FACE")), face);
139
+ if (NIL_P(face)) {
140
+ rb_raise(rb_eArgError, "undefined face.");
141
+ }
142
+ font_option = FONT_OPTION(font_option);
143
+
144
+ int font_face = NUM2INT(face);
145
+ if (FO_ITALIC(font_option)) {
146
+ font_face |= CV_FONT_ITALIC;
147
+ }
148
+ try {
149
+ cvInitFont(CVFONT(self),
150
+ font_face,
151
+ FO_HSCALE(font_option),
152
+ FO_VSCALE(font_option),
153
+ FO_SHEAR(font_option),
154
+ FO_THICKNESS(font_option),
155
+ FO_LINE_TYPE(font_option));
156
+ }
157
+ catch (cv::Exception& e) {
158
+ raise_cverror(e);
159
+ }
160
+
161
+ return self;
162
+ }
163
+
164
+
165
+ VALUE
166
+ rb_face(VALUE self)
167
+ {
168
+ return INT2FIX(CVFONT(self)->font_face);
169
+ }
170
+
171
+ VALUE
172
+ rb_hscale(VALUE self)
173
+ {
174
+ return rb_float_new(CVFONT(self)->hscale);
175
+ }
176
+
177
+ VALUE
178
+ rb_vscale(VALUE self)
179
+ {
180
+ return rb_float_new(CVFONT(self)->vscale);
181
+ }
182
+
183
+ VALUE
184
+ rb_shear(VALUE self)
185
+ {
186
+ return rb_float_new(CVFONT(self)->shear);
187
+ }
188
+
189
+ VALUE
190
+ rb_thickness(VALUE self)
191
+ {
192
+ return INT2FIX(CVFONT(self)->thickness);
193
+ }
194
+
195
+ VALUE
196
+ rb_line_type(VALUE self)
197
+ {
198
+ return INT2FIX(CVFONT(self)->line_type);
199
+ }
200
+
201
+ VALUE
202
+ rb_italic(VALUE self)
203
+ {
204
+ return ((CVFONT(self)->font_face & CV_FONT_ITALIC) > 0) ? Qtrue : Qfalse;
205
+ }
206
+
207
+ __NAMESPACE_END_CVFONT
208
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,64 @@
1
+ /************************************************************
2
+
3
+ cvfont.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVFONT_H
11
+ #define RUBY_OPENCV_CVFONT_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVFONT namespace cCvFont {
16
+ #define __NAMESPACE_END_CVFONT }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVFONT
20
+
21
+ #define FONT_OPTION(op) rb_get_option_table(rb_klass, "FONT_OPTION", op)
22
+ #define FO_ITALIC(op) TRUE_OR_FALSE(LOOKUP_HASH(op, "italic"))
23
+ #define FO_HSCALE(op) NUM2DBL(LOOKUP_HASH(op, "hscale"))
24
+ #define FO_VSCALE(op) NUM2DBL(LOOKUP_HASH(op, "vscale"))
25
+ #define FO_SHEAR(op) NUM2DBL(LOOKUP_HASH(op, "shear"))
26
+ #define FO_THICKNESS(op) NUM2INT(LOOKUP_HASH(op, "thickness"))
27
+ #define FO_LINE_TYPE(op) rb_font_option_line_type(op)
28
+
29
+ VALUE rb_class();
30
+
31
+ void define_ruby_class();
32
+
33
+ VALUE rb_allocate(VALUE klass);
34
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
35
+
36
+ VALUE rb_face(VALUE self);
37
+ VALUE rb_hscale(VALUE self);
38
+ VALUE rb_vscale(VALUE self);
39
+ VALUE rb_shear(VALUE self);
40
+ VALUE rb_thickness(VALUE self);
41
+ VALUE rb_line_type(VALUE self);
42
+ VALUE rb_italic(VALUE self);
43
+
44
+ __NAMESPACE_END_CVFONT
45
+
46
+ inline CvFont*
47
+ CVFONT(VALUE object)
48
+ {
49
+ CvFont *ptr;
50
+ Data_Get_Struct(object, CvFont, ptr);
51
+ return ptr;
52
+ }
53
+
54
+ inline CvFont*
55
+ CVFONT_WITH_CHECK(VALUE object)
56
+ {
57
+ if (!rb_obj_is_kind_of(object, cCvFont::rb_class()))
58
+ raise_typeerror(object, cCvFont::rb_class());
59
+ return CVFONT(object);
60
+ }
61
+
62
+ __NAMESPACE_END_OPENCV
63
+
64
+ #endif // RUBY_OPENCV_CVFONT_H
@@ -0,0 +1,168 @@
1
+ /************************************************************
2
+
3
+ cvhaarclassifercascade.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvhaarclassifiercascade.h"
11
+ /*
12
+ * Document-class: OpenCV::CvHaarClassifierCascade
13
+ *
14
+ * CvHaarClassifierCascade object is "fast-object-detector".
15
+ * This detector can discover object (e.g. human's face) from image.
16
+ *
17
+ * Find face-area from picture "lena"...
18
+ * link:../images/face_detect_from_lena.jpg
19
+ */
20
+ __NAMESPACE_BEGIN_OPENCV
21
+ __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
22
+
23
+ VALUE rb_klass;
24
+
25
+ VALUE
26
+ rb_class()
27
+ {
28
+ return rb_klass;
29
+ }
30
+
31
+ void define_ruby_class()
32
+ {
33
+ if (rb_klass)
34
+ return;
35
+ /*
36
+ * opencv = rb_define_module("OpenCV");
37
+ *
38
+ * note: this comment is used by rdoc.
39
+ */
40
+ VALUE opencv = rb_module_opencv();
41
+
42
+ rb_klass = rb_define_class_under(opencv, "CvHaarClassifierCascade", rb_cObject);
43
+ rb_define_alloc_func(rb_klass, rb_allocate);
44
+ rb_define_singleton_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load), 1);
45
+ rb_define_method(rb_klass, "detect_objects", RUBY_METHOD_FUNC(rb_detect_objects), -1);
46
+ }
47
+
48
+ VALUE
49
+ rb_allocate(VALUE klass)
50
+ {
51
+ return OPENCV_OBJECT(klass, 0);
52
+ }
53
+
54
+ void
55
+ cvhaarclassifiercascade_free(void* ptr)
56
+ {
57
+ if (ptr) {
58
+ CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)ptr;
59
+ cvReleaseHaarClassifierCascade(&cascade);
60
+ }
61
+ }
62
+
63
+ /*
64
+ * call-seq:
65
+ * CvHaarClassiferCascade.load(<i>path</i>) -> object-detector
66
+ *
67
+ * Load trained cascade of haar classifers from file.
68
+ * Object detection classifiers are stored in XML or YAML files.
69
+ * sample of object detection classifier files is included by OpenCV.
70
+ *
71
+ * You can found these at
72
+ * C:\Program Files\OpenCV\data\haarcascades\*.xml (Windows, default install path)
73
+ *
74
+ * e.g. you want to try to detect human's face.
75
+ * detector = CvHaarClassiferCascade.load("haarcascade_frontalface_alt.xml")
76
+ */
77
+ VALUE
78
+ rb_load(VALUE klass, VALUE path)
79
+ {
80
+ CvHaarClassifierCascade *cascade = NULL;
81
+ try {
82
+ cascade = (CvHaarClassifierCascade*)cvLoad(StringValueCStr(path), 0, 0, 0);
83
+ }
84
+ catch (cv::Exception& e) {
85
+ raise_cverror(e);
86
+ }
87
+ if (!CV_IS_HAAR_CLASSIFIER(cascade))
88
+ rb_raise(rb_eArgError, "invalid format haar classifier cascade file.");
89
+ return Data_Wrap_Struct(klass, 0, cvhaarclassifiercascade_free, cascade);
90
+ }
91
+
92
+ /*
93
+ * call-seq:
94
+ * detect_objects(image[, options]) -> cvseq(include CvAvgComp object)
95
+ * detect_objects(image[, options]){|cmp| ... } -> cvseq(include CvAvgComp object)
96
+ *
97
+ * Detects objects in the image. This method finds rectangular regions in the
98
+ * given image that are likely to contain objects the cascade has been trained
99
+ * for and return those regions as a sequence of rectangles.
100
+ *
101
+ * * <i>option</i> should be Hash include these keys.
102
+ * :scale_factor (should be > 1.0)
103
+ * The factor by which the search window is scaled between the subsequent scans,
104
+ * 1.1 mean increasing window by 10%.
105
+ * :storage
106
+ * Memory storage to store the resultant sequence of the object candidate rectangles
107
+ * :flags
108
+ * Mode of operation. Currently the only flag that may be specified is CV_HAAR_DO_CANNY_PRUNING .
109
+ * If it is set, the function uses Canny edge detector to reject some image regions that contain
110
+ * too few or too much edges and thus can not contain the searched object. The particular threshold
111
+ * values are tuned for face detection and in this case the pruning speeds up the processing
112
+ * :min_neighbors
113
+ * Minimum number (minus 1) of neighbor rectangles that makes up an object.
114
+ * All the groups of a smaller number of rectangles than min_neighbors - 1 are rejected.
115
+ * If min_neighbors is 0, the function does not any grouping at all and returns all the detected
116
+ * candidate rectangles, whitch many be useful if the user wants to apply a customized grouping procedure.
117
+ * :min_size
118
+ * Minimum window size. By default, it is set to size of samples the classifier has been
119
+ * trained on (~20x20 for face detection).
120
+ * :max_size
121
+ * aximum window size to use. By default, it is set to the size of the image.
122
+ */
123
+ VALUE
124
+ rb_detect_objects(int argc, VALUE *argv, VALUE self)
125
+ {
126
+ VALUE image, options;
127
+ rb_scan_args(argc, argv, "11", &image, &options);
128
+
129
+ double scale_factor;
130
+ int flags, min_neighbors;
131
+ CvSize min_size, max_size;
132
+ VALUE storage_val;
133
+ if (NIL_P(options)) {
134
+ scale_factor = 1.1;
135
+ flags = 0;
136
+ min_neighbors = 3;
137
+ min_size = max_size = cvSize(0, 0);
138
+ storage_val = cCvMemStorage::new_object();
139
+ }
140
+ else {
141
+ scale_factor = IF_DBL(LOOKUP_HASH(options, "scale_factor"), 1.1);
142
+ flags = IF_INT(LOOKUP_HASH(options, "flags"), 0);
143
+ min_neighbors = IF_INT(LOOKUP_HASH(options, "min_neighbors"), 3);
144
+ VALUE min_size_val = LOOKUP_HASH(options, "min_size");
145
+ min_size = NIL_P(min_size_val) ? cvSize(0, 0) : VALUE_TO_CVSIZE(min_size_val);
146
+ VALUE max_size_val = LOOKUP_HASH(options, "max_size");
147
+ max_size = NIL_P(max_size_val) ? cvSize(0, 0) : VALUE_TO_CVSIZE(max_size_val);
148
+ storage_val = CHECK_CVMEMSTORAGE(LOOKUP_HASH(options, "storage"));
149
+ }
150
+
151
+ VALUE result = Qnil;
152
+ try {
153
+ CvSeq *seq = cvHaarDetectObjects(CVARR_WITH_CHECK(image), CVHAARCLASSIFIERCASCADE(self), CVMEMSTORAGE(storage_val),
154
+ scale_factor, min_neighbors, flags, min_size, max_size);
155
+ result = cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvAvgComp::rb_class(), storage_val);
156
+ if (rb_block_given_p()) {
157
+ for(int i = 0; i < seq->total; ++i)
158
+ rb_yield(REFER_OBJECT(cCvAvgComp::rb_class(), cvGetSeqElem(seq, i), storage_val));
159
+ }
160
+ }
161
+ catch (cv::Exception& e) {
162
+ raise_cverror(e);
163
+ }
164
+ return result;
165
+ }
166
+
167
+ __NAMESPACE_END_CVHAARCLASSIFERCASCADE
168
+ __NAMESPACE_END_OPENCV