ruby-opencv 0.0.10-i386-mingw32

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