jf-ruby-opencv 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.yardopts +3 -0
  4. data/DEVELOPERS_NOTE.md +137 -0
  5. data/Gemfile +9 -0
  6. data/History.txt +5 -0
  7. data/License.txt +30 -0
  8. data/Manifest.txt +239 -0
  9. data/README.md +94 -0
  10. data/Rakefile +99 -0
  11. data/config.yml +7 -0
  12. data/examples/alpha_blend.rb +21 -0
  13. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  14. data/examples/contours/bitmap-contours.png +0 -0
  15. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  16. data/examples/contours/contour_retrieval_modes.rb +139 -0
  17. data/examples/contours/rotated-boxes.jpg +0 -0
  18. data/examples/convexhull.rb +47 -0
  19. data/examples/face_detect.rb +20 -0
  20. data/examples/facerec/create_csv.rb +43 -0
  21. data/examples/facerec/facerec_eigenfaces.rb +132 -0
  22. data/examples/facerec/facerec_fisherfaces.rb +131 -0
  23. data/examples/facerec/facerec_lbph.rb +116 -0
  24. data/examples/facerec/readme.md +111 -0
  25. data/examples/find_obj.rb +169 -0
  26. data/examples/houghcircle.rb +22 -0
  27. data/examples/images/box.png +0 -0
  28. data/examples/images/box_in_scene.png +0 -0
  29. data/examples/images/inpaint.png +0 -0
  30. data/examples/images/lena-256x256.jpg +0 -0
  31. data/examples/images/lena-eyes.jpg +0 -0
  32. data/examples/images/lenna-rotated.jpg +0 -0
  33. data/examples/images/lenna.jpg +0 -0
  34. data/examples/images/stuff.jpg +0 -0
  35. data/examples/images/tiffany.jpg +0 -0
  36. data/examples/inpaint.rb +57 -0
  37. data/examples/match_kdtree.rb +88 -0
  38. data/examples/match_template.rb +26 -0
  39. data/examples/paint.rb +70 -0
  40. data/examples/snake.rb +43 -0
  41. data/ext/opencv/algorithm.cpp +291 -0
  42. data/ext/opencv/algorithm.h +38 -0
  43. data/ext/opencv/curve.cpp +127 -0
  44. data/ext/opencv/curve.h +34 -0
  45. data/ext/opencv/cvavgcomp.cpp +64 -0
  46. data/ext/opencv/cvavgcomp.h +39 -0
  47. data/ext/opencv/cvbox2d.cpp +195 -0
  48. data/ext/opencv/cvbox2d.h +61 -0
  49. data/ext/opencv/cvcapture.cpp +633 -0
  50. data/ext/opencv/cvcapture.h +82 -0
  51. data/ext/opencv/cvchain.cpp +233 -0
  52. data/ext/opencv/cvchain.h +46 -0
  53. data/ext/opencv/cvcircle32f.cpp +126 -0
  54. data/ext/opencv/cvcircle32f.h +52 -0
  55. data/ext/opencv/cvconnectedcomp.cpp +156 -0
  56. data/ext/opencv/cvconnectedcomp.h +49 -0
  57. data/ext/opencv/cvcontour.cpp +384 -0
  58. data/ext/opencv/cvcontour.h +51 -0
  59. data/ext/opencv/cvcontourtree.cpp +96 -0
  60. data/ext/opencv/cvcontourtree.h +41 -0
  61. data/ext/opencv/cvconvexitydefect.cpp +92 -0
  62. data/ext/opencv/cvconvexitydefect.h +42 -0
  63. data/ext/opencv/cverror.cpp +115 -0
  64. data/ext/opencv/cverror.h +28 -0
  65. data/ext/opencv/cvfeaturetree.cpp +123 -0
  66. data/ext/opencv/cvfeaturetree.h +55 -0
  67. data/ext/opencv/cvfont.cpp +228 -0
  68. data/ext/opencv/cvfont.h +64 -0
  69. data/ext/opencv/cvhaarclassifiercascade.cpp +148 -0
  70. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  71. data/ext/opencv/cvhistogram.cpp +717 -0
  72. data/ext/opencv/cvhistogram.h +73 -0
  73. data/ext/opencv/cvhumoments.cpp +178 -0
  74. data/ext/opencv/cvhumoments.h +51 -0
  75. data/ext/opencv/cvline.cpp +159 -0
  76. data/ext/opencv/cvline.h +54 -0
  77. data/ext/opencv/cvmat.cpp +6086 -0
  78. data/ext/opencv/cvmat.h +290 -0
  79. data/ext/opencv/cvmemstorage.cpp +73 -0
  80. data/ext/opencv/cvmemstorage.h +50 -0
  81. data/ext/opencv/cvmoments.cpp +293 -0
  82. data/ext/opencv/cvmoments.h +75 -0
  83. data/ext/opencv/cvpoint.cpp +234 -0
  84. data/ext/opencv/cvpoint.h +64 -0
  85. data/ext/opencv/cvpoint2d32f.cpp +216 -0
  86. data/ext/opencv/cvpoint2d32f.h +63 -0
  87. data/ext/opencv/cvpoint3d32f.cpp +252 -0
  88. data/ext/opencv/cvpoint3d32f.h +66 -0
  89. data/ext/opencv/cvrect.cpp +338 -0
  90. data/ext/opencv/cvrect.h +79 -0
  91. data/ext/opencv/cvscalar.cpp +241 -0
  92. data/ext/opencv/cvscalar.h +71 -0
  93. data/ext/opencv/cvseq.cpp +663 -0
  94. data/ext/opencv/cvseq.h +75 -0
  95. data/ext/opencv/cvsize.cpp +227 -0
  96. data/ext/opencv/cvsize.h +65 -0
  97. data/ext/opencv/cvsize2d32f.cpp +215 -0
  98. data/ext/opencv/cvsize2d32f.h +64 -0
  99. data/ext/opencv/cvslice.cpp +126 -0
  100. data/ext/opencv/cvslice.h +61 -0
  101. data/ext/opencv/cvsurfparams.cpp +208 -0
  102. data/ext/opencv/cvsurfparams.h +58 -0
  103. data/ext/opencv/cvsurfpoint.cpp +246 -0
  104. data/ext/opencv/cvsurfpoint.h +52 -0
  105. data/ext/opencv/cvtermcriteria.cpp +198 -0
  106. data/ext/opencv/cvtermcriteria.h +71 -0
  107. data/ext/opencv/cvtwopoints.cpp +122 -0
  108. data/ext/opencv/cvtwopoints.h +51 -0
  109. data/ext/opencv/cvutils.cpp +192 -0
  110. data/ext/opencv/cvutils.h +30 -0
  111. data/ext/opencv/cvvideowriter.cpp +142 -0
  112. data/ext/opencv/cvvideowriter.h +43 -0
  113. data/ext/opencv/eigenfaces.cpp +75 -0
  114. data/ext/opencv/eigenfaces.h +30 -0
  115. data/ext/opencv/extconf.rb +77 -0
  116. data/ext/opencv/facerecognizer.cpp +219 -0
  117. data/ext/opencv/facerecognizer.h +46 -0
  118. data/ext/opencv/fisherfaces.cpp +75 -0
  119. data/ext/opencv/fisherfaces.h +30 -0
  120. data/ext/opencv/gui.cpp +71 -0
  121. data/ext/opencv/gui.h +30 -0
  122. data/ext/opencv/iplconvkernel.cpp +198 -0
  123. data/ext/opencv/iplconvkernel.h +71 -0
  124. data/ext/opencv/iplimage.cpp +651 -0
  125. data/ext/opencv/iplimage.h +73 -0
  126. data/ext/opencv/lbph.cpp +78 -0
  127. data/ext/opencv/lbph.h +30 -0
  128. data/ext/opencv/mouseevent.cpp +186 -0
  129. data/ext/opencv/mouseevent.h +56 -0
  130. data/ext/opencv/opencv.cpp +819 -0
  131. data/ext/opencv/opencv.h +408 -0
  132. data/ext/opencv/pointset.cpp +280 -0
  133. data/ext/opencv/pointset.h +68 -0
  134. data/ext/opencv/trackbar.cpp +127 -0
  135. data/ext/opencv/trackbar.h +69 -0
  136. data/ext/opencv/window.cpp +377 -0
  137. data/ext/opencv/window.h +66 -0
  138. data/images/CvMat_sobel.png +0 -0
  139. data/images/CvMat_sub_rect.png +0 -0
  140. data/images/CvSeq_relationmap.png +0 -0
  141. data/lib/opencv.rb +12 -0
  142. data/lib/opencv/psyched_yaml.rb +22 -0
  143. data/lib/opencv/version.rb +3 -0
  144. data/ruby-opencv.gemspec +44 -0
  145. data/test/eigenfaces_save.xml +7524 -0
  146. data/test/fisherfaces_save.xml +7530 -0
  147. data/test/helper.rb +167 -0
  148. data/test/lbph_save.xml +4304 -0
  149. data/test/runner.rb +30 -0
  150. data/test/samples/airplane.jpg +0 -0
  151. data/test/samples/baboon.jpg +0 -0
  152. data/test/samples/baboon200.jpg +0 -0
  153. data/test/samples/baboon200_rotated.jpg +0 -0
  154. data/test/samples/blank0.jpg +0 -0
  155. data/test/samples/blank1.jpg +0 -0
  156. data/test/samples/blank2.jpg +0 -0
  157. data/test/samples/blank3.jpg +0 -0
  158. data/test/samples/blank4.jpg +0 -0
  159. data/test/samples/blank5.jpg +0 -0
  160. data/test/samples/blank6.jpg +0 -0
  161. data/test/samples/blank7.jpg +0 -0
  162. data/test/samples/blank8.jpg +0 -0
  163. data/test/samples/blank9.jpg +0 -0
  164. data/test/samples/cat.jpg +0 -0
  165. data/test/samples/chessboard.jpg +0 -0
  166. data/test/samples/contours.jpg +0 -0
  167. data/test/samples/fruits.jpg +0 -0
  168. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  169. data/test/samples/inpaint-mask.bmp +0 -0
  170. data/test/samples/lena-256x256.jpg +0 -0
  171. data/test/samples/lena-32x32.jpg +0 -0
  172. data/test/samples/lena-eyes.jpg +0 -0
  173. data/test/samples/lena-inpaint.jpg +0 -0
  174. data/test/samples/lena.jpg +0 -0
  175. data/test/samples/lines.jpg +0 -0
  176. data/test/samples/messy0.jpg +0 -0
  177. data/test/samples/messy1.jpg +0 -0
  178. data/test/samples/movie_sample.avi +0 -0
  179. data/test/samples/one_way_train_0000.jpg +0 -0
  180. data/test/samples/one_way_train_0001.jpg +0 -0
  181. data/test/samples/partially_blank0.jpg +0 -0
  182. data/test/samples/partially_blank1.jpg +0 -0
  183. data/test/samples/smooth0.jpg +0 -0
  184. data/test/samples/smooth1.jpg +0 -0
  185. data/test/samples/smooth2.jpg +0 -0
  186. data/test/samples/smooth3.jpg +0 -0
  187. data/test/samples/smooth4.jpg +0 -0
  188. data/test/samples/smooth5.jpg +0 -0
  189. data/test/samples/smooth6.jpg +0 -0
  190. data/test/samples/str-cv-rotated.jpg +0 -0
  191. data/test/samples/str-cv.jpg +0 -0
  192. data/test/samples/str-ov.jpg +0 -0
  193. data/test/samples/stuff.jpg +0 -0
  194. data/test/test_curve.rb +43 -0
  195. data/test/test_cvavgcomp.rb +24 -0
  196. data/test/test_cvbox2d.rb +76 -0
  197. data/test/test_cvcapture.rb +191 -0
  198. data/test/test_cvchain.rb +108 -0
  199. data/test/test_cvcircle32f.rb +41 -0
  200. data/test/test_cvconnectedcomp.rb +61 -0
  201. data/test/test_cvcontour.rb +171 -0
  202. data/test/test_cvcontourtree.rb +43 -0
  203. data/test/test_cverror.rb +50 -0
  204. data/test/test_cvfeaturetree.rb +65 -0
  205. data/test/test_cvfont.rb +58 -0
  206. data/test/test_cvhaarclassifiercascade.rb +63 -0
  207. data/test/test_cvhistogram.rb +271 -0
  208. data/test/test_cvhumoments.rb +83 -0
  209. data/test/test_cvline.rb +50 -0
  210. data/test/test_cvmat.rb +3036 -0
  211. data/test/test_cvmat_drawing.rb +349 -0
  212. data/test/test_cvmat_dxt.rb +150 -0
  213. data/test/test_cvmat_imageprocessing.rb +2085 -0
  214. data/test/test_cvmoments.rb +180 -0
  215. data/test/test_cvpoint.rb +75 -0
  216. data/test/test_cvpoint2d32f.rb +75 -0
  217. data/test/test_cvpoint3d32f.rb +93 -0
  218. data/test/test_cvrect.rb +144 -0
  219. data/test/test_cvscalar.rb +113 -0
  220. data/test/test_cvseq.rb +311 -0
  221. data/test/test_cvsize.rb +75 -0
  222. data/test/test_cvsize2d32f.rb +75 -0
  223. data/test/test_cvslice.rb +31 -0
  224. data/test/test_cvsurfparams.rb +57 -0
  225. data/test/test_cvsurfpoint.rb +66 -0
  226. data/test/test_cvtermcriteria.rb +56 -0
  227. data/test/test_cvtwopoints.rb +40 -0
  228. data/test/test_cvvideowriter.rb +58 -0
  229. data/test/test_eigenfaces.rb +93 -0
  230. data/test/test_fisherfaces.rb +93 -0
  231. data/test/test_iplconvkernel.rb +54 -0
  232. data/test/test_iplimage.rb +232 -0
  233. data/test/test_lbph.rb +166 -0
  234. data/test/test_mouseevent.rb +17 -0
  235. data/test/test_opencv.rb +360 -0
  236. data/test/test_pointset.rb +128 -0
  237. data/test/test_preliminary.rb +130 -0
  238. data/test/test_trackbar.rb +47 -0
  239. data/test/test_window.rb +115 -0
  240. data/yard_extension.rb +5 -0
  241. metadata +352 -0
@@ -0,0 +1,123 @@
1
+ /************************************************************
2
+
3
+ cvfeaturetree.cpp -
4
+
5
+ $Author: ser1zw $
6
+
7
+ Copyright (C) 2011 ser1zw
8
+
9
+ ************************************************************/
10
+ #include "cvfeaturetree.h"
11
+ /*
12
+ * Document-class: OpenCV::CvFeatureTree
13
+ */
14
+ __NAMESPACE_BEGIN_OPENCV
15
+ __NAMESPACE_BEGIN_CVFEATURETREE
16
+
17
+ VALUE rb_klass;
18
+
19
+ VALUE
20
+ rb_class()
21
+ {
22
+ return rb_klass;
23
+ }
24
+
25
+ void
26
+ mark_feature_tree(void *ptr)
27
+ {
28
+ if (ptr) {
29
+ VALUE desc = ((CvFeatureTreeWrap*)ptr)->desc;
30
+ rb_gc_mark(desc);
31
+ }
32
+ }
33
+
34
+ void
35
+ rb_release_feature_tree(void *ptr)
36
+ {
37
+ if (ptr) {
38
+ CvFeatureTree* ft = ((CvFeatureTreeWrap*)ptr)->feature_tree;
39
+ cvReleaseFeatureTree(ft);
40
+ }
41
+ }
42
+
43
+ VALUE
44
+ rb_allocate(VALUE klass)
45
+ {
46
+ CvFeatureTreeWrap* ptr;
47
+ return Data_Make_Struct(klass, CvFeatureTreeWrap, mark_feature_tree,
48
+ rb_release_feature_tree, ptr);
49
+ }
50
+
51
+ /*
52
+ * Create a new kd-tree
53
+ * @overload new(desc)
54
+ * @param desc [CvMat] Descriptors
55
+ * @return [CvFeatureTree] self
56
+ * @opencv_func cvCreateKDTree
57
+ */
58
+ VALUE
59
+ rb_initialize(VALUE self, VALUE desc)
60
+ {
61
+ CvMat* desc_mat = CVMAT_WITH_CHECK(desc);
62
+ CvFeatureTreeWrap* self_ptr = (CvFeatureTreeWrap*)DATA_PTR(self);
63
+ free(self_ptr);
64
+ self_ptr = ALLOC(CvFeatureTreeWrap);
65
+ try {
66
+ self_ptr->feature_tree = cvCreateKDTree(desc_mat);
67
+ }
68
+ catch (cv::Exception& e) {
69
+ raise_cverror(e);
70
+ }
71
+ self_ptr->desc = desc;
72
+ return self;
73
+ }
74
+
75
+ /*
76
+ * Find features from kd-tree
77
+ * @overload find_features(desc, k, emax)
78
+ * @param desc [CvMat] m x d matrix of (row-)vectors to find the nearest neighbors of.
79
+ * @param k [Integer] The number of neighbors to find.
80
+ * @param emax [Integer] The maximum number of leaves to visit.
81
+ * @return [Array] Array of [results, dist]
82
+ * - results: m x k set of row indices of matching vectors (referring to matrix passed to cvCreateFeatureTree). Contains -1 in some columns if fewer than k neighbors found.
83
+ * - dist: m x k matrix of distances to k nearest neighbors.
84
+ * @opencv_func cvFindFeatures
85
+ */
86
+ VALUE
87
+ rb_find_features(VALUE self, VALUE desc, VALUE k, VALUE emax)
88
+ {
89
+ CvMat* desc_mat = CVMAT_WITH_CHECK(desc);
90
+ int _k = NUM2INT(k);
91
+ VALUE results = cCvMat::new_object(desc_mat->rows, _k, CV_32SC1);
92
+ VALUE dist = cCvMat::new_object(desc_mat->rows, _k, CV_64FC1);
93
+ try {
94
+ cvFindFeatures(CVFEATURETREE(self), desc_mat, CVMAT(results), CVMAT(dist), _k, NUM2INT(emax));
95
+ }
96
+ catch (cv::Exception& e) {
97
+ raise_cverror(e);
98
+ }
99
+ return rb_assoc_new(results, dist);
100
+ }
101
+
102
+ void
103
+ init_ruby_class()
104
+ {
105
+ #if 0
106
+ // For documentation using YARD
107
+ VALUE opencv = rb_define_module("OpenCV");
108
+ #endif
109
+
110
+ if (rb_klass)
111
+ return;
112
+
113
+ VALUE opencv = rb_module_opencv();
114
+ rb_klass = rb_define_class_under(opencv, "CvFeatureTree", rb_cObject);
115
+ rb_define_alloc_func(rb_klass, rb_allocate);
116
+ rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), 1);
117
+
118
+ rb_define_method(rb_klass, "find_features", RUBY_METHOD_FUNC(rb_find_features), 3);
119
+ }
120
+
121
+ __NAMESPACE_END_OPENCV
122
+ __NAMESPACE_END_CVFEATURETREE
123
+
@@ -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 init_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,228 @@
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
+ VALUE
43
+ rb_allocate(VALUE klass)
44
+ {
45
+ CvFont *ptr;
46
+ return Data_Make_Struct(klass, CvFont, 0, -1, ptr);
47
+ }
48
+
49
+ /*
50
+ * Create font object
51
+ * @overload new(face, font_option = nil)
52
+ * @param face [Symbol] Font name identifier. Only a subset of Hershey fonts (http://sources.isc.org/utils/misc/hershey-font.txt) are supported now:
53
+ * - :simplex - normal size sans-serif font
54
+ * - :plain - small size sans-serif font
55
+ * - :duplex - normal size sans-serif font (more complex than :simplex)
56
+ * - :complex - normal size serif font
57
+ * - :triplex - normal size serif font (more complex than :complex)
58
+ * - :complex_small - smaller version of :complex
59
+ * - :script_simplex - hand-writing style font
60
+ * - :script_complex - more complex variant of :script_simplex
61
+ *
62
+ * @param font_option [Hash] should be Hash include these keys.
63
+ * @option font_option [Number] :hscale Horizontal scale. If equal to 1.0, the characters have the original width depending on the font type. If equal to 0.5, the characters are of half the original width.
64
+ * @option font_option [Number] :vscale Vertical scale. If equal to 1.0, the characters have the original height depending on the font type. If equal to 0.5, the characters are of half the original height.
65
+ * @option font_option [Number] :shear Approximate tangent of the character slope relative to the vertical line. Zero value means a non-italic font, 1.0f means ~45 degree slope, etc.
66
+ * @option font_option [Number] :thickness Thickness of the text strokes.
67
+ * @option font_option [Number] :line_type Type of the strokes, see CvMat#Line description.
68
+ * @option font_option [Number] :italic If value is not nil or false that means italic or oblique font.
69
+ *
70
+ * @example Create Font
71
+ * OpenCV::CvFont.new(:simplex, :hscale => 2, :vslace => 2, :italic => true)
72
+ * # create 2x bigger than normal, italic type font.
73
+ *
74
+ * @opencv_func cvInitFont
75
+ */
76
+ VALUE
77
+ rb_initialize(int argc, VALUE *argv, VALUE self)
78
+ {
79
+ VALUE face, font_option;
80
+ rb_scan_args(argc, argv, "11", &face, &font_option);
81
+ Check_Type(face, T_SYMBOL);
82
+ face = rb_hash_lookup(rb_const_get(cCvFont::rb_class(), rb_intern("FACE")), face);
83
+ if (NIL_P(face)) {
84
+ rb_raise(rb_eArgError, "undefined face.");
85
+ }
86
+ font_option = FONT_OPTION(font_option);
87
+
88
+ int font_face = NUM2INT(face);
89
+ if (FO_ITALIC(font_option)) {
90
+ font_face |= CV_FONT_ITALIC;
91
+ }
92
+ try {
93
+ cvInitFont(CVFONT(self),
94
+ font_face,
95
+ FO_HSCALE(font_option),
96
+ FO_VSCALE(font_option),
97
+ FO_SHEAR(font_option),
98
+ FO_THICKNESS(font_option),
99
+ FO_LINE_TYPE(font_option));
100
+ }
101
+ catch (cv::Exception& e) {
102
+ raise_cverror(e);
103
+ }
104
+
105
+ return self;
106
+ }
107
+
108
+ /*
109
+ * Returns font face
110
+ * @overload face
111
+ * @return [Integer] Font face
112
+ */
113
+ VALUE
114
+ rb_face(VALUE self)
115
+ {
116
+ return INT2FIX(CVFONT(self)->font_face);
117
+ }
118
+
119
+ /*
120
+ * Returns hscale
121
+ * @overload hscale
122
+ * @return [Number] hscale
123
+ */
124
+ VALUE
125
+ rb_hscale(VALUE self)
126
+ {
127
+ return rb_float_new(CVFONT(self)->hscale);
128
+ }
129
+
130
+ /*
131
+ * Returns vscale
132
+ * @overload vscale
133
+ * @return [Number] vscale
134
+ */
135
+ VALUE
136
+ rb_vscale(VALUE self)
137
+ {
138
+ return rb_float_new(CVFONT(self)->vscale);
139
+ }
140
+
141
+ /*
142
+ * Returns shear
143
+ * @overload shear
144
+ * @return [Number] shear
145
+ */
146
+ VALUE
147
+ rb_shear(VALUE self)
148
+ {
149
+ return rb_float_new(CVFONT(self)->shear);
150
+ }
151
+
152
+ /*
153
+ * Returns thickness
154
+ * @overload thickness
155
+ * @return [Integer] thickness
156
+ */
157
+ VALUE
158
+ rb_thickness(VALUE self)
159
+ {
160
+ return INT2FIX(CVFONT(self)->thickness);
161
+ }
162
+
163
+ /*
164
+ * Returns line type
165
+ * @overload line_type
166
+ * @return [Integer] line_type
167
+ */
168
+ VALUE
169
+ rb_line_type(VALUE self)
170
+ {
171
+ return INT2FIX(CVFONT(self)->line_type);
172
+ }
173
+
174
+ /*
175
+ * Returns italic or not
176
+ * @overload italic
177
+ * @return [Boolean] self is italic or not
178
+ */
179
+ VALUE
180
+ rb_italic(VALUE self)
181
+ {
182
+ return ((CVFONT(self)->font_face & CV_FONT_ITALIC) > 0) ? Qtrue : Qfalse;
183
+ }
184
+
185
+ void
186
+ init_ruby_class()
187
+ {
188
+ #if 0
189
+ // For documentation using YARD
190
+ VALUE opencv = rb_define_module("OpenCV");
191
+ #endif
192
+
193
+ if (rb_klass)
194
+ return;
195
+
196
+ VALUE opencv = rb_module_opencv();
197
+ rb_klass = rb_define_class_under(opencv, "CvFont", rb_cObject);
198
+ rb_define_alloc_func(rb_klass, rb_allocate);
199
+ VALUE face = rb_hash_new();
200
+ rb_define_const(rb_klass, "FACE", face);
201
+ rb_hash_aset(face, ID2SYM(rb_intern("simplex")), INT2FIX(CV_FONT_HERSHEY_SIMPLEX));
202
+ rb_hash_aset(face, ID2SYM(rb_intern("plain")), INT2FIX(CV_FONT_HERSHEY_PLAIN));
203
+ rb_hash_aset(face, ID2SYM(rb_intern("duplex")), INT2FIX(CV_FONT_HERSHEY_DUPLEX));
204
+ rb_hash_aset(face, ID2SYM(rb_intern("triplex")), INT2FIX(CV_FONT_HERSHEY_TRIPLEX));
205
+ rb_hash_aset(face, ID2SYM(rb_intern("complex_small")), INT2FIX(CV_FONT_HERSHEY_COMPLEX_SMALL));
206
+ rb_hash_aset(face, ID2SYM(rb_intern("script_simplex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_SIMPLEX));
207
+ rb_hash_aset(face, ID2SYM(rb_intern("script_complex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_COMPLEX));
208
+
209
+ VALUE default_option = rb_hash_new();
210
+ rb_define_const(rb_klass, "FONT_OPTION", default_option);
211
+ rb_hash_aset(default_option, ID2SYM(rb_intern("hscale")), rb_float_new(1.0));
212
+ rb_hash_aset(default_option, ID2SYM(rb_intern("vscale")), rb_float_new(1.0));
213
+ rb_hash_aset(default_option, ID2SYM(rb_intern("shear")), INT2FIX(0));
214
+ rb_hash_aset(default_option, ID2SYM(rb_intern("thickness")), INT2FIX(1));
215
+ rb_hash_aset(default_option, ID2SYM(rb_intern("line_type")), INT2FIX(8));
216
+
217
+ rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
218
+ rb_define_method(rb_klass, "face", RUBY_METHOD_FUNC(rb_face), 0);
219
+ rb_define_method(rb_klass, "hscale", RUBY_METHOD_FUNC(rb_hscale), 0);
220
+ rb_define_method(rb_klass, "vscale", RUBY_METHOD_FUNC(rb_vscale), 0);
221
+ rb_define_method(rb_klass, "shear", RUBY_METHOD_FUNC(rb_shear), 0);
222
+ rb_define_method(rb_klass, "thickness", RUBY_METHOD_FUNC(rb_thickness), 0);
223
+ rb_define_method(rb_klass, "line_type", RUBY_METHOD_FUNC(rb_line_type), 0);
224
+ rb_define_method(rb_klass, "italic", RUBY_METHOD_FUNC(rb_italic), 0);
225
+ }
226
+
227
+ __NAMESPACE_END_CVFONT
228
+ __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 init_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