bonanza-ruby-opencv 0.0.13.20140330211753

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) 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 +98 -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 +607 -0
  50. data/ext/opencv/cvcapture.h +72 -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 +332 -0
  58. data/ext/opencv/cvcontour.h +48 -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 +715 -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 +6829 -0
  78. data/ext/opencv/cvmat.h +323 -0
  79. data/ext/opencv/cvmemstorage.cpp +73 -0
  80. data/ext/opencv/cvmemstorage.h +53 -0
  81. data/ext/opencv/cvmoments.cpp +293 -0
  82. data/ext/opencv/cvmoments.h +75 -0
  83. data/ext/opencv/cvpoint.cpp +265 -0
  84. data/ext/opencv/cvpoint.h +67 -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 +441 -0
  90. data/ext/opencv/cvrect.h +88 -0
  91. data/ext/opencv/cvscalar.cpp +301 -0
  92. data/ext/opencv/cvscalar.h +76 -0
  93. data/ext/opencv/cvseq.cpp +605 -0
  94. data/ext/opencv/cvseq.h +74 -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 +279 -0
  104. data/ext/opencv/cvsurfpoint.h +54 -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 +221 -0
  110. data/ext/opencv/cvutils.h +31 -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 +82 -0
  116. data/ext/opencv/facerecognizer.cpp +181 -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 +666 -0
  125. data/ext/opencv/iplimage.h +75 -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 +833 -0
  131. data/ext/opencv/opencv.h +405 -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 +4 -0
  144. data/test/eigenfaces_save.xml +7524 -0
  145. data/test/fisherfaces_save.xml +7530 -0
  146. data/test/helper.rb +166 -0
  147. data/test/lbph_save.xml +4304 -0
  148. data/test/runner.rb +30 -0
  149. data/test/samples/airplane.jpg +0 -0
  150. data/test/samples/baboon.jpg +0 -0
  151. data/test/samples/baboon200.jpg +0 -0
  152. data/test/samples/baboon200_rotated.jpg +0 -0
  153. data/test/samples/blank0.jpg +0 -0
  154. data/test/samples/blank1.jpg +0 -0
  155. data/test/samples/blank2.jpg +0 -0
  156. data/test/samples/blank3.jpg +0 -0
  157. data/test/samples/blank4.jpg +0 -0
  158. data/test/samples/blank5.jpg +0 -0
  159. data/test/samples/blank6.jpg +0 -0
  160. data/test/samples/blank7.jpg +0 -0
  161. data/test/samples/blank8.jpg +0 -0
  162. data/test/samples/blank9.jpg +0 -0
  163. data/test/samples/cat.jpg +0 -0
  164. data/test/samples/chessboard.jpg +0 -0
  165. data/test/samples/contours.jpg +0 -0
  166. data/test/samples/fruits.jpg +0 -0
  167. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  168. data/test/samples/inpaint-mask.bmp +0 -0
  169. data/test/samples/lena-256x256.jpg +0 -0
  170. data/test/samples/lena-32x32.jpg +0 -0
  171. data/test/samples/lena-eyes.jpg +0 -0
  172. data/test/samples/lena-inpaint.jpg +0 -0
  173. data/test/samples/lena.jpg +0 -0
  174. data/test/samples/lines.jpg +0 -0
  175. data/test/samples/messy0.jpg +0 -0
  176. data/test/samples/messy1.jpg +0 -0
  177. data/test/samples/movie_sample.avi +0 -0
  178. data/test/samples/one_way_train_0000.jpg +0 -0
  179. data/test/samples/one_way_train_0001.jpg +0 -0
  180. data/test/samples/partially_blank0.jpg +0 -0
  181. data/test/samples/partially_blank1.jpg +0 -0
  182. data/test/samples/smooth0.jpg +0 -0
  183. data/test/samples/smooth1.jpg +0 -0
  184. data/test/samples/smooth2.jpg +0 -0
  185. data/test/samples/smooth3.jpg +0 -0
  186. data/test/samples/smooth4.jpg +0 -0
  187. data/test/samples/smooth5.jpg +0 -0
  188. data/test/samples/smooth6.jpg +0 -0
  189. data/test/samples/str-cv-rotated.jpg +0 -0
  190. data/test/samples/str-cv.jpg +0 -0
  191. data/test/samples/str-ov.jpg +0 -0
  192. data/test/samples/stuff.jpg +0 -0
  193. data/test/test_curve.rb +43 -0
  194. data/test/test_cvavgcomp.rb +24 -0
  195. data/test/test_cvbox2d.rb +76 -0
  196. data/test/test_cvcapture.rb +183 -0
  197. data/test/test_cvchain.rb +108 -0
  198. data/test/test_cvcircle32f.rb +41 -0
  199. data/test/test_cvconnectedcomp.rb +61 -0
  200. data/test/test_cvcontour.rb +150 -0
  201. data/test/test_cvcontourtree.rb +43 -0
  202. data/test/test_cverror.rb +50 -0
  203. data/test/test_cvfeaturetree.rb +65 -0
  204. data/test/test_cvfont.rb +58 -0
  205. data/test/test_cvhaarclassifiercascade.rb +63 -0
  206. data/test/test_cvhistogram.rb +271 -0
  207. data/test/test_cvhumoments.rb +83 -0
  208. data/test/test_cvline.rb +50 -0
  209. data/test/test_cvmat.rb +3003 -0
  210. data/test/test_cvmat_drawing.rb +349 -0
  211. data/test/test_cvmat_dxt.rb +150 -0
  212. data/test/test_cvmat_imageprocessing.rb +2085 -0
  213. data/test/test_cvmoments.rb +180 -0
  214. data/test/test_cvpoint.rb +75 -0
  215. data/test/test_cvpoint2d32f.rb +75 -0
  216. data/test/test_cvpoint3d32f.rb +93 -0
  217. data/test/test_cvrect.rb +144 -0
  218. data/test/test_cvscalar.rb +113 -0
  219. data/test/test_cvseq.rb +295 -0
  220. data/test/test_cvsize.rb +75 -0
  221. data/test/test_cvsize2d32f.rb +75 -0
  222. data/test/test_cvslice.rb +31 -0
  223. data/test/test_cvsurfparams.rb +57 -0
  224. data/test/test_cvsurfpoint.rb +66 -0
  225. data/test/test_cvtermcriteria.rb +56 -0
  226. data/test/test_cvtwopoints.rb +40 -0
  227. data/test/test_cvvideowriter.rb +58 -0
  228. data/test/test_eigenfaces.rb +93 -0
  229. data/test/test_fisherfaces.rb +93 -0
  230. data/test/test_iplconvkernel.rb +54 -0
  231. data/test/test_iplimage.rb +232 -0
  232. data/test/test_lbph.rb +152 -0
  233. data/test/test_mouseevent.rb +17 -0
  234. data/test/test_opencv.rb +360 -0
  235. data/test/test_pointset.rb +128 -0
  236. data/test/test_preliminary.rb +130 -0
  237. data/test/test_trackbar.rb +47 -0
  238. data/test/test_window.rb +115 -0
  239. data/yard_extension.rb +5 -0
  240. metadata +399 -0
@@ -0,0 +1,405 @@
1
+ /************************************************************
2
+
3
+ opencv.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_H
11
+ #define RUBY_OPENCV_H
12
+
13
+ #define __NAMESPACE_BEGIN_OPENCV namespace mOpenCV {
14
+ #define __NAMESPACE_END_OPENCV }
15
+
16
+ /* include headers */
17
+ #include <ruby.h>
18
+ #ifdef HAVE_RUBY_VERSION_H
19
+ #include <ruby/version.h>
20
+ #else
21
+ #include <version.h>
22
+ #endif
23
+
24
+ #ifdef RUBY_WIN32_H
25
+ #ifdef write
26
+ #undef write
27
+ #endif // write
28
+ #endif // RUBY_WIN32_H
29
+
30
+ #ifndef ANYARGS
31
+ #define ANYARGS ()
32
+ #endif
33
+
34
+ extern "C" {
35
+ #ifdef HAVE_RUBY_ST_H
36
+ #include <ruby/st.h>
37
+ #else
38
+ #include <st.h>
39
+ #endif
40
+
41
+ #ifdef HAVE_STDARG_H
42
+ #include <stdarg.h>
43
+ #define va_init_list(a,b) va_start(a,b)
44
+ #else
45
+ #include <varargs.h>
46
+ #define va_init_list(a,b) va_start(a)
47
+ #endif
48
+ }
49
+
50
+ // standard c headers
51
+ #define _USE_MATH_DEFINES // for VC++
52
+ #include <math.h>
53
+ #include <limits.h>
54
+ #include <float.h>
55
+ #include <assert.h>
56
+
57
+ // OpenCV headers
58
+ #include "opencv2/core/core_c.h"
59
+ #include "opencv2/core/core.hpp"
60
+ #include "opencv2/imgproc/imgproc_c.h"
61
+ #include "opencv2/imgproc/imgproc.hpp"
62
+ #include "opencv2/video/tracking.hpp"
63
+ #include "opencv2/video/background_segm.hpp"
64
+ #include "opencv2/features2d/features2d.hpp"
65
+ #include "opencv2/flann/flann.hpp"
66
+ #include "opencv2/calib3d/calib3d.hpp"
67
+ #include "opencv2/objdetect/objdetect.hpp"
68
+ #include "opencv2/legacy/compat.hpp"
69
+ #include "opencv2/legacy/legacy.hpp"
70
+ #include "opencv2/legacy/blobtrack.hpp"
71
+ #include "opencv2/contrib/contrib.hpp"
72
+ #include "opencv2/highgui/highgui_c.h"
73
+ #include "opencv2/highgui/highgui.hpp"
74
+ #include "opencv2/core/internal.hpp"
75
+ #include "opencv2/photo/photo.hpp"
76
+
77
+ #ifdef HAVE_ML_H
78
+ #include "opencv2/ml/ml.hpp"
79
+ #endif
80
+
81
+ #ifdef HAVE_OPENCV2_NONFREE_NONFREE_HPP
82
+ #include "opencv2/nonfree/nonfree.hpp"
83
+ #endif
84
+
85
+ // Ruby/OpenCV headers
86
+ #include "cvutils.h"
87
+ #include "cverror.h"
88
+ #include "cvpoint.h"
89
+ #include "cvpoint2d32f.h"
90
+ #include "cvsize.h"
91
+ #include "cvsize2d32f.h"
92
+ #include "cvrect.h"
93
+ #include "cvscalar.h"
94
+ #include "cvslice.h"
95
+ #include "cvtermcriteria.h"
96
+ #include "cvbox2d.h"
97
+ #include "cvfont.h"
98
+ #include "iplconvkernel.h"
99
+ #include "cvmoments.h"
100
+ #include "cvhumoments.h"
101
+ #include "cvconvexitydefect.h"
102
+ #include "cvpoint3d32f.h"
103
+
104
+ #include "cvmemstorage.h"
105
+
106
+ #include "cvseq.h"
107
+ #include "curve.h"
108
+ #include "pointset.h"
109
+ #include "cvchain.h"
110
+ #include "cvcontour.h"
111
+ #include "cvcontourtree.h"
112
+
113
+ #include "cvmat.h"
114
+ #include "iplimage.h"
115
+ #include "cvhistogram.h"
116
+ #include "cvcapture.h"
117
+ #include "cvvideowriter.h"
118
+
119
+ #include "cvline.h"
120
+ #include "cvtwopoints.h"
121
+ #include "cvcircle32f.h"
122
+
123
+ #include "cvconnectedcomp.h"
124
+ #include "cvavgcomp.h"
125
+ #include "cvhaarclassifiercascade.h"
126
+
127
+ #include "cvsurfpoint.h"
128
+ #include "cvsurfparams.h"
129
+
130
+ #include "cvfeaturetree.h"
131
+
132
+ #include "algorithm.h"
133
+ #include "facerecognizer.h"
134
+ #include "eigenfaces.h"
135
+ #include "fisherfaces.h"
136
+ #include "lbph.h"
137
+
138
+ // GUI
139
+ #include "gui.h"
140
+ #include "window.h"
141
+ #include "trackbar.h"
142
+ #include "mouseevent.h"
143
+
144
+ // memory management wrapper
145
+ #define RB_CVALLOC(type) (type*)rb_cvAlloc(sizeof(type))
146
+
147
+ // useful macros
148
+ #define IF_INT(val, ifnone) NIL_P(val) ? ifnone : NUM2INT(val)
149
+ #define IF_DBL(val, ifnone) NIL_P(val) ? ifnone : NUM2DBL(val)
150
+ #define IF_STRING(str) NIL_P(str) ? NULL : TYPE(str) == T_STRING ? rb
151
+ #define IF_BOOL(val, t, f, ifnone) val == Qtrue ? t : val == Qfalse ? f : ifnone
152
+
153
+ #define IF_DEPTH(val, ifnone) NIL_P(val) ? ifnone : NUM2INT(val)
154
+
155
+ #define REGISTER_HASH(hash, str, value) rb_hash_aset(hash, ID2SYM(rb_intern(str)), INT2FIX(value))
156
+ #define LOOKUP_HASH(hash, key_as_cstr) (rb_hash_lookup(hash, ID2SYM(rb_intern(key_as_cstr))))
157
+
158
+ #define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
159
+
160
+ #ifndef BOOL2INT
161
+ #define BOOL2INT(x) ((x == Qtrue) ? 1 : 0)
162
+ #endif
163
+
164
+ #ifndef INT2BOOL
165
+ #define INT2BOOL(x) (x ? Qtrue : Qfalse)
166
+ #endif
167
+
168
+ // wrapper for <= 1.8
169
+ #ifndef RARRAY_LEN
170
+ #define RARRAY_LEN(arg) (RARRAY(arg)->len)
171
+ #endif
172
+
173
+ #ifndef RARRAY_PTR
174
+ #define RARRAY_PTR(arg) (RARRAY(arg)->ptr)
175
+ #endif
176
+
177
+ #ifndef RSTRING_LEN
178
+ #define RSTRING_LEN(arg) (RSTRING(arg)->len)
179
+ #endif
180
+
181
+ #ifndef RSTRING_PTR
182
+ #define RSTRING_PTR(arg) (RSTRING(arg)->ptr)
183
+ #endif
184
+
185
+ #ifndef DBL2NUM
186
+ #define DBL2NUM(dbl) (rb_float_new(dbl))
187
+ #endif
188
+
189
+
190
+ // OpenCV module
191
+ __NAMESPACE_BEGIN_OPENCV
192
+
193
+ void mark_root_object(void *ptr);
194
+ VALUE lookup_root_object(void *ptr);
195
+ void register_root_object(void *ptr, VALUE root);
196
+ void unregister_object(void *ptr);
197
+ void free_object(void *ptr);
198
+ void release_object(void *ptr);
199
+ void release_iplconvkernel_object(void *ptr);
200
+
201
+ VALUE rb_module_opencv();
202
+ void init_ruby_module();
203
+
204
+ // Ruby/OpenCV inline functions
205
+ inline CvArr*
206
+ CVARR(VALUE object)
207
+ {
208
+ CvArr *ptr;
209
+ Data_Get_Struct(object, CvArr, ptr);
210
+ return ptr;
211
+ }
212
+
213
+ inline CvArr*
214
+ CVARR_WITH_CHECK(VALUE object)
215
+ {
216
+ Check_Type(object, T_DATA);
217
+ void *ptr = DATA_PTR(object);
218
+ if (CV_IS_IMAGE(ptr) || CV_IS_MAT(ptr) || CV_IS_SEQ(ptr) ||
219
+ CV_IS_MATND(ptr) || CV_IS_SPARSE_MAT(ptr)) {
220
+ return CVARR(object);
221
+ }
222
+ else {
223
+ raise_compatible_typeerror(object, (char*)"CvArr");
224
+ }
225
+ return NULL;
226
+ }
227
+
228
+ inline VALUE
229
+ OPENCV_OBJECT(VALUE klass, void *ptr)
230
+ {
231
+ return Data_Wrap_Struct(klass, 0, release_object, ptr);
232
+ }
233
+
234
+ inline VALUE
235
+ IPLCONVKERNEL_OBJECT(VALUE klass, void *ptr)
236
+ {
237
+ return Data_Wrap_Struct(klass, 0, release_iplconvkernel_object, ptr);
238
+ }
239
+
240
+ inline VALUE
241
+ GENERIC_OBJECT(VALUE klass, void *ptr)
242
+ {
243
+ return Data_Wrap_Struct(klass, 0, -1, ptr);
244
+ }
245
+
246
+ inline VALUE
247
+ DEPEND_OBJECT(VALUE klass, void *ptr, VALUE root)
248
+ {
249
+ register_root_object(ptr, root);
250
+ return Data_Wrap_Struct(klass, mark_root_object, free_object, ptr);
251
+ }
252
+
253
+ inline VALUE
254
+ REFER_OBJECT(VALUE klass, void *ptr, VALUE root)
255
+ {
256
+ register_root_object(ptr, root);
257
+ return Data_Wrap_Struct(klass, mark_root_object, unregister_object, ptr);
258
+ }
259
+
260
+ inline int
261
+ CVMETHOD(const char *name, VALUE method, int ifnone = 0)
262
+ {
263
+ VALUE value;
264
+ switch (TYPE(method)) {
265
+ case T_NIL:
266
+ return ifnone;
267
+ case T_FIXNUM:
268
+ return FIX2INT(method);
269
+ case T_STRING:
270
+ method = rb_str_intern(method);
271
+ case T_SYMBOL:
272
+ value = rb_hash_lookup(rb_const_get(rb_module_opencv(), rb_intern(name)), method);
273
+ return NIL_P(value) ? ifnone : FIX2INT(value);
274
+ default:
275
+ raise_typeerror(method, rb_cSymbol);
276
+ }
277
+ return ifnone;
278
+ }
279
+
280
+ inline int
281
+ TRUE_OR_FALSE(VALUE object, int ifnone = 0)
282
+ {
283
+ int value = ifnone;
284
+ switch (TYPE(object)) {
285
+ case T_TRUE:
286
+ value = 1;
287
+ break;
288
+ case T_FALSE:
289
+ value = 0;
290
+ break;
291
+ case T_NIL:
292
+ break;
293
+ default:
294
+ break;
295
+ }
296
+ return value;
297
+ }
298
+
299
+ inline int
300
+ CV2IPL_DEPTH(int depth)
301
+ {
302
+ switch (depth) {
303
+ case CV_8U:
304
+ return IPL_DEPTH_8U;
305
+ break;
306
+ case CV_8S:
307
+ return IPL_DEPTH_8S;
308
+ break;
309
+ case CV_16U:
310
+ return IPL_DEPTH_16U;
311
+ break;
312
+ case CV_32F:
313
+ return IPL_DEPTH_32F;
314
+ break;
315
+ case CV_32S:
316
+ return IPL_DEPTH_32S;
317
+ break;
318
+ case CV_64F:
319
+ return IPL_DEPTH_64F;
320
+ break;
321
+ default:
322
+ rb_raise(rb_eArgError, "Invalid depth: %d", depth);
323
+ break;
324
+ }
325
+ return 0;
326
+ }
327
+
328
+ VALUE rb_BGR2BGRA(VALUE klass, VALUE image);
329
+ VALUE rb_RGB2RGBA(VALUE klass, VALUE image);
330
+ VALUE rb_BGRA2BGR(VALUE klass, VALUE image);
331
+ VALUE rb_RGBA2RGB(VALUE klass, VALUE image);
332
+ VALUE rb_BGR2RGBA(VALUE klass, VALUE image);
333
+ VALUE rb_RGB2BGRA(VALUE klass, VALUE image);
334
+ VALUE rb_RGBA2BGR(VALUE klass, VALUE image);
335
+ VALUE rb_BGRA2RGB(VALUE klass, VALUE image);
336
+ VALUE rb_BGR2RGB(VALUE klass, VALUE image);
337
+ VALUE rb_RGB2BGR(VALUE klass, VALUE image);
338
+ VALUE rb_BGRA2RGBA(VALUE klass, VALUE image);
339
+ VALUE rb_RGBA2BGRA(VALUE klass, VALUE image);
340
+ VALUE rb_BGR2GRAY(VALUE klass, VALUE image);
341
+ VALUE rb_RGB2GRAY(VALUE klass, VALUE image);
342
+ VALUE rb_GRAY2BGR(VALUE klass, VALUE image);
343
+ VALUE rb_GRAY2RGB(VALUE klass, VALUE image);
344
+ VALUE rb_GRAY2BGRA(VALUE klass, VALUE image);
345
+ VALUE rb_GRAY2RGBA(VALUE klass, VALUE image);
346
+ VALUE rb_BGRA2GRAY(VALUE klass, VALUE image);
347
+ VALUE rb_RGBA2GRAY(VALUE klass, VALUE image);
348
+ VALUE rb_BGR2BGR565(VALUE klass, VALUE image);
349
+ VALUE rb_RGB2BGR565(VALUE klass, VALUE image);
350
+ VALUE rb_BGR5652BGR(VALUE klass, VALUE image);
351
+ VALUE rb_BGR5652RGB(VALUE klass, VALUE image);
352
+ VALUE rb_BGRA2BGR565(VALUE klass, VALUE image);
353
+ VALUE rb_RGBA2BGR565(VALUE klass, VALUE image);
354
+ VALUE rb_BGR5652BGRA(VALUE klass, VALUE image);
355
+ VALUE rb_BGR5652RGBA(VALUE klass, VALUE image);
356
+ VALUE rb_GRAY2BGR565(VALUE klass, VALUE image);
357
+ VALUE rb_BGR5652GRAY(VALUE klass, VALUE image);
358
+ VALUE rb_BGR2BGR555(VALUE klass, VALUE image);
359
+ VALUE rb_RGB2BGR555(VALUE klass, VALUE image);
360
+ VALUE rb_BGR5552BGR(VALUE klass, VALUE image);
361
+ VALUE rb_BGR5552RGB(VALUE klass, VALUE image);
362
+ VALUE rb_BGRA2BGR555(VALUE klass, VALUE image);
363
+ VALUE rb_RGBA2BGR555(VALUE klass, VALUE image);
364
+ VALUE rb_BGR5552BGRA(VALUE klass, VALUE image);
365
+ VALUE rb_BGR5552RGBA(VALUE klass, VALUE image);
366
+ VALUE rb_GRAY2BGR555(VALUE klass, VALUE image);
367
+ VALUE rb_BGR5552GRAY(VALUE klass, VALUE image);
368
+ VALUE rb_BGR2XYZ(VALUE klass, VALUE image);
369
+ VALUE rb_RGB2XYZ(VALUE klass, VALUE image);
370
+ VALUE rb_XYZ2BGR(VALUE klass, VALUE image);
371
+ VALUE rb_XYZ2RGB(VALUE klass, VALUE image);
372
+ VALUE rb_BGR2YCrCb(VALUE klass, VALUE image);
373
+ VALUE rb_RGB2YCrCb(VALUE klass, VALUE image);
374
+ VALUE rb_YCrCb2BGR(VALUE klass, VALUE image);
375
+ VALUE rb_YCrCb2RGB(VALUE klass, VALUE image);
376
+ VALUE rb_BGR2HSV(VALUE klass, VALUE image);
377
+ VALUE rb_RGB2HSV(VALUE klass, VALUE image);
378
+ VALUE rb_BGR2Lab(VALUE klass, VALUE image);
379
+ VALUE rb_RGB2Lab(VALUE klass, VALUE image);
380
+ VALUE rb_BayerBG2BGR(VALUE klass, VALUE image);
381
+ VALUE rb_BayerGB2BGR(VALUE klass, VALUE image);
382
+ VALUE rb_BayerRG2BGR(VALUE klass, VALUE image);
383
+ VALUE rb_BayerGR2BGR(VALUE klass, VALUE image);
384
+ VALUE rb_BayerBG2RGB(VALUE klass, VALUE image);
385
+ VALUE rb_BayerGB2RGB(VALUE klass, VALUE image);
386
+ VALUE rb_BayerRG2RGB(VALUE klass, VALUE image);
387
+ VALUE rb_BayerGR2RGB(VALUE klass, VALUE image);
388
+ VALUE rb_BGR2Luv(VALUE klass, VALUE image);
389
+ VALUE rb_RGB2Luv(VALUE klass, VALUE image);
390
+ VALUE rb_BGR2HLS(VALUE klass, VALUE image);
391
+ VALUE rb_RGB2HLS(VALUE klass, VALUE image);
392
+ VALUE rb_HSV2BGR(VALUE klass, VALUE image);
393
+ VALUE rb_HSV2RGB(VALUE klass, VALUE image);
394
+ VALUE rb_Lab2BGR(VALUE klass, VALUE image);
395
+ VALUE rb_Lab2RGB(VALUE klass, VALUE image);
396
+ VALUE rb_Luv2BGR(VALUE klass, VALUE image);
397
+ VALUE rb_Luv2RGB(VALUE klass, VALUE image);
398
+ VALUE rb_HLS2BGR(VALUE klass, VALUE image);
399
+ VALUE rb_HLS2RGB(VALUE klass, VALUE image);
400
+
401
+ VALUE rb_build_information(VALUE klass);
402
+
403
+ __NAMESPACE_END_OPENCV
404
+
405
+ #endif // RUBY_OPENCV_H
@@ -0,0 +1,280 @@
1
+ /************************************************************
2
+
3
+ pointset.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "pointset.h"
11
+ /*
12
+ * Document-class: OpenCV::PointSet
13
+ */
14
+
15
+ __NAMESPACE_BEGIN_OPENCV
16
+ __NAMESPACE_BEGIN_POINT_SET
17
+
18
+ VALUE module;
19
+
20
+ VALUE
21
+ rb_module()
22
+ {
23
+ return module;
24
+ }
25
+
26
+ /*
27
+ * call-seq:
28
+ * contour_area -> float
29
+ *
30
+ * Calculates area of the whole contour or contour section.
31
+ *
32
+ * note: Orientation of the contour affects the area sign, thus the method may return negative result.
33
+ */
34
+ VALUE
35
+ rb_contour_area(int argc, VALUE *argv, VALUE self)
36
+ {
37
+ VALUE slice;
38
+ rb_scan_args(argc, argv, "01", &slice);
39
+ double area = 0;
40
+ try {
41
+ area = cvContourArea(CVARR(self), NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice));
42
+ }
43
+ catch (cv::Exception& e) {
44
+ raise_cverror(e);
45
+ }
46
+ return rb_float_new(area);
47
+ }
48
+
49
+ /*
50
+ * call-seq:
51
+ * fit_ellipse2 -> cvbox2d
52
+ *
53
+ * Return fits ellipse to set of 2D points.
54
+ */
55
+ VALUE
56
+ rb_fit_ellipse2(VALUE self)
57
+ {
58
+ CvBox2D box;
59
+ try {
60
+ box = cvFitEllipse2(CVARR(self));
61
+ }
62
+ catch (cv::Exception& e) {
63
+ raise_cverror(e);
64
+ }
65
+ return cCvBox2D::new_object(box);
66
+ }
67
+
68
+ /*
69
+ * call-seq:
70
+ * convex_hull2([orientation_clockwise = true]) -> cvcontour
71
+ *
72
+ * Finds convex hull of 2D point set using Sklansky's algorithm.
73
+ *
74
+ * <i>orientation_clockwise</i>: Desired orientation of convex hull (true: clockwise, false: counter clockwise).
75
+ */
76
+ VALUE
77
+ rb_convex_hull2(int argc, VALUE *argv, VALUE self)
78
+ {
79
+ VALUE clockwise, return_points;
80
+ rb_scan_args(argc, argv, "02", &clockwise, &return_points);
81
+ VALUE storage = cCvMemStorage::new_object();
82
+ CvSeq *hull = NULL;
83
+ int return_pts = TRUE_OR_FALSE(return_points, 1);
84
+ try {
85
+ hull = cvConvexHull2(CVSEQ(self), CVMEMSTORAGE(storage),
86
+ TRUE_OR_FALSE(clockwise, 1) ? CV_CLOCKWISE : CV_COUNTER_CLOCKWISE,
87
+ return_pts);
88
+ }
89
+ catch (cv::Exception& e) {
90
+ raise_cverror(e);
91
+ }
92
+ return cCvSeq::new_sequence(cCvContour::rb_class(), hull, cCvPoint::rb_class(), storage);
93
+ }
94
+
95
+ /*
96
+ * call-seq:
97
+ * check_contour_convexity -> true or false
98
+ *
99
+ * Tests whether the input contour is convex or not. The contour must be simple, i.e. without self-intersections.
100
+ */
101
+ VALUE
102
+ rb_check_contour_convexity(VALUE self)
103
+ {
104
+ int convexity = 0;
105
+ try {
106
+ convexity = cvCheckContourConvexity(CVARR(self));
107
+ }
108
+ catch (cv::Exception& e) {
109
+ raise_cverror(e);
110
+ }
111
+ return convexity ? Qtrue : Qfalse;
112
+ }
113
+
114
+ /*
115
+ * call-seq:
116
+ * convexity_defects(hull) -> cvseq(include CvConvexityDefect)
117
+ *
118
+ * Finds convexity defects of contour.
119
+ */
120
+ VALUE
121
+ rb_convexity_defects(VALUE self, VALUE hull)
122
+ {
123
+ CvSeq *defects = NULL;
124
+ CvSeq *hull_seq = CVSEQ_WITH_CHECK(hull);
125
+ VALUE storage = cCvMemStorage::new_object();
126
+ CvMemStorage *storage_ptr = CVMEMSTORAGE(storage);
127
+ try {
128
+ defects = cvConvexityDefects(CVSEQ(self), hull_seq, storage_ptr);
129
+ }
130
+ catch (cv::Exception& e) {
131
+ raise_cverror(e);
132
+ }
133
+ return cCvSeq::new_sequence(cCvSeq::rb_class(), defects, cCvConvexityDefect::rb_class(), storage);
134
+ }
135
+
136
+ /*
137
+ * call-seq:
138
+ * min_area_rect2 -> cvbox2d
139
+ *
140
+ * Finds circumscribed rectangle of minimal area for given 2D point set.
141
+ */
142
+ VALUE
143
+ rb_min_area_rect2(VALUE self)
144
+ {
145
+ VALUE storage = cCvMemStorage::new_object();
146
+ CvBox2D rect;
147
+ try {
148
+ rect = cvMinAreaRect2(CVARR(self), CVMEMSTORAGE(storage));
149
+ }
150
+ catch (cv::Exception& e) {
151
+ raise_cverror(e);
152
+ }
153
+ return cCvBox2D::new_object(rect);
154
+ }
155
+
156
+ /*
157
+ * call-seq:
158
+ * min_enclosing_circle -> cvcircle32f
159
+ *
160
+ * Finds circumscribed circle of minimal area for given 2D point set.
161
+ */
162
+ VALUE
163
+ rb_min_enclosing_circle(VALUE self)
164
+ {
165
+ VALUE circle = cCvCircle32f::rb_allocate(cCvCircle32f::rb_class());
166
+ int success = 0;
167
+ try {
168
+ success = cvMinEnclosingCircle(CVARR(self), &CVCIRCLE32F(circle)->center,
169
+ &CVCIRCLE32F(circle)->radius);
170
+ }
171
+ catch (cv::Exception& e) {
172
+ raise_cverror(e);
173
+ }
174
+ return success ? circle : Qnil;
175
+ }
176
+
177
+ void
178
+ init_ruby_module()
179
+ {
180
+ #if 0
181
+ // For documentation using YARD
182
+ VALUE opencv = rb_define_module("OpenCV");
183
+ #endif
184
+
185
+ if (module)
186
+ return;
187
+ /*
188
+ * opencv = rb_define_module("OpenCV");
189
+ *
190
+ * note: this comment is used by rdoc.
191
+ */
192
+ VALUE opencv = rb_module_opencv();
193
+ module = rb_define_module_under(opencv, "PointSet");
194
+ rb_define_method(module, "contour_area", RUBY_METHOD_FUNC(rb_contour_area), -1);
195
+ rb_define_method(module, "fit_ellipse2", RUBY_METHOD_FUNC(rb_fit_ellipse2), 0);
196
+
197
+ rb_define_method(module, "convex_hull2", RUBY_METHOD_FUNC(rb_convex_hull2), -1);
198
+ rb_define_method(module, "check_contour_convexity", RUBY_METHOD_FUNC(rb_check_contour_convexity), 0);
199
+ rb_define_alias(module, "convexity?", "check_contour_convexity");
200
+ rb_define_method(module, "convexity_defects", RUBY_METHOD_FUNC(rb_convexity_defects), 1);
201
+ rb_define_method(module, "min_area_rect2", RUBY_METHOD_FUNC(rb_min_area_rect2), 0);
202
+ rb_define_method(module, "min_enclosing_circle", RUBY_METHOD_FUNC(rb_min_enclosing_circle), 0);
203
+ }
204
+
205
+ __NAMESPACE_END_POINT_SET
206
+
207
+ int
208
+ CVPOINTS_FROM_POINT_SET(VALUE object, CvPoint **pointset)
209
+ {
210
+ if (rb_obj_is_kind_of(object, cCvSeq::rb_class())) {
211
+ if (CV_IS_SEQ_POINT_SET(CVSEQ(object))) {
212
+ *pointset = (CvPoint*)cvCvtSeqToArray(CVSEQ(object),
213
+ rb_cvAlloc(CVSEQ(object)->total * CVSEQ(object)->elem_size));
214
+ return CVSEQ(object)->total;
215
+ }
216
+ else {
217
+ rb_raise(rb_eTypeError, "sequence does not contain %s or %s.",
218
+ rb_class2name(cCvPoint::rb_class()), rb_class2name(cCvPoint2D32f::rb_class()));
219
+ }
220
+ }
221
+ else if (rb_obj_is_kind_of(object, cCvMat::rb_class())) {
222
+ /* to do */
223
+ rb_raise(rb_eNotImpError, "CvMat to CvSeq conversion not implemented.");
224
+ }
225
+ else if (rb_obj_is_kind_of(object, rb_cArray)) {
226
+ int len = RARRAY_LEN(object);
227
+ *pointset = (CvPoint*)rb_cvAlloc(len * sizeof(CvPoint));
228
+ ID id_x = rb_intern("x");
229
+ ID id_y = rb_intern("y");
230
+ for (int i = 0; i < len; ++i) {
231
+ (*pointset)[i].x = NUM2INT(rb_funcall(rb_ary_entry(object, i), id_x, 0));
232
+ (*pointset)[i].y = NUM2INT(rb_funcall(rb_ary_entry(object, i), id_y, 0));
233
+ }
234
+ return len;
235
+ }
236
+ else {
237
+ rb_raise(rb_eTypeError, "Can't convert CvSeq(PointSet).");
238
+ }
239
+ }
240
+
241
+ CvSeq*
242
+ VALUE_TO_POINT_SET(VALUE object)
243
+ {
244
+ CvSeq *seq = 0;
245
+ VALUE tmp, storage;
246
+ int length;
247
+ CvPoint2D32f p32;
248
+ if (rb_obj_is_kind_of(object, cCvSeq::rb_class())) {
249
+ seq = CVSEQ(object);
250
+ if (CV_IS_SEQ_POINT_SET(seq)) {
251
+ return seq;
252
+ }
253
+ else {
254
+ rb_raise(rb_eTypeError, "sequence is not contain %s or %s.", rb_class2name(cCvPoint::rb_class()), rb_class2name(cCvPoint2D32f::rb_class()));
255
+ }
256
+ }
257
+ else if (rb_obj_is_kind_of(object, cCvMat::rb_class())) {
258
+ /* to do */
259
+ rb_raise(rb_eNotImpError, "CvMat to CvSeq conversion not implemented.");
260
+ }
261
+ else if (rb_obj_is_kind_of(object, rb_cArray)) {
262
+ //pointset = cCvSeq::new_sequence(cCvSeq::rb_class(), )
263
+ length = RARRAY_LEN(object);
264
+ storage = cCvMemStorage::new_object();
265
+ seq = cvCreateSeq(CV_SEQ_POINT_SET, sizeof(CvSeq), sizeof(CvPoint), CVMEMSTORAGE(storage));
266
+ for (int i = 0; i < RARRAY_LEN(object); i++) {
267
+ p32.x = NUM2DBL(rb_funcall(rb_ary_entry(object, i), rb_intern("x"), 0));
268
+ p32.y = NUM2DBL(rb_funcall(rb_ary_entry(object, i), rb_intern("y"), 0));
269
+ cvSeqPush(seq, &p32);
270
+ }
271
+ tmp = cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvPoint2D32f::rb_class(), storage);
272
+ return seq;
273
+ }
274
+ else {
275
+ rb_raise(rb_eTypeError, "Can't convert CvSeq(PointSet).");
276
+ }
277
+ }
278
+
279
+ __NAMESPACE_END_OPENCV
280
+