jf-ruby-opencv 0.0.18

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 (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,408 @@
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
+ // Workaround for https://bugs.ruby-lang.org/issues/11962
25
+ #undef RB_OBJ_WB_UNPROTECT_FOR
26
+ #define RB_OBJ_WB_UNPROTECT_FOR(type, obj) \
27
+ (RGENGC_WB_PROTECTED_##type ? \
28
+ OBJ_WB_UNPROTECT((VALUE)(obj)) : ((VALUE)(obj)))
29
+
30
+ #ifdef RUBY_WIN32_H
31
+ #ifdef write
32
+ #undef write
33
+ #endif // write
34
+ #endif // RUBY_WIN32_H
35
+
36
+ #ifndef ANYARGS
37
+ #define ANYARGS ()
38
+ #endif
39
+
40
+ extern "C" {
41
+ #ifdef HAVE_RUBY_ST_H
42
+ #include <ruby/st.h>
43
+ #else
44
+ #include <st.h>
45
+ #endif
46
+
47
+ #ifdef HAVE_STDARG_H
48
+ #include <stdarg.h>
49
+ #define va_init_list(a,b) va_start(a,b)
50
+ #else
51
+ #include <varargs.h>
52
+ #define va_init_list(a,b) va_start(a)
53
+ #endif
54
+ }
55
+
56
+ // standard c headers
57
+ #define _USE_MATH_DEFINES // for VC++
58
+ #include <math.h>
59
+ #include <limits.h>
60
+ #include <float.h>
61
+ #include <assert.h>
62
+
63
+ // OpenCV headers
64
+ #include "opencv2/core/core_c.h"
65
+ #include "opencv2/core/core.hpp"
66
+ #include "opencv2/imgproc/imgproc_c.h"
67
+ #include "opencv2/imgproc/imgproc.hpp"
68
+ #include "opencv2/video/tracking.hpp"
69
+ #include "opencv2/video/background_segm.hpp"
70
+ #include "opencv2/features2d/features2d.hpp"
71
+ #include "opencv2/flann/flann.hpp"
72
+ #include "opencv2/calib3d/calib3d.hpp"
73
+ #include "opencv2/objdetect/objdetect.hpp"
74
+ #include "opencv2/legacy/compat.hpp"
75
+ #include "opencv2/legacy/legacy.hpp"
76
+ #include "opencv2/legacy/blobtrack.hpp"
77
+ #include "opencv2/contrib/contrib.hpp"
78
+ #include "opencv2/highgui/highgui_c.h"
79
+ #include "opencv2/highgui/highgui.hpp"
80
+ #include "opencv2/core/internal.hpp"
81
+ #include "opencv2/photo/photo.hpp"
82
+
83
+ #ifdef HAVE_ML_H
84
+ #include "opencv2/ml/ml.hpp"
85
+ #endif
86
+
87
+ #ifdef HAVE_OPENCV2_NONFREE_NONFREE_HPP
88
+ #include "opencv2/nonfree/nonfree.hpp"
89
+ #endif
90
+
91
+ // Ruby/OpenCV headers
92
+ #include "cvutils.h"
93
+ #include "cverror.h"
94
+ #include "cvpoint.h"
95
+ #include "cvpoint2d32f.h"
96
+ #include "cvsize.h"
97
+ #include "cvsize2d32f.h"
98
+ #include "cvrect.h"
99
+ #include "cvscalar.h"
100
+ #include "cvslice.h"
101
+ #include "cvtermcriteria.h"
102
+ #include "cvbox2d.h"
103
+ #include "cvfont.h"
104
+ #include "iplconvkernel.h"
105
+ #include "cvmoments.h"
106
+ #include "cvhumoments.h"
107
+ #include "cvconvexitydefect.h"
108
+ #include "cvpoint3d32f.h"
109
+
110
+ #include "cvmemstorage.h"
111
+
112
+ #include "cvseq.h"
113
+ #include "curve.h"
114
+ #include "pointset.h"
115
+ #include "cvchain.h"
116
+ #include "cvcontour.h"
117
+ #include "cvcontourtree.h"
118
+
119
+ #include "cvmat.h"
120
+ #include "iplimage.h"
121
+ #include "cvhistogram.h"
122
+ #include "cvcapture.h"
123
+ #include "cvvideowriter.h"
124
+
125
+ #include "cvline.h"
126
+ #include "cvtwopoints.h"
127
+ #include "cvcircle32f.h"
128
+
129
+ #include "cvconnectedcomp.h"
130
+ #include "cvavgcomp.h"
131
+ #include "cvhaarclassifiercascade.h"
132
+
133
+ #include "cvsurfpoint.h"
134
+ #include "cvsurfparams.h"
135
+
136
+ #include "cvfeaturetree.h"
137
+
138
+ #include "algorithm.h"
139
+ #include "facerecognizer.h"
140
+ #include "eigenfaces.h"
141
+ #include "fisherfaces.h"
142
+ #include "lbph.h"
143
+
144
+ // GUI
145
+ #include "gui.h"
146
+ #include "window.h"
147
+ #include "trackbar.h"
148
+ #include "mouseevent.h"
149
+
150
+ // memory management wrapper
151
+ #define RB_CVALLOC(type) (type*)rb_cvAlloc(sizeof(type))
152
+
153
+ // useful macros
154
+ #define IF_INT(val, ifnone) NIL_P(val) ? ifnone : NUM2INT(val)
155
+ #define IF_DBL(val, ifnone) NIL_P(val) ? ifnone : NUM2DBL(val)
156
+ #define IF_BOOL(val, t, f, ifnone) val == Qtrue ? t : val == Qfalse ? f : ifnone
157
+
158
+ #define REGISTER_HASH(hash, str, value) rb_hash_aset(hash, ID2SYM(rb_intern(str)), INT2FIX(value))
159
+ #define LOOKUP_HASH(hash, key_as_cstr) (rb_hash_lookup(hash, ID2SYM(rb_intern(key_as_cstr))))
160
+
161
+ #define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
162
+
163
+ #ifndef BOOL2INT
164
+ #define BOOL2INT(x) ((x == Qtrue) ? 1 : 0)
165
+ #endif
166
+
167
+ #ifndef INT2BOOL
168
+ #define INT2BOOL(x) (x ? Qtrue : Qfalse)
169
+ #endif
170
+
171
+ // wrapper for <= 1.8
172
+ #ifndef RARRAY_LEN
173
+ #define RARRAY_LEN(arg) (RARRAY(arg)->len)
174
+ #endif
175
+
176
+ #ifndef RARRAY_PTR
177
+ #define RARRAY_PTR(arg) (RARRAY(arg)->ptr)
178
+ #endif
179
+
180
+ #ifndef RSTRING_LEN
181
+ #define RSTRING_LEN(arg) (RSTRING(arg)->len)
182
+ #endif
183
+
184
+ #ifndef RSTRING_PTR
185
+ #define RSTRING_PTR(arg) (RSTRING(arg)->ptr)
186
+ #endif
187
+
188
+ #ifndef DBL2NUM
189
+ #define DBL2NUM(dbl) (rb_float_new(dbl))
190
+ #endif
191
+
192
+
193
+ // OpenCV module
194
+ __NAMESPACE_BEGIN_OPENCV
195
+
196
+ void mark_root_object(void *ptr);
197
+ VALUE lookup_root_object(void *ptr);
198
+ void register_root_object(void *ptr, VALUE root);
199
+ void unregister_object(void *ptr);
200
+ void free_object(void *ptr);
201
+ void release_object(void *ptr);
202
+ void release_iplconvkernel_object(void *ptr);
203
+
204
+ VALUE rb_module_opencv();
205
+ void init_ruby_module();
206
+
207
+ // Ruby/OpenCV inline functions
208
+ inline CvArr*
209
+ CVARR(VALUE object)
210
+ {
211
+ CvArr *ptr;
212
+ Data_Get_Struct(object, CvArr, ptr);
213
+ return ptr;
214
+ }
215
+
216
+ inline CvArr*
217
+ CVARR_WITH_CHECK(VALUE object)
218
+ {
219
+ Check_Type(object, T_DATA);
220
+ void *ptr = DATA_PTR(object);
221
+ if (CV_IS_IMAGE(ptr) || CV_IS_MAT(ptr) || CV_IS_SEQ(ptr) ||
222
+ CV_IS_MATND(ptr) || CV_IS_SPARSE_MAT(ptr)) {
223
+ return CVARR(object);
224
+ }
225
+ else {
226
+ raise_compatible_typeerror(object, (char*)"CvArr");
227
+ }
228
+ return NULL;
229
+ }
230
+
231
+ inline VALUE
232
+ OPENCV_OBJECT(VALUE klass, void *ptr)
233
+ {
234
+ return Data_Wrap_Struct(klass, 0, release_object, ptr);
235
+ }
236
+
237
+ inline VALUE
238
+ IPLCONVKERNEL_OBJECT(VALUE klass, void *ptr)
239
+ {
240
+ return Data_Wrap_Struct(klass, 0, release_iplconvkernel_object, ptr);
241
+ }
242
+
243
+ inline VALUE
244
+ GENERIC_OBJECT(VALUE klass, void *ptr)
245
+ {
246
+ return Data_Wrap_Struct(klass, 0, -1, ptr);
247
+ }
248
+
249
+ inline VALUE
250
+ DEPEND_OBJECT(VALUE klass, void *ptr, VALUE root)
251
+ {
252
+ register_root_object(ptr, root);
253
+ return Data_Wrap_Struct(klass, mark_root_object, free_object, ptr);
254
+ }
255
+
256
+ inline VALUE
257
+ REFER_OBJECT(VALUE klass, void *ptr, VALUE root)
258
+ {
259
+ register_root_object(ptr, root);
260
+ return Data_Wrap_Struct(klass, mark_root_object, unregister_object, ptr);
261
+ }
262
+
263
+ inline int
264
+ CVMETHOD(const char *name, VALUE method, int ifnone = 0)
265
+ {
266
+ VALUE value;
267
+ switch (TYPE(method)) {
268
+ case T_NIL:
269
+ return ifnone;
270
+ case T_FIXNUM:
271
+ return FIX2INT(method);
272
+ case T_STRING:
273
+ method = rb_str_intern(method);
274
+ case T_SYMBOL:
275
+ value = rb_hash_lookup(rb_const_get(rb_module_opencv(), rb_intern(name)), method);
276
+ return NIL_P(value) ? ifnone : FIX2INT(value);
277
+ default:
278
+ raise_typeerror(method, rb_cSymbol);
279
+ }
280
+ return ifnone;
281
+ }
282
+
283
+ inline int
284
+ TRUE_OR_FALSE(VALUE object, int ifnone = 0)
285
+ {
286
+ int value = ifnone;
287
+ switch (TYPE(object)) {
288
+ case T_TRUE:
289
+ value = 1;
290
+ break;
291
+ case T_FALSE:
292
+ value = 0;
293
+ break;
294
+ case T_NIL:
295
+ break;
296
+ default:
297
+ break;
298
+ }
299
+ return value;
300
+ }
301
+
302
+ inline int
303
+ CV2IPL_DEPTH(int depth)
304
+ {
305
+ switch (depth) {
306
+ case CV_8U:
307
+ return IPL_DEPTH_8U;
308
+ break;
309
+ case CV_8S:
310
+ return IPL_DEPTH_8S;
311
+ break;
312
+ case CV_16U:
313
+ return IPL_DEPTH_16U;
314
+ break;
315
+ case CV_32F:
316
+ return IPL_DEPTH_32F;
317
+ break;
318
+ case CV_32S:
319
+ return IPL_DEPTH_32S;
320
+ break;
321
+ case CV_64F:
322
+ return IPL_DEPTH_64F;
323
+ break;
324
+ default:
325
+ rb_raise(rb_eArgError, "Invalid depth: %d", depth);
326
+ break;
327
+ }
328
+ return 0;
329
+ }
330
+
331
+ VALUE rb_BGR2BGRA(VALUE klass, VALUE image);
332
+ VALUE rb_RGB2RGBA(VALUE klass, VALUE image);
333
+ VALUE rb_BGRA2BGR(VALUE klass, VALUE image);
334
+ VALUE rb_RGBA2RGB(VALUE klass, VALUE image);
335
+ VALUE rb_BGR2RGBA(VALUE klass, VALUE image);
336
+ VALUE rb_RGB2BGRA(VALUE klass, VALUE image);
337
+ VALUE rb_RGBA2BGR(VALUE klass, VALUE image);
338
+ VALUE rb_BGRA2RGB(VALUE klass, VALUE image);
339
+ VALUE rb_BGR2RGB(VALUE klass, VALUE image);
340
+ VALUE rb_RGB2BGR(VALUE klass, VALUE image);
341
+ VALUE rb_BGRA2RGBA(VALUE klass, VALUE image);
342
+ VALUE rb_RGBA2BGRA(VALUE klass, VALUE image);
343
+ VALUE rb_BGR2GRAY(VALUE klass, VALUE image);
344
+ VALUE rb_RGB2GRAY(VALUE klass, VALUE image);
345
+ VALUE rb_GRAY2BGR(VALUE klass, VALUE image);
346
+ VALUE rb_GRAY2RGB(VALUE klass, VALUE image);
347
+ VALUE rb_GRAY2BGRA(VALUE klass, VALUE image);
348
+ VALUE rb_GRAY2RGBA(VALUE klass, VALUE image);
349
+ VALUE rb_BGRA2GRAY(VALUE klass, VALUE image);
350
+ VALUE rb_RGBA2GRAY(VALUE klass, VALUE image);
351
+ VALUE rb_BGR2BGR565(VALUE klass, VALUE image);
352
+ VALUE rb_RGB2BGR565(VALUE klass, VALUE image);
353
+ VALUE rb_BGR5652BGR(VALUE klass, VALUE image);
354
+ VALUE rb_BGR5652RGB(VALUE klass, VALUE image);
355
+ VALUE rb_BGRA2BGR565(VALUE klass, VALUE image);
356
+ VALUE rb_RGBA2BGR565(VALUE klass, VALUE image);
357
+ VALUE rb_BGR5652BGRA(VALUE klass, VALUE image);
358
+ VALUE rb_BGR5652RGBA(VALUE klass, VALUE image);
359
+ VALUE rb_GRAY2BGR565(VALUE klass, VALUE image);
360
+ VALUE rb_BGR5652GRAY(VALUE klass, VALUE image);
361
+ VALUE rb_BGR2BGR555(VALUE klass, VALUE image);
362
+ VALUE rb_RGB2BGR555(VALUE klass, VALUE image);
363
+ VALUE rb_BGR5552BGR(VALUE klass, VALUE image);
364
+ VALUE rb_BGR5552RGB(VALUE klass, VALUE image);
365
+ VALUE rb_BGRA2BGR555(VALUE klass, VALUE image);
366
+ VALUE rb_RGBA2BGR555(VALUE klass, VALUE image);
367
+ VALUE rb_BGR5552BGRA(VALUE klass, VALUE image);
368
+ VALUE rb_BGR5552RGBA(VALUE klass, VALUE image);
369
+ VALUE rb_GRAY2BGR555(VALUE klass, VALUE image);
370
+ VALUE rb_BGR5552GRAY(VALUE klass, VALUE image);
371
+ VALUE rb_BGR2XYZ(VALUE klass, VALUE image);
372
+ VALUE rb_RGB2XYZ(VALUE klass, VALUE image);
373
+ VALUE rb_XYZ2BGR(VALUE klass, VALUE image);
374
+ VALUE rb_XYZ2RGB(VALUE klass, VALUE image);
375
+ VALUE rb_BGR2YCrCb(VALUE klass, VALUE image);
376
+ VALUE rb_RGB2YCrCb(VALUE klass, VALUE image);
377
+ VALUE rb_YCrCb2BGR(VALUE klass, VALUE image);
378
+ VALUE rb_YCrCb2RGB(VALUE klass, VALUE image);
379
+ VALUE rb_BGR2HSV(VALUE klass, VALUE image);
380
+ VALUE rb_RGB2HSV(VALUE klass, VALUE image);
381
+ VALUE rb_BGR2Lab(VALUE klass, VALUE image);
382
+ VALUE rb_RGB2Lab(VALUE klass, VALUE image);
383
+ VALUE rb_BayerBG2BGR(VALUE klass, VALUE image);
384
+ VALUE rb_BayerGB2BGR(VALUE klass, VALUE image);
385
+ VALUE rb_BayerRG2BGR(VALUE klass, VALUE image);
386
+ VALUE rb_BayerGR2BGR(VALUE klass, VALUE image);
387
+ VALUE rb_BayerBG2RGB(VALUE klass, VALUE image);
388
+ VALUE rb_BayerGB2RGB(VALUE klass, VALUE image);
389
+ VALUE rb_BayerRG2RGB(VALUE klass, VALUE image);
390
+ VALUE rb_BayerGR2RGB(VALUE klass, VALUE image);
391
+ VALUE rb_BGR2Luv(VALUE klass, VALUE image);
392
+ VALUE rb_RGB2Luv(VALUE klass, VALUE image);
393
+ VALUE rb_BGR2HLS(VALUE klass, VALUE image);
394
+ VALUE rb_RGB2HLS(VALUE klass, VALUE image);
395
+ VALUE rb_HSV2BGR(VALUE klass, VALUE image);
396
+ VALUE rb_HSV2RGB(VALUE klass, VALUE image);
397
+ VALUE rb_Lab2BGR(VALUE klass, VALUE image);
398
+ VALUE rb_Lab2RGB(VALUE klass, VALUE image);
399
+ VALUE rb_Luv2BGR(VALUE klass, VALUE image);
400
+ VALUE rb_Luv2RGB(VALUE klass, VALUE image);
401
+ VALUE rb_HLS2BGR(VALUE klass, VALUE image);
402
+ VALUE rb_HLS2RGB(VALUE klass, VALUE image);
403
+
404
+ VALUE rb_build_information(VALUE klass);
405
+
406
+ __NAMESPACE_END_OPENCV
407
+
408
+ #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
+