afeld-opencv 0.0.8

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 (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,137 @@
1
+ /************************************************************
2
+
3
+ cvvideowriter.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvvideowriter.h"
11
+ /*
12
+ * Document-class: OpenCV::CvVideoWriter
13
+ *
14
+ * Create video stream from images.
15
+ *
16
+ * C structure is "black box".
17
+ */
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVVIDEOWRITER
20
+
21
+ VALUE rb_klass;
22
+
23
+ VALUE
24
+ rb_class()
25
+ {
26
+ return rb_klass;
27
+ }
28
+
29
+ void
30
+ define_ruby_class()
31
+ {
32
+ if (rb_klass)
33
+ return;
34
+ /*
35
+ * opencv = rb_define_module("OpenCV");
36
+ *
37
+ * note: this comment is used by rdoc.
38
+ */
39
+ VALUE opencv = rb_module_opencv();
40
+ rb_klass = rb_define_class_under(opencv, "CvVideoWriter", rb_cObject);
41
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
42
+ rb_define_method(rb_klass, "write", RUBY_METHOD_FUNC(rb_write), 1);
43
+ rb_define_method(rb_klass, "close", RUBY_METHOD_FUNC(rb_close), 0);
44
+ }
45
+
46
+ /*
47
+ * call-seq:
48
+ * CvVideoWriter.new(<i>filname, fourcc, fps, size[, is_color]</i>) -> cvvideowriter
49
+ * CvVideoWriter.new(<i>filname, fourcc, fps, size[, is_color]</i>){|vw| ... } -> nil
50
+ *
51
+ * Open new video writer. If block given, writer is closed automatically when end of block.
52
+ *
53
+ * note: if <i>fourcc</i> is nil, popup codec select dialog (Windows only).
54
+ */
55
+ VALUE
56
+ rb_initialize(int argc, VALUE *argv, VALUE self)
57
+ {
58
+ VALUE filename, fourcc, fps, size, is_color_val;
59
+ rb_scan_args(argc, argv, "41", &filename, &fourcc, &fps, &size, &is_color_val);
60
+ char codec[4] = {' ', ' ', ' ', ' '};
61
+ int codec_number;
62
+ Check_Type(filename, T_STRING);
63
+ if (RSTRING_LEN(filename) == 0)
64
+ rb_raise(rb_eArgError, "argument 1 (file name) dose not given");
65
+ if (NIL_P(fourcc))
66
+ codec_number = -1;
67
+ else {
68
+ Check_Type(fourcc, T_STRING);
69
+ if (RSTRING_LEN(fourcc) > 4)
70
+ rb_raise(rb_eStandardError, "argument 2 (fourcc) should be specific 4-character. (i.e \"PIM1\",\"MJPG\")");
71
+ else {
72
+ int len = RSTRING_LEN(fourcc);
73
+ for (int i = 0; i < len; ++i)
74
+ codec[i] = RSTRING_PTR(fourcc)[i];
75
+ codec_number = CV_FOURCC(codec[0], codec[1], codec[2], codec[3]);
76
+ }
77
+ }
78
+ int is_color;
79
+ if (NIL_P(is_color_val))
80
+ is_color = 1;
81
+ else
82
+ is_color = (is_color_val == Qtrue) ? 1 : 0;
83
+ try {
84
+ DATA_PTR(self) = cvCreateVideoWriter(StringValueCStr(filename), codec_number,
85
+ NUM2DBL(fps), VALUE_TO_CVSIZE(size), is_color);
86
+ }
87
+ catch (cv::Exception& e) {
88
+ raise_cverror(e);
89
+ }
90
+ if (rb_block_given_p()) {
91
+ rb_yield(self);
92
+ rb_close(self);
93
+ return Qnil;
94
+ }
95
+ else
96
+ return self;
97
+ }
98
+
99
+ /*
100
+ * call-seq:
101
+ * write(<i>frame</i>)
102
+ *
103
+ * Write image as frame of video stream.
104
+ * <i>frame</i> should be IplImage
105
+ */
106
+ VALUE
107
+ rb_write(VALUE self, VALUE frame)
108
+ {
109
+ try {
110
+ cvWriteFrame(CVVIDEOWRITER(self), IPLIMAGE_WITH_CHECK(frame));
111
+ }
112
+ catch (cv::Exception& e) {
113
+ raise_cverror(e);
114
+ }
115
+ return self;
116
+ }
117
+
118
+ /*
119
+ * Close vidoe writer.
120
+ */
121
+ VALUE
122
+ rb_close(VALUE self)
123
+ {
124
+ CvVideoWriter *writer = CVVIDEOWRITER(self);
125
+ try {
126
+ if (writer)
127
+ cvReleaseVideoWriter(&writer);
128
+ }
129
+ catch (cv::Exception& e) {
130
+ raise_cverror(e);
131
+ }
132
+ return Qnil;
133
+ }
134
+
135
+
136
+ __NAMESPACE_END_CVVIDEOWRITER
137
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,43 @@
1
+ /************************************************************
2
+
3
+ cvvideowriter.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVVIDEOWRITER_H
11
+ #define RUBY_OPENCV_CVVIDEOWRITER_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVVIDEOWRITER namespace cCvVideoWriter {
16
+ #define __NAMESPACE_END_CVVIDEOWRITER }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVVIDEOWRITER
20
+
21
+ VALUE rb_class();
22
+
23
+ void define_ruby_class();
24
+
25
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
26
+ VALUE rb_write(VALUE self, VALUE frame);
27
+ VALUE rb_close(VALUE self);
28
+
29
+ __NAMESPACE_END_CVVIDEOWRITER
30
+
31
+ inline CvVideoWriter*
32
+ CVVIDEOWRITER(VALUE object)
33
+ {
34
+ // CvVideoWriter is
35
+ // CvVideoWriter *ptr;
36
+ // Data_Get_Struct(object, CvVideoWriter, ptr);
37
+ // return ptr;
38
+ return (CvVideoWriter*)DATA_PTR(object);
39
+ }
40
+
41
+ __NAMESPACE_END_OPENCV
42
+
43
+ #endif // RUBY_OPENCV_CVVIDEOWRITER_H
@@ -0,0 +1,68 @@
1
+ /************************************************************
2
+
3
+ gui.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "gui.h"
11
+ /*
12
+ * Document-module: OpenCV::GUI
13
+ *
14
+ * OpenCV simple GUI interface. Provides Window, Trackbar.
15
+ * This GUI work on GTK or Microsoft Windows native GUI.
16
+ */
17
+ __NAMESPACE_BEGIN_OPENCV
18
+ __NAMESPACE_BEGIN_GUI
19
+
20
+ VALUE rb_module;
21
+
22
+ VALUE
23
+ rb_module_GUI()
24
+ {
25
+ return rb_module;
26
+ }
27
+
28
+ void
29
+ define_ruby_module()
30
+ {
31
+ if (rb_module)
32
+ return;
33
+ /*
34
+ * opencv = rb_define_module("OpenCV");
35
+ *
36
+ * note: this comment is used by rdoc.
37
+ */
38
+ VALUE opencv = rb_module_opencv();
39
+ rb_module = rb_define_module_under(opencv, "GUI");
40
+ rb_define_singleton_method(rb_module, "wait_key", RUBY_METHOD_FUNC(rb_wait_key), -1);
41
+ }
42
+
43
+ /*
44
+ * call-seq:
45
+ * wait_key(<i>[delay]</i>) -> int or nil
46
+ *
47
+ * Waits for a pressed key each GUI wedget.
48
+ * Return the code of the pressed key or nil if no key were pressed until the specified timeout has elapsed.
49
+ * <i>delay</i> should be Fixnum. Wait <i>delay</i> millisecond.
50
+ */
51
+ VALUE
52
+ rb_wait_key(int argc, VALUE *argv, VALUE self)
53
+ {
54
+ VALUE delay;
55
+ rb_scan_args(argc, argv, "01", &delay);
56
+ int keycode = 0;
57
+ try {
58
+ keycode = cvWaitKey(IF_INT(delay, 0));
59
+ }
60
+ catch (cv::Exception& e) {
61
+ raise_cverror(e);
62
+ }
63
+ return (keycode < 0) ? Qnil : INT2NUM(keycode);
64
+ }
65
+
66
+ __NAMESPACE_END_GUI
67
+ __NAMESPACE_END_OPENCV
68
+
@@ -0,0 +1,30 @@
1
+ /************************************************************
2
+
3
+ gui.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_GUI_H
11
+ #define RUBY_OPENCV_GUI_H
12
+
13
+ #define __NAMESPACE_BEGIN_GUI namespace mGUI {
14
+ #define __NAMESPACE_END_GUI }
15
+
16
+ #include "opencv.h"
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_GUI
20
+
21
+ VALUE rb_module_GUI();
22
+ void define_ruby_module();
23
+
24
+ VALUE rb_wait_key(int argc, VALUE *argv, VALUE self);
25
+
26
+ __NAMESPACE_END_GUI
27
+ __NAMESPACE_END_OPENCV
28
+
29
+ #endif // RUBY_OPENCV_GUI_H
30
+
@@ -0,0 +1,192 @@
1
+ /************************************************************
2
+
3
+ iplconvkernel.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "iplconvkernel.h"
11
+ /*
12
+ * Document-class: OpenCV::IplConvKernel
13
+ *
14
+ * Structuring element can be used in the morphological operations.
15
+ *
16
+ * CvMat#erode, CvMat#dilate, CvMat#morphology_open, CvMat#morphology_close,
17
+ * CvMat#morphology_gradient, CvMat#morphology_tophat, CvMat#morphology_blackhat
18
+ *
19
+ * Create by IplConvKernel.new or CvMat#to_IplConvKernel
20
+ */
21
+ __NAMESPACE_BEGIN_OPENCV
22
+ __NAMESPACE_BEGIN_IPLCONVKERNEL
23
+
24
+ VALUE rb_klass;
25
+
26
+ VALUE
27
+ rb_class()
28
+ {
29
+ return rb_klass;
30
+ }
31
+
32
+ void
33
+ define_ruby_class()
34
+ {
35
+ if (rb_klass)
36
+ return;
37
+ /*
38
+ * opencv = rb_define_module("OpenCV");
39
+ *
40
+ * note: this comment is used by rdoc.
41
+ */
42
+ VALUE opencv = rb_module_opencv();
43
+ rb_klass = rb_define_class_under(opencv, "IplConvKernel", rb_cObject);
44
+ rb_define_alloc_func(rb_klass, rb_allocate);
45
+
46
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
47
+ rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
48
+ rb_define_method(rb_klass, "cols", RUBY_METHOD_FUNC(rb_cols), 0);
49
+ rb_define_alias(rb_klass, "columns", "cols");
50
+ rb_define_method(rb_klass, "rows", RUBY_METHOD_FUNC(rb_rows), 0);
51
+ rb_define_method(rb_klass, "anchor", RUBY_METHOD_FUNC(rb_anchor), 0);
52
+ rb_define_method(rb_klass, "anchor_x", RUBY_METHOD_FUNC(rb_anchor_x), 0);
53
+ rb_define_method(rb_klass, "anchor_y", RUBY_METHOD_FUNC(rb_anchor_y), 0);
54
+ }
55
+
56
+ VALUE
57
+ rb_allocate(VALUE klass)
58
+ {
59
+ return IPLCONVKERNEL_OBJECT(klass, 0);
60
+ }
61
+
62
+ /*
63
+ * call-seq:
64
+ * IplConvKernel.new(cols, rows, anchor_x, anchor_y, shape [,values = nil])
65
+ *
66
+ * Creates structuring element.
67
+ * cols
68
+ * Number of columns in the structuring element.
69
+ * rows
70
+ * Number of rows in the structuring element.
71
+ * anchor_x
72
+ * Relative horizontal offset of the anchor point.
73
+ * anchor_y
74
+ * Relative vertical offset of the anchor point.
75
+ * shape
76
+ * Shape of the structuring element; may have the following values:
77
+ * :rect
78
+ * :cross
79
+ * :ellipse
80
+ * :custom
81
+ *
82
+ */
83
+ VALUE
84
+ rb_initialize(int argc, VALUE *argv, VALUE self)
85
+ {
86
+ VALUE shape, rows, cols, anchor_x, anchor_y, values;
87
+ rb_scan_args(argc, argv, "51", &cols, &rows, &anchor_x, &anchor_y, &shape, &values);
88
+ int shape_type;
89
+ int _cols = NUM2INT(cols);
90
+ int _rows = NUM2INT(rows);
91
+ int num_values;
92
+ int *_values = NULL;
93
+ const int INVALID_SHAPE = -1;
94
+
95
+ shape_type = CVMETHOD("STRUCTURING_ELEMENT_SHAPE", shape, INVALID_SHAPE);
96
+ if (shape_type == INVALID_SHAPE)
97
+ rb_raise(rb_eTypeError, "argument 1 (shape) should be :rect or :cross or :ellipse or :custom.");
98
+ if (shape_type == CV_SHAPE_CUSTOM) {
99
+ if (NIL_P(values))
100
+ rb_raise(rb_eArgError, "argument 6 (values) should not be nil when the shape is :custom.");
101
+ num_values = RARRAY_LEN(values);
102
+ _values = ALLOCA_N(int, num_values);
103
+ VALUE *values_ptr = RARRAY_PTR(values);
104
+ for (int i = 0; i < num_values; ++i)
105
+ _values[i] = NUM2INT(values_ptr[i]);
106
+ }
107
+ try {
108
+ DATA_PTR(self) = rb_cvCreateStructuringElementEx(_cols, _rows, NUM2INT(anchor_x), NUM2INT(anchor_y),
109
+ shape_type, _values);
110
+ }
111
+ catch (cv::Exception& e) {
112
+ raise_cverror(e);
113
+ }
114
+ return self;
115
+ }
116
+
117
+ /*
118
+ * call-seq:
119
+ * size -> cvsize
120
+ *
121
+ * Return the structuring element's size.
122
+ */
123
+ VALUE
124
+ rb_size(VALUE self)
125
+ {
126
+ IplConvKernel *kernel = IPLCONVKERNEL(self);
127
+ return cCvSize::new_object(cvSize(kernel->nCols, kernel->nRows));
128
+ }
129
+
130
+ /*
131
+ * call-seq:
132
+ * cols -> int
133
+ *
134
+ * Return number of columns in the structuring element.
135
+ */
136
+ VALUE
137
+ rb_cols(VALUE self)
138
+ {
139
+ return INT2NUM(IPLCONVKERNEL(self)->nCols);
140
+ }
141
+
142
+ /*
143
+ * call-seq:
144
+ * rows -> int
145
+ *
146
+ * Return number of rows in the structuring element.
147
+ */
148
+ VALUE
149
+ rb_rows(VALUE self)
150
+ {
151
+ return INT2NUM(IPLCONVKERNEL(self)->nRows);
152
+ }
153
+
154
+ /*
155
+ * call-seq:
156
+ * anchor -> cvpoint
157
+ *
158
+ * Return anchor of the structuring element.
159
+ */
160
+ VALUE
161
+ rb_anchor(VALUE self)
162
+ {
163
+ IplConvKernel *kernel = IPLCONVKERNEL(self);
164
+ return cCvPoint::new_object(cvPoint(kernel->anchorX, kernel->anchorY));
165
+ }
166
+
167
+ /*
168
+ * call-seq:
169
+ * anchor_x -> int
170
+ *
171
+ * Return relative horizontal offset of the anchor point.
172
+ */
173
+ VALUE
174
+ rb_anchor_x(VALUE self)
175
+ {
176
+ return INT2NUM(IPLCONVKERNEL(self)->anchorX);
177
+ }
178
+
179
+ /*
180
+ * call-seq:
181
+ * anchor_y -> int
182
+ *
183
+ * Return relative vertical offset of the anchor point.
184
+ */
185
+ VALUE
186
+ rb_anchor_y(VALUE self)
187
+ {
188
+ return INT2NUM(IPLCONVKERNEL(self)->anchorY);
189
+ }
190
+
191
+ __NAMESPACE_END_IPLCONVKERNEL
192
+ __NAMESPACE_END_OPENCV