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,82 @@
1
+ /************************************************************
2
+
3
+ cvcapture.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVCAPTURE_H
11
+ #define RUBY_OPENCV_CVCAPTURE_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVCAPTURE namespace cCvCapture {
16
+ #define __NAMESPACE_END_CVCAPTURE }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+
20
+ typedef struct {
21
+ CvCapture* ptr;
22
+ bool opened;
23
+ } sCvCapture;
24
+
25
+ __NAMESPACE_BEGIN_CVCAPTURE
26
+
27
+
28
+ VALUE rb_class();
29
+
30
+ void init_ruby_class();
31
+
32
+ void cvcapture_free(void *ptr);
33
+ VALUE rb_open(int argc, VALUE *argv, VALUE klass);
34
+
35
+ VALUE rb_close(VALUE self);
36
+
37
+ VALUE rb_grab(VALUE self);
38
+ VALUE rb_retrieve(VALUE self);
39
+ VALUE rb_query(VALUE self);
40
+
41
+ VALUE rb_get_millisecond(VALUE self);
42
+ VALUE rb_set_millisecond(VALUE self, VALUE value);
43
+ VALUE rb_get_frames(VALUE self);
44
+ VALUE rb_set_frames(VALUE self, VALUE value);
45
+ VALUE rb_get_avi_ratio(VALUE self);
46
+ VALUE rb_set_avi_ratio(VALUE self, VALUE value);
47
+ VALUE rb_get_size(VALUE self);
48
+ VALUE rb_set_size(VALUE self, VALUE value);
49
+ VALUE rb_get_width(VALUE self);
50
+ VALUE rb_set_width(VALUE self, VALUE value);
51
+ VALUE rb_get_height(VALUE self);
52
+ VALUE rb_set_height(VALUE self, VALUE value);
53
+ VALUE rb_get_fps(VALUE self);
54
+ VALUE rb_set_fps(VALUE self, VALUE value);
55
+ VALUE rb_get_fourcc(VALUE self);
56
+ VALUE rb_get_frame_count(VALUE self);
57
+ VALUE rb_get_format(VALUE self);
58
+ VALUE rb_get_mode(VALUE self);
59
+ VALUE rb_get_brightness(VALUE self);
60
+ VALUE rb_get_contrast(VALUE self);
61
+ VALUE rb_get_saturation(VALUE self);
62
+ VALUE rb_get_hue(VALUE self);
63
+ VALUE rb_get_gain(VALUE self);
64
+ VALUE rb_get_exposure(VALUE self);
65
+ VALUE rb_get_convert_rgb(VALUE self);
66
+ VALUE rb_get_rectification(VALUE self);
67
+
68
+ __NAMESPACE_END_CVCAPTURE
69
+
70
+
71
+ inline CvCapture*
72
+ CVCAPTURE(VALUE object) {
73
+ sCvCapture *scap;
74
+ Data_Get_Struct(object, sCvCapture, scap);
75
+ if (!scap->opened)
76
+ rb_raise(rb_eIOError, "Resource is not available!");
77
+ return scap->ptr;
78
+ }
79
+
80
+ __NAMESPACE_END_OPENCV
81
+
82
+ #endif // RUBY_OPENCV_CVCAPTURE_H
@@ -0,0 +1,233 @@
1
+ /************************************************************
2
+
3
+ cvchain.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvchain.h"
11
+ /*
12
+ * Document-class: OpenCV::CvChain
13
+ *
14
+ * Freeman chain code
15
+ */
16
+ __NAMESPACE_BEGIN_OPENCV
17
+ __NAMESPACE_BEGIN_CVCHAIN
18
+
19
+ #define APPROX_CHAIN_OPTION(op) rb_get_option_table(rb_klass, "APPROX_CHAIN_OPTION", op)
20
+ #define APPROX_CHAIN_METHOD(op) CVMETHOD("APPROX_CHAIN_METHOD", LOOKUP_HASH(op, "method"), CV_CHAIN_APPROX_SIMPLE)
21
+ #define APPROX_CHAIN_PARAMETER(op) NUM2INT(LOOKUP_HASH(op, "parameter"))
22
+ #define APPROX_CHAIN_MINIMAL_PERIMETER(op) NUM2INT(LOOKUP_HASH(op, "minimal_perimeter"))
23
+ #define APPROX_CHAIN_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_HASH(op, "recursive"))
24
+
25
+ VALUE rb_klass;
26
+
27
+ VALUE
28
+ rb_class()
29
+ {
30
+ return rb_klass;
31
+ }
32
+
33
+ VALUE
34
+ rb_allocate(VALUE klass)
35
+ {
36
+ return Data_Wrap_Struct(klass, mark_root_object, unregister_object, NULL);
37
+ }
38
+
39
+ /*
40
+ * Create a new chain code
41
+ * @overload new(storage=nil)
42
+ * @param storage [CvMemStorage,nil] Sequence location (If storage is nil, allocates a new storage automatically)
43
+ * @return [CvChain] New CvChain instance
44
+ * @opencv_func cvCreateSeq (seq_flags=CV_SEQ_ELTYPE_CODE)
45
+ */
46
+ VALUE
47
+ rb_initialize(int argc, VALUE *argv, VALUE self)
48
+ {
49
+ CvMemStorage *storage;
50
+ VALUE storage_value;
51
+ if (rb_scan_args(argc, argv, "01", &storage_value) > 0) {
52
+ storage_value = CHECK_CVMEMSTORAGE(storage_value);
53
+ storage = CVMEMSTORAGE(storage_value);
54
+ }
55
+ else
56
+ storage = rb_cvCreateMemStorage(0);
57
+ try {
58
+ DATA_PTR(self) = (CvChain*)cvCreateSeq(CV_SEQ_ELTYPE_CODE, sizeof(CvChain),
59
+ sizeof(int), storage);
60
+ }
61
+ catch (cv::Exception& e) {
62
+ raise_cverror(e);
63
+ }
64
+ CvSeq* self_ptr = CVSEQ(self);
65
+ cCvSeq::register_elem_class(self_ptr, rb_cInteger);
66
+ register_root_object(self_ptr, storage_value);
67
+
68
+ return self;
69
+ }
70
+
71
+ /*
72
+ * Returns Freeman chain code origin
73
+ * @overload origin
74
+ * @return [CvPoint] Origin of the chain code
75
+ */
76
+ VALUE
77
+ rb_origin(VALUE self)
78
+ {
79
+ return cCvPoint::new_object(CVCHAIN(self)->origin);
80
+ }
81
+
82
+ /*
83
+ * Set Freeman chain code origin
84
+ * @overload origin=value
85
+ * @param value [CvPoint] Origin of the chain code
86
+ * @return [CvChain] self
87
+ */
88
+ VALUE
89
+ rb_set_origin(VALUE self, VALUE origin)
90
+ {
91
+ CVCHAIN(self)->origin = VALUE_TO_CVPOINT(origin);
92
+ return self;
93
+ }
94
+
95
+ /*
96
+ * Returns the chain codes
97
+ * @overload codes
98
+ * @return [Array<Integer>] Chain codes
99
+ * @opencv_func cvStartReadChainPoints
100
+ * @opencv_func CV_READ_SEQ_ELEM
101
+ */
102
+ VALUE
103
+ rb_codes(VALUE self)
104
+ {
105
+ CvChain *chain = CVCHAIN(self);
106
+ CvChainPtReader reader;
107
+ int total = chain->total;
108
+ VALUE ary = rb_ary_new2(total);
109
+ try {
110
+ cvStartReadChainPoints(chain, &reader);
111
+ for (int i = 0; i < total; ++i) {
112
+ CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
113
+ rb_ary_store(ary, i, INT2FIX(reader.code));
114
+ }
115
+ }
116
+ catch (cv::Exception& e) {
117
+ raise_cverror(e);
118
+ }
119
+ return ary;
120
+ }
121
+
122
+ /*
123
+ * Returns the points of the chain codes
124
+ * @overload points
125
+ * @return [Array<CvPoint>] Points of the chain codes
126
+ * @opencv_func cvStartReadChainPoints
127
+ * @opencv_func CV_READ_CHAIN_POINT
128
+ */
129
+ VALUE
130
+ rb_points(VALUE self)
131
+ {
132
+ CvChain *chain = CVCHAIN(self);
133
+ CvChainPtReader reader;
134
+ CvPoint p = chain->origin;
135
+ int total = chain->total;
136
+ VALUE ary = rb_ary_new2(total);
137
+ try {
138
+ cvStartReadChainPoints(chain, &reader);
139
+ for (int i = 0; i < total; ++i) {
140
+ CV_READ_CHAIN_POINT(p, reader);
141
+ rb_ary_store(ary, i, cCvPoint::new_object(p));
142
+ }
143
+ }
144
+ catch (cv::Exception& e) {
145
+ raise_cverror(e);
146
+ }
147
+ return ary;
148
+ }
149
+
150
+ /*
151
+ * Approximates Freeman chains with a polygonal curve
152
+ * @overload approx_chain(options)
153
+ * @param options [Hash] Parameters
154
+ * @option options [Symbol] :method Approximation method (see the description of CvMat#find_contours)
155
+ * @option options [Number] :minimal_perimeter Approximates only those contours whose perimeters
156
+ * are not less than minimal_perimeter. Other chains are removed from the resulting structure.
157
+ * @option options [Boolean] :recursive Recursion flag. If it is true, the function approximates
158
+ * all chains that can be obtained from chain by using the h_next or v_next links.
159
+ * Otherwise, the single input chain is approximated.
160
+ * @return [CvSeq<CvPoint>] Polygonal curve
161
+ * @opencv_func cvApproxChains
162
+ */
163
+ VALUE
164
+ rb_approx_chains(int argc, VALUE *argv, VALUE self)
165
+ {
166
+ VALUE approx_chain_option;
167
+ rb_scan_args(argc, argv, "01", &approx_chain_option);
168
+
169
+ approx_chain_option = APPROX_CHAIN_OPTION(approx_chain_option);
170
+ VALUE storage = cCvMemStorage::new_object();
171
+ CvSeq *seq = cvApproxChains(CVSEQ(self), CVMEMSTORAGE(storage),
172
+ APPROX_CHAIN_METHOD(approx_chain_option),
173
+ APPROX_CHAIN_PARAMETER(approx_chain_option),
174
+ APPROX_CHAIN_MINIMAL_PERIMETER(approx_chain_option),
175
+ APPROX_CHAIN_RECURSIVE(approx_chain_option));
176
+
177
+ if (seq && seq->total > 0) {
178
+ return cCvSeq::new_sequence(cCvChain::rb_class(), seq, cCvPoint::rb_class(), storage);
179
+ }
180
+ return Qnil;
181
+ }
182
+
183
+ VALUE
184
+ new_object()
185
+ {
186
+ VALUE storage = cCvMemStorage::new_object();
187
+ CvSeq *seq = NULL;
188
+ try {
189
+ seq = cvCreateSeq(CV_SEQ_CHAIN_CONTOUR, sizeof(CvChain), sizeof(int), CVMEMSTORAGE(storage));
190
+ }
191
+ catch (cv::Exception& e) {
192
+ raise_cverror(e);
193
+ }
194
+ return cCvSeq::new_sequence(cCvChain::rb_class(), seq, T_FIXNUM, storage);
195
+ }
196
+
197
+ void
198
+ init_ruby_class()
199
+ {
200
+ #if 0
201
+ // For documentation using YARD
202
+ VALUE opencv = rb_define_module("OpenCV");
203
+ VALUE cvseq = rb_define_class_under(opencv, "CvSeq");
204
+ VALUE curve = rb_define_module_under(opencv, "Curve");
205
+ #endif
206
+
207
+ if (rb_klass)
208
+ return;
209
+
210
+ VALUE opencv = rb_module_opencv();
211
+ VALUE cvseq = cCvSeq::rb_class();
212
+ VALUE curve = mCurve::rb_module();
213
+
214
+ rb_klass = rb_define_class_under(opencv, "CvChain", cvseq);
215
+ rb_include_module(rb_klass, curve);
216
+ VALUE approx_chain_option = rb_hash_new();
217
+ rb_define_const(rb_klass, "APPROX_CHAIN_OPTION", approx_chain_option);
218
+ rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("method")), ID2SYM(rb_intern("approx_simple")));
219
+ rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("parameter")), rb_float_new(0));
220
+ rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("minimal_perimeter")), INT2FIX(0));
221
+ rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("recursive")), Qfalse);
222
+
223
+ rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
224
+ rb_define_method(rb_klass, "origin", RUBY_METHOD_FUNC(rb_origin), 0);
225
+ rb_define_method(rb_klass, "origin=", RUBY_METHOD_FUNC(rb_set_origin), 1);
226
+ rb_define_method(rb_klass, "codes", RUBY_METHOD_FUNC(rb_codes), 0);
227
+ rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
228
+ rb_define_method(rb_klass, "approx_chains", RUBY_METHOD_FUNC(rb_approx_chains), -1);
229
+ rb_define_alias(rb_klass, "approx", "approx_chains");
230
+ }
231
+
232
+ __NAMESPACE_END_CVCHAIN
233
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,46 @@
1
+ /************************************************************
2
+
3
+ cvchain.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVCHAIN_H
11
+ #define RUBY_OPENCV_CVCHAIN_H
12
+ #include "opencv.h"
13
+
14
+ #define __NAMESPACE_BEGIN_CVCHAIN namespace cCvChain {
15
+ #define __NAMESPACE_END_CVCHAIN }
16
+
17
+ __NAMESPACE_BEGIN_OPENCV
18
+ __NAMESPACE_BEGIN_CVCHAIN
19
+
20
+ VALUE rb_class();
21
+
22
+ void init_ruby_class();
23
+
24
+ VALUE rb_allocate(VALUE klass);
25
+
26
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
27
+ VALUE rb_origin(VALUE self);
28
+ VALUE rb_set_origin(VALUE self, VALUE origin);
29
+ VALUE rb_codes(VALUE self);
30
+ VALUE rb_points(VALUE self);
31
+ VALUE rb_approx_chains(int argc, VALUE *argv, VALUE self);
32
+
33
+ VALUE new_object();
34
+
35
+ __NAMESPACE_END_CVCHAIN
36
+
37
+ inline CvChain*
38
+ CVCHAIN(VALUE object){
39
+ CvChain *ptr;
40
+ Data_Get_Struct(object, CvChain, ptr);
41
+ return ptr;
42
+ }
43
+
44
+ __NAMESPACE_END_OPENCV
45
+
46
+ #endif // RUBY_OPENCV_CVCHAIN_H
@@ -0,0 +1,126 @@
1
+ /************************************************************
2
+
3
+ cvcircle32f.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvcircle32f.h"
11
+ /*
12
+ * Document-class: OpenCV::CvCircle32f
13
+ *
14
+ * Combination of center and radius.
15
+ *
16
+ * see CvMat#hough_circles
17
+ */
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVCIRCLE32F
20
+
21
+ VALUE rb_klass;
22
+
23
+ VALUE
24
+ rb_class()
25
+ {
26
+ return rb_klass;
27
+ }
28
+
29
+ VALUE
30
+ rb_allocate(VALUE klass)
31
+ {
32
+ CvCircle32f *ptr;
33
+ return Data_Make_Struct(klass, CvCircle32f, 0, -1, ptr);
34
+ }
35
+
36
+ /*
37
+ * Returns center point of the circle
38
+ * @overload center
39
+ * @return [CvPoint2D32f] Center point of the circle
40
+ */
41
+ VALUE
42
+ rb_center(VALUE self)
43
+ {
44
+ return cCvPoint2D32f::new_object(CVCIRCLE32F(self)->center);
45
+ }
46
+
47
+ /*
48
+ * Returns radius of the circle
49
+ * @overload radius
50
+ * @return [Number] Radius of the circle
51
+ */
52
+ VALUE
53
+ rb_radius(VALUE self)
54
+ {
55
+ return rb_float_new(CVCIRCLE32F(self)->radius);
56
+ }
57
+
58
+ /*
59
+ * Accesses to parameters of the circle by array-like interface ([X-coordinate, Y-coordinate, radius])
60
+ * @overload []
61
+ * @param index [Integer] Index
62
+ * @return [Number] X-coordinate, Y-coordinate or radius of the circle
63
+ */
64
+ VALUE
65
+ rb_aref(VALUE self, VALUE index)
66
+ {
67
+ switch (NUM2INT(index)) {
68
+ case 0:
69
+ return DBL2NUM(CVCIRCLE32F(self)->center.x);
70
+ break;
71
+ case 1:
72
+ return DBL2NUM(CVCIRCLE32F(self)->center.y);
73
+ break;
74
+ case 2:
75
+ return DBL2NUM(CVCIRCLE32F(self)->radius);
76
+ break;
77
+ default:
78
+ rb_raise(rb_eIndexError, "index should be 0...3");
79
+ break;
80
+ }
81
+ return Qnil;
82
+ }
83
+
84
+ /*
85
+ * Returns parameters of the circle as an array which contains [center<CvPoint2D32f>, radius<Number>]
86
+ * @overload to_ary
87
+ * @return [Array<CvPoint2D32f,Number>] An array which contains [center, radius]
88
+ */
89
+ VALUE
90
+ rb_to_ary(VALUE self)
91
+ {
92
+ return rb_ary_new3(2, rb_center(self), rb_radius(self));
93
+ }
94
+
95
+ VALUE
96
+ new_object(CvCircle32f circle32f)
97
+ {
98
+ VALUE object = rb_allocate(rb_klass);
99
+ *CVCIRCLE32F(object) = circle32f;
100
+ return object;
101
+ }
102
+
103
+ void
104
+ init_ruby_class()
105
+ {
106
+ #if 0
107
+ // For documentation using YARD
108
+ VALUE opencv = rb_define_module("OpenCV");
109
+ #endif
110
+
111
+ if (rb_klass)
112
+ return;
113
+
114
+ VALUE opencv = rb_module_opencv();
115
+
116
+ rb_klass = rb_define_class_under(opencv, "CvCircle32f", rb_cObject);
117
+ rb_define_alloc_func(rb_klass, rb_allocate);
118
+ rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
119
+ rb_define_method(rb_klass, "radius", RUBY_METHOD_FUNC(rb_radius), 0);
120
+ rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
121
+ rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
122
+ rb_define_alias(rb_klass, "to_a", "to_ary");
123
+ }
124
+
125
+ __NAMESPACE_END_CVCIRCLE32F
126
+ __NAMESPACE_END_OPENCV