opencv 0.0.6

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 (117) hide show
  1. data/History.txt +5 -0
  2. data/License.txt +30 -0
  3. data/Manifest.txt +115 -0
  4. data/README.txt +47 -0
  5. data/Rakefile +34 -0
  6. data/examples/convexhull.rb +41 -0
  7. data/examples/face_detect.rb +25 -0
  8. data/examples/houghcircle.rb +23 -0
  9. data/examples/inpaint.png +0 -0
  10. data/examples/inpaint.rb +43 -0
  11. data/examples/paint.rb +72 -0
  12. data/examples/snake.rb +43 -0
  13. data/examples/stuff.jpg +0 -0
  14. data/ext/curve.cpp +103 -0
  15. data/ext/curve.h +34 -0
  16. data/ext/cvavgcomp.cpp +67 -0
  17. data/ext/cvavgcomp.h +39 -0
  18. data/ext/cvbox2d.cpp +114 -0
  19. data/ext/cvbox2d.h +53 -0
  20. data/ext/cvcapture.cpp +276 -0
  21. data/ext/cvcapture.h +54 -0
  22. data/ext/cvchain.cpp +184 -0
  23. data/ext/cvchain.h +43 -0
  24. data/ext/cvchaincode.cpp +49 -0
  25. data/ext/cvchaincode.h +43 -0
  26. data/ext/cvcircle32f.cpp +90 -0
  27. data/ext/cvcircle32f.h +53 -0
  28. data/ext/cvcondensation.cpp +230 -0
  29. data/ext/cvcondensation.h +49 -0
  30. data/ext/cvconnectedcomp.cpp +115 -0
  31. data/ext/cvconnectedcomp.h +46 -0
  32. data/ext/cvcontour.cpp +219 -0
  33. data/ext/cvcontour.h +47 -0
  34. data/ext/cvcontourtree.cpp +86 -0
  35. data/ext/cvcontourtree.h +41 -0
  36. data/ext/cvconvexitydefect.cpp +103 -0
  37. data/ext/cvconvexitydefect.h +42 -0
  38. data/ext/cverror.cpp +140 -0
  39. data/ext/cverror.h +79 -0
  40. data/ext/cvfont.cpp +173 -0
  41. data/ext/cvfont.h +56 -0
  42. data/ext/cvhaarclassifiercascade.cpp +159 -0
  43. data/ext/cvhaarclassifiercascade.h +41 -0
  44. data/ext/cvhistogram.cpp +200 -0
  45. data/ext/cvhistogram.h +51 -0
  46. data/ext/cvindex.cpp +73 -0
  47. data/ext/cvindex.h +40 -0
  48. data/ext/cvline.cpp +106 -0
  49. data/ext/cvline.h +52 -0
  50. data/ext/cvmat.cpp +4809 -0
  51. data/ext/cvmat.h +286 -0
  52. data/ext/cvmatnd.cpp +44 -0
  53. data/ext/cvmatnd.h +28 -0
  54. data/ext/cvmemstorage.cpp +64 -0
  55. data/ext/cvmemstorage.h +53 -0
  56. data/ext/cvmoments.cpp +204 -0
  57. data/ext/cvmoments.h +48 -0
  58. data/ext/cvpoint.cpp +229 -0
  59. data/ext/cvpoint.h +59 -0
  60. data/ext/cvpoint2d32f.cpp +213 -0
  61. data/ext/cvpoint2d32f.h +61 -0
  62. data/ext/cvpoint3d32f.cpp +245 -0
  63. data/ext/cvpoint3d32f.h +64 -0
  64. data/ext/cvrect.cpp +340 -0
  65. data/ext/cvrect.h +79 -0
  66. data/ext/cvscalar.cpp +227 -0
  67. data/ext/cvscalar.h +63 -0
  68. data/ext/cvseq.cpp +583 -0
  69. data/ext/cvseq.h +71 -0
  70. data/ext/cvset.cpp +63 -0
  71. data/ext/cvset.h +39 -0
  72. data/ext/cvsize.cpp +223 -0
  73. data/ext/cvsize.h +63 -0
  74. data/ext/cvsize2d32f.cpp +180 -0
  75. data/ext/cvsize2d32f.h +59 -0
  76. data/ext/cvslice.cpp +82 -0
  77. data/ext/cvslice.h +53 -0
  78. data/ext/cvsparsemat.cpp +44 -0
  79. data/ext/cvsparsemat.h +28 -0
  80. data/ext/cvtermcriteria.cpp +183 -0
  81. data/ext/cvtermcriteria.h +71 -0
  82. data/ext/cvtwopoints.cpp +98 -0
  83. data/ext/cvtwopoints.h +50 -0
  84. data/ext/cvvector.cpp +206 -0
  85. data/ext/cvvector.h +54 -0
  86. data/ext/cvvideowriter.cpp +116 -0
  87. data/ext/cvvideowriter.h +41 -0
  88. data/ext/extconf.rb +61 -0
  89. data/ext/gui.cpp +65 -0
  90. data/ext/gui.h +33 -0
  91. data/ext/iplconvkernel.cpp +177 -0
  92. data/ext/iplconvkernel.h +52 -0
  93. data/ext/iplimage.cpp +238 -0
  94. data/ext/iplimage.h +54 -0
  95. data/ext/mouseevent.cpp +184 -0
  96. data/ext/mouseevent.h +59 -0
  97. data/ext/opencv.cpp +481 -0
  98. data/ext/opencv.h +356 -0
  99. data/ext/point3dset.cpp +41 -0
  100. data/ext/point3dset.h +31 -0
  101. data/ext/pointset.cpp +238 -0
  102. data/ext/pointset.h +69 -0
  103. data/ext/trackbar.cpp +122 -0
  104. data/ext/trackbar.h +65 -0
  105. data/ext/window.cpp +368 -0
  106. data/ext/window.h +56 -0
  107. data/images/CvMat_sobel.png +0 -0
  108. data/images/CvMat_sub_rect.png +0 -0
  109. data/images/CvSeq_relationmap.png +0 -0
  110. data/images/face_detect_from_lena.jpg +0 -0
  111. data/lib/opencv.rb +3 -0
  112. data/lib/version.rb +3 -0
  113. data/setup/setup.cygwin.rb +120 -0
  114. data/setup/setup.mingw.rb +99 -0
  115. data/setup/setup.mswin32.rb +103 -0
  116. data/test/test_opencv.rb +4 -0
  117. metadata +191 -0
@@ -0,0 +1,356 @@
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
+ #include <version.h>
19
+
20
+ #ifdef RUBY_WIN32_H
21
+ #ifdef write
22
+ #undef write
23
+ #endif // write
24
+ #endif // RUBY_WIN32_H
25
+
26
+ #ifndef ANYARGS
27
+ #define ANYARGS ()
28
+ #endif
29
+
30
+ extern "C"{
31
+ #include <st.h>
32
+ #ifdef HAVE_CALLBACK_H
33
+ #include <callback.h> // callhack.h is ffcall header
34
+ #endif
35
+
36
+ #ifdef HAVE_STDARG_H
37
+ #include <stdarg.h>
38
+ #define va_init_list(a,b) va_start(a,b)
39
+ #else
40
+ #include <varargs.h>
41
+ #define va_init_list(a,b) va_start(a)
42
+ #endif
43
+ }
44
+
45
+ // standard c headers
46
+ #include <math.h>
47
+ #include <limits.h>
48
+ #include <float.h>
49
+ #include <assert.h>
50
+
51
+ // OpenCV headers
52
+ #include <cxcore.h>
53
+ #include <cv.h>
54
+ #include <highgui.h>
55
+ #include <cxmisc.h>
56
+ #ifdef HAVE_ML_H
57
+ #include <ml.h>
58
+ #endif
59
+
60
+ // Ruby/OpenCV headers
61
+ #include "cverror.h"
62
+ #include "cvpoint.h"
63
+ #include "cvpoint2d32f.h"
64
+ #include "cvsize.h"
65
+ #include "cvsize2d32f.h"
66
+ #include "cvrect.h"
67
+ #include "cvscalar.h"
68
+ #include "cvslice.h"
69
+ #include "cvtermcriteria.h"
70
+ #include "cvbox2d.h"
71
+ #include "cvfont.h"
72
+ #include "iplconvkernel.h"
73
+ #include "cvmoments.h"
74
+ #include "cvconvexitydefect.h"
75
+ #include "cvpoint3d32f.h"
76
+
77
+ #include "cvmemstorage.h"
78
+
79
+ #include "cvseq.h"
80
+ #include "curve.h"
81
+ #include "pointset.h"
82
+ #include "point3dset.h"
83
+ #include "cvset.h"
84
+ #include "cvchain.h"
85
+ #include "cvchaincode.h"
86
+ #include "cvcontour.h"
87
+ #include "cvcontourtree.h"
88
+
89
+ #include "cvmat.h"
90
+ #include "iplimage.h"
91
+ #include "cvmatnd.h"
92
+ #include "cvsparsemat.h"
93
+ #include "cvhistogram.h"
94
+ #include "cvcapture.h"
95
+
96
+ #include "cvindex.h"
97
+ #include "cvline.h"
98
+ #include "cvtwopoints.h"
99
+ #include "cvcircle32f.h"
100
+
101
+ #include "cvcondensation.h"
102
+
103
+ #include "cvconnectedcomp.h"
104
+ #include "cvavgcomp.h"
105
+ #include "cvhaarclassifiercascade.h"
106
+
107
+ // GUI
108
+ #include "gui.h"
109
+ #include "window.h"
110
+ #include "trackbar.h"
111
+ #include "mouseevent.h"
112
+
113
+ // memory management wrapper
114
+ #define CVALLOC(type) (type*)cvAlloc(sizeof(type))
115
+
116
+ // useful macros
117
+ #define IF_INT(val, ifnone) NIL_P(val) ? ifnone : NUM2INT(val)
118
+ #define IF_DBL(val, ifnone) NIL_P(val) ? ifnone : NUM2DBL(val)
119
+ #define IF_STRING(str) NIL_P(str) ? NULL : TYPE(str) == T_STRING ? rb
120
+ #define IF_BOOL(val, t, f, ifnone) val == Qtrue ? t : val == Qfalse ? f : ifnone
121
+
122
+ #define IF_DEPTH(val, ifnone) NIL_P(val) ? ifnone : FIX2INT(val)
123
+
124
+ #define RESIST_CVMETHOD(hash, str, value) rb_hash_aset(hash, ID2SYM(rb_intern(str)), INT2FIX(value))
125
+
126
+ #define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
127
+
128
+ // OpenCV module
129
+ __NAMESPACE_BEGIN_OPENCV
130
+
131
+ void mark_root_object(void *ptr);
132
+ VALUE lookup_root_object(void *ptr);
133
+ void resist_root_object(void *ptr, VALUE root);
134
+ void unresist_object(void *ptr);
135
+ void free_object(void *ptr);
136
+ void release_object(void *ptr);
137
+
138
+ VALUE rb_module_opencv();
139
+ void define_ruby_module();
140
+
141
+ // Ruby/OpenCV inline functions
142
+ inline CvArr*
143
+ CVARR(VALUE object)
144
+ {
145
+ CvArr *ptr;
146
+ Data_Get_Struct(object, CvArr, ptr);
147
+ return ptr;
148
+ }
149
+
150
+ inline VALUE
151
+ OPENCV_OBJECT(VALUE klass, void *ptr)
152
+ {
153
+ return Data_Wrap_Struct(klass, 0, release_object, ptr);
154
+ }
155
+
156
+ inline VALUE
157
+ GENERIC_OBJECT(VALUE klass, void *ptr)
158
+ {
159
+ return Data_Wrap_Struct(klass, 0, 0, ptr);
160
+ }
161
+
162
+ inline VALUE
163
+ DEPEND_OBJECT(VALUE klass, void *ptr, VALUE root)
164
+ {
165
+ resist_root_object(ptr, root);
166
+ return Data_Wrap_Struct(klass, mark_root_object, free_object, ptr);
167
+ }
168
+
169
+ inline VALUE
170
+ REFER_OBJECT(VALUE klass, void *ptr, VALUE root)
171
+ {
172
+ resist_root_object(ptr, root);
173
+ return Data_Wrap_Struct(klass, mark_root_object, unresist_object, ptr);
174
+ }
175
+
176
+ inline VALUE
177
+ CONVERT(VALUE object, VALUE klass)
178
+ {
179
+ VALUE method_name = rb_str_concat(rb_str_new2("from_"), rb_str_new2(rb_obj_classname(object)));
180
+ VALUE result = rb_funcall(klass, rb_intern(StringValueCStr(method_name)), 1, object);
181
+ if(CLASS_OF(result) != klass)
182
+ rb_raise(rb_eTypeError, "require %s, but return %s.", rb_class2name(klass), rb_class2name(CLASS_OF(result)));
183
+ return result;
184
+ }
185
+
186
+ inline int
187
+ CVMETHOD(const char *name, VALUE method, int ifnone = 0)
188
+ {
189
+ VALUE value;
190
+ switch(TYPE(method)){
191
+ case T_NIL:
192
+ return ifnone;
193
+ case T_FIXNUM:
194
+ return FIX2INT(method);
195
+ case T_STRING:
196
+ method = rb_str_intern(method);
197
+ case T_SYMBOL:
198
+ value = rb_hash_aref(rb_const_get(rb_module_opencv(), rb_intern(name)), method);
199
+ if(NIL_P(value)){
200
+ rb_warn("invalid opencv method type (see OpenCV::%s)", name);
201
+ return ifnone;
202
+ }else{
203
+ return FIX2INT(value);
204
+ }if (rb_obj_is_kind_of(value, rb_cNumeric))
205
+ default:
206
+ rb_raise(rb_eTypeError, "");
207
+ }
208
+ return 0;
209
+ }
210
+
211
+ inline int
212
+ TRUE_OR_FALSE(VALUE object, int ifnone)
213
+ {
214
+ int value = ifnone;
215
+ switch (TYPE(object)) {
216
+ case T_TRUE:
217
+ value = 1;
218
+ break;
219
+ case T_FALSE:
220
+ value = 0;
221
+ break;
222
+ case T_NIL:
223
+ break;
224
+ default:
225
+ rb_warn("argument should be true or false.");
226
+ }
227
+ return value;
228
+ }
229
+
230
+ VALUE rb_BGR2BGRA(VALUE klass, VALUE image);
231
+ VALUE rb_RGB2RGBA(VALUE klass, VALUE image);
232
+ VALUE rb_BGRA2BGR(VALUE klass, VALUE image);
233
+ VALUE rb_RGBA2RGB(VALUE klass, VALUE image);
234
+ VALUE rb_BGR2RGBA(VALUE klass, VALUE image);
235
+ VALUE rb_RGB2BGRA(VALUE klass, VALUE image);
236
+ VALUE rb_RGBA2BGR(VALUE klass, VALUE image);
237
+ VALUE rb_BGRA2RGB(VALUE klass, VALUE image);
238
+ VALUE rb_BGR2RGB(VALUE klass, VALUE image);
239
+ VALUE rb_RGB2BGR(VALUE klass, VALUE image);
240
+ VALUE rb_BGRA2RGBA(VALUE klass, VALUE image);
241
+ VALUE rb_RGBA2BGRA(VALUE klass, VALUE image);
242
+ VALUE rb_BGR2GRAY(VALUE klass, VALUE image);
243
+ VALUE rb_RGB2GRAY(VALUE klass, VALUE image);
244
+ VALUE rb_GRAY2BGR(VALUE klass, VALUE image);
245
+ VALUE rb_GRAY2RGB(VALUE klass, VALUE image);
246
+ VALUE rb_GRAY2BGRA(VALUE klass, VALUE image);
247
+ VALUE rb_GRAY2RGBA(VALUE klass, VALUE image);
248
+ VALUE rb_BGRA2GRAY(VALUE klass, VALUE image);
249
+ VALUE rb_RGBA2GRAY(VALUE klass, VALUE image);
250
+ VALUE rb_BGR2BGR565(VALUE klass, VALUE image);
251
+ VALUE rb_RGB2BGR565(VALUE klass, VALUE image);
252
+ VALUE rb_BGR5652BGR(VALUE klass, VALUE image);
253
+ VALUE rb_BGR5652RGB(VALUE klass, VALUE image);
254
+ VALUE rb_BGRA2BGR565(VALUE klass, VALUE image);
255
+ VALUE rb_RGBA2BGR565(VALUE klass, VALUE image);
256
+ VALUE rb_BGR5652BGRA(VALUE klass, VALUE image);
257
+ VALUE rb_BGR5652RGBA(VALUE klass, VALUE image);
258
+ VALUE rb_GRAY2BGR565(VALUE klass, VALUE image);
259
+ VALUE rb_BGR5652GRAY(VALUE klass, VALUE image);
260
+ VALUE rb_BGR2BGR555(VALUE klass, VALUE image);
261
+ VALUE rb_RGB2BGR555(VALUE klass, VALUE image);
262
+ VALUE rb_BGR5552BGR(VALUE klass, VALUE image);
263
+ VALUE rb_BGR5552RGB(VALUE klass, VALUE image);
264
+ VALUE rb_BGRA2BGR555(VALUE klass, VALUE image);
265
+ VALUE rb_RGBA2BGR555(VALUE klass, VALUE image);
266
+ VALUE rb_BGR5552BGRA(VALUE klass, VALUE image);
267
+ VALUE rb_BGR5552RGBA(VALUE klass, VALUE image);
268
+ VALUE rb_GRAY2BGR555(VALUE klass, VALUE image);
269
+ VALUE rb_BGR5552GRAY(VALUE klass, VALUE image);
270
+ VALUE rb_BGR2XYZ(VALUE klass, VALUE image);
271
+ VALUE rb_RGB2XYZ(VALUE klass, VALUE image);
272
+ VALUE rb_XYZ2BGR(VALUE klass, VALUE image);
273
+ VALUE rb_XYZ2RGB(VALUE klass, VALUE image);
274
+ VALUE rb_BGR2YCrCb(VALUE klass, VALUE image);
275
+ VALUE rb_RGB2YCrCb(VALUE klass, VALUE image);
276
+ VALUE rb_YCrCb2BGR(VALUE klass, VALUE image);
277
+ VALUE rb_YCrCb2RGB(VALUE klass, VALUE image);
278
+ VALUE rb_BGR2HSV(VALUE klass, VALUE image);
279
+ VALUE rb_RGB2HSV(VALUE klass, VALUE image);
280
+ VALUE rb_BGR2Lab(VALUE klass, VALUE image);
281
+ VALUE rb_RGB2Lab(VALUE klass, VALUE image);
282
+ VALUE rb_BayerBG2BGR(VALUE klass, VALUE image);
283
+ VALUE rb_BayerGB2BGR(VALUE klass, VALUE image);
284
+ VALUE rb_BayerRG2BGR(VALUE klass, VALUE image);
285
+ VALUE rb_BayerGR2BGR(VALUE klass, VALUE image);
286
+ VALUE rb_BayerBG2RGB(VALUE klass, VALUE image);
287
+ VALUE rb_BayerGB2RGB(VALUE klass, VALUE image);
288
+ VALUE rb_BayerRG2RGB(VALUE klass, VALUE image);
289
+ VALUE rb_BayerGR2RGB(VALUE klass, VALUE image);
290
+ VALUE rb_BGR2Luv(VALUE klass, VALUE image);
291
+ VALUE rb_RGB2Luv(VALUE klass, VALUE image);
292
+ VALUE rb_BGR2HLS(VALUE klass, VALUE image);
293
+ VALUE rb_RGB2HLS(VALUE klass, VALUE image);
294
+ VALUE rb_HSV2BGR(VALUE klass, VALUE image);
295
+ VALUE rb_HSV2RGB(VALUE klass, VALUE image);
296
+ VALUE rb_Lab2BGR(VALUE klass, VALUE image);
297
+ VALUE rb_Lab2RGB(VALUE klass, VALUE image);
298
+ VALUE rb_Luv2BGR(VALUE klass, VALUE image);
299
+ VALUE rb_Luv2RGB(VALUE klass, VALUE image);
300
+ VALUE rb_HLS2BGR(VALUE klass, VALUE image);
301
+ VALUE rb_HLS2RGB(VALUE klass, VALUE image);
302
+
303
+ __NAMESPACE_END_OPENCV
304
+
305
+ inline VALUE
306
+ extract_options_from_args_bang(VALUE ary)
307
+ {
308
+ return (RARRAY(ary)->len > 0 && rb_obj_is_kind_of(RARRAY(ary)->ptr[RARRAY(ary)->len -1], rb_cHash)) ? rb_ary_pop(ary) : rb_hash_new();
309
+ }
310
+
311
+ /*
312
+ inline VALUE
313
+ assert_valid_keys(VALUE keys, VALUE valid_keys)
314
+ {
315
+ VALUE unknown_keys = rb_funcall(keys, rb_intern("-"), 1, rb_funcall(valid_keys, rb_intern("flatten"), 0));
316
+ if (NUM2INT(rb_funcall(unknown_keys, rb_intern("empty?"), 0)) != 0){
317
+ rb_raise(rb_eArgError, "Unknown key(s): %s",
318
+ RSTRING(rb_funcall(unknown_keys, rb_intern("join"), 1, rb_str_new2(", ")))->ptr);
319
+ }
320
+ return Qnil;
321
+ }
322
+ */
323
+ /*
324
+ inline void
325
+ assert_valid_keys(VALUE options, int n, ...){
326
+ va_list valid_keys;
327
+ if (!(n > 0)) {return;}
328
+ VALUE unknown_keys = rb_funcall(options, rb_intern("keys"), 0);
329
+ va_start(valid_keys, n);
330
+ for (int i = 0; i < n; i++)
331
+ rb_ary_delete(unknown_keys, ID2SYM(rb_intern(va_arg(valid_keys, char*))));
332
+ if (RARRAY(unknown_keys)->len > 0)
333
+ rb_raise(rb_eArgError, "Unknown key(s): %s",
334
+ RSTRING(rb_funcall(unknown_keys, rb_intern("join"), 1, rb_str_new2(", ")))->ptr);
335
+ va_end(valid_keys);
336
+ }
337
+
338
+ inline VALUE
339
+ validate_option(VALUE options, const *char key, char *ifnone, int n, ...){
340
+ va_list valid_values;
341
+ VALUE value = rb_hash_aref(options, ID2SYM(rb_intern(key)));
342
+ if (!value || !(n > 0)) {return ifnone;}
343
+ va_start(valid_values, n);
344
+ for (int i = 0; i < n; i++){
345
+ if (!strcmp(StringValueCStr(value), va_arg(valid_values, char*))){
346
+ rb_warn("Option :%s value :%s does not defined. Default value :%s is used.", StringValueCStr(value), );
347
+ return ifnone;
348
+ }
349
+ }
350
+ va_end(valid_values);
351
+ return value;
352
+ }
353
+
354
+ #define OPTIONS(value, hash, key, default) value = ((value = rb_hash_aref(hash, ID2SYM(rb_intern(key)))) ? value : default)
355
+ */
356
+ #endif // RUBY_OPENCV_H
@@ -0,0 +1,41 @@
1
+ /************************************************************
2
+
3
+ point3dset.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2008 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include"point3dset.h"
11
+ /*
12
+ * Document-class: OpenCV::Point3DSet
13
+ */
14
+
15
+ __NAMESPACE_BEGIN_OPENCV
16
+ __NAMESPACE_BEGIN_POINT3D_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, "Point3DSet");
38
+ }
39
+
40
+ __NAMESPACE_END_POINT3D_SET
41
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,31 @@
1
+ /************************************************************
2
+
3
+ point3dset.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2008 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_POINT3DSET_H
11
+ #define RUBY_OPENCV_POINT3DSET_H
12
+
13
+ #define __NAMESPACE_BEGIN_POINT3D_SET namespace mPoint3DSet{
14
+ #define __NAMESPACE_END_POINT3D_SET }
15
+
16
+ #include"opencv.h"
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_POINT3D_SET
20
+
21
+ VALUE rb_module();
22
+
23
+ void define_ruby_module();
24
+
25
+ __NAMESPACE_END_POINT3D_SET
26
+
27
+ #define POINT3D_SET_P(object) rb_obj_is_kind_of(object, cCvSeq::rb_class()) && CV_IS_SEQ_POINT3D_SET(CVSEQ(object))
28
+
29
+ __NAMESPACE_END_OPENCV
30
+
31
+ #endif // RUBY_OPENCV_POINT3DSET_H
@@ -0,0 +1,238 @@
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_ellipse", RUBY_METHOD_FUNC(rb_fit_ellipse), 0);
40
+
41
+ rb_define_method(module, "convex_hull", RUBY_METHOD_FUNC(rb_convex_hull), -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_rect", RUBY_METHOD_FUNC(rb_min_area_rect), 0);
46
+ rb_define_method(module, "min_enclosing_circle", RUBY_METHOD_FUNC(rb_min_enclosing_circle), 0);
47
+ }
48
+
49
+ VALUE
50
+ rb_extend_object(VALUE self, VALUE object)
51
+ {
52
+ CvSeq *seq = 0;
53
+ if(!rb_obj_is_kind_of(object, cCvSeq::rb_class()))
54
+ rb_raise(rb_eTypeError, "object is not %s.\n", rb_class2name(cCvSeq::rb_class()));
55
+
56
+ if(!CV_IS_SEQ(seq))
57
+ rb_raise(rb_eTypeError, "object is not sequence.");
58
+ return rb_call_super(1, &object);
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * contour_area -> float
64
+ *
65
+ * Calculates area of the whole contour or contour section.
66
+ *
67
+ * note: Orientation of the contour affects the area sign, thus the method may return negative result.
68
+ */
69
+ VALUE
70
+ rb_contour_area(int argc, VALUE *argv, VALUE self)
71
+ {
72
+ VALUE slice;
73
+ rb_scan_args(argc, argv, "01", &slice);
74
+ return rb_float_new(cvContourArea(CVARR(self), NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice)));
75
+ }
76
+
77
+ /*
78
+ * call-seq:
79
+ * fit_ellipse -> cvbox2d
80
+ *
81
+ * Return fits ellipse to set of 2D points.
82
+ */
83
+ VALUE
84
+ rb_fit_ellipse(VALUE self)
85
+ {
86
+ return cCvBox2D::new_object(cvFitEllipse2(CVARR(self)));
87
+ }
88
+
89
+ /*
90
+ * call-seq:
91
+ * convex_hull(<i>[reverse = fasle]</i>) -> cvcontour
92
+ *
93
+ * Finds convex hull of 2D point set using Sklansky's algorithm.
94
+ *
95
+ * <i>reverse</i> is desired orientation of convex hull.
96
+ * If reverse is false mean clockwise, otherwise counter clockwise.
97
+ */
98
+ VALUE
99
+ rb_convex_hull(int argc, VALUE *argv, VALUE self)
100
+ {
101
+ VALUE reverse, storage;
102
+ rb_scan_args(argc, argv, "01", &reverse);
103
+ storage = cCvMemStorage::new_object();
104
+ CvSeq *hull = cvConvexHull2(CVSEQ(self), CVMEMSTORAGE(storage), TRUE_OR_FALSE(reverse, 0) ? CV_COUNTER_CLOCKWISE : CV_CLOCKWISE, 1);
105
+ if(CV_IS_SEQ_HOLE(CVSEQ(self)))
106
+ hull->flags |= CV_SEQ_FLAG_HOLE;
107
+ return cCvSeq::new_sequence(cCvContour::rb_class(), hull, cCvPoint::rb_class(), storage);
108
+ }
109
+
110
+ /*
111
+ * call-seq:
112
+ * check_contour_convexity -> true or false
113
+ *
114
+ * Tests whether the input contour is convex or not. The contour must be simple, i.e. without self-intersections.
115
+ */
116
+ VALUE
117
+ rb_check_contour_convexity(VALUE self)
118
+ {
119
+ return cvCheckContourConvexity(CVARR(self)) ? Qtrue : Qfalse;
120
+ }
121
+
122
+ /*
123
+ * call-seq:
124
+ * convexity_defects(<i>[reverse = false]</i>) -> cvseq(include CvConvexityDefect)
125
+ *
126
+ * Finds convexity defects of contour.
127
+ */
128
+ VALUE
129
+ rb_convexity_defects(int argc, VALUE *argv, VALUE self)
130
+ {
131
+ VALUE reverse, storage;
132
+ rb_scan_args(argc, argv, "01", &reverse);
133
+ storage = cCvMemStorage::new_object();
134
+ CvSeq *hull, *convex;
135
+ hull = cvConvexHull2(CVSEQ(self), CVMEMSTORAGE(storage), TRUE_OR_FALSE(reverse, 0) ? CV_COUNTER_CLOCKWISE : CV_CLOCKWISE, 0);
136
+ convex = cvConvexityDefects(CVSEQ(self), hull, CVMEMSTORAGE(storage));
137
+ return cCvSeq::new_sequence(cCvSeq::rb_class(), convex, cCvConvexityDefect::rb_class(), storage);
138
+ }
139
+
140
+ /*
141
+ * call-seq:
142
+ * min_area_rect -> cvbox2d
143
+ *
144
+ * Finds circumscribed rectangle of minimal area for given 2D point set.
145
+ */
146
+ VALUE
147
+ rb_min_area_rect(VALUE self)
148
+ {
149
+ VALUE storage = cCvMemStorage::new_object();
150
+ return cCvBox2D::new_object(cvMinAreaRect2(CVARR(self), CVMEMSTORAGE(storage)));
151
+ }
152
+
153
+ /*
154
+ * call-seq:
155
+ * min_enclosing_circle -> cvcircle32f
156
+ *
157
+ * Finds circumscribed circle of minimal area for given 2D point set.
158
+ */
159
+ VALUE
160
+ rb_min_enclosing_circle(VALUE self)
161
+ {
162
+ VALUE circle = cCvCircle32f::rb_allocate(cCvCircle32f::rb_class());
163
+ cvMinEnclosingCircle(CVARR(self), &CVCIRCLE32F(circle)->center, &CVCIRCLE32F(circle)->radius);
164
+ return circle;
165
+ }
166
+
167
+ VALUE
168
+ rb_calc_pgh(VALUE self)
169
+ {
170
+ /* not yet */
171
+ return Qnil;
172
+ }
173
+
174
+ __NAMESPACE_END_POINT_SET
175
+
176
+ int
177
+ CVPOINTS_FROM_POINT_SET(VALUE object, CvPoint **pointset)
178
+ {
179
+ VALUE storage;
180
+ CvSeq *seq = 0;
181
+ CvPoint2D32f p32;
182
+ if(rb_obj_is_kind_of(object, cCvSeq::rb_class())){
183
+ if(CV_IS_SEQ_POINT_SET(CVSEQ(object))){
184
+ *pointset = (CvPoint*)cvCvtSeqToArray(CVSEQ(object), cvAlloc(CVSEQ(object)->total * CVSEQ(object)->elem_size));
185
+ return CVSEQ(object)->total;
186
+ }else{
187
+ rb_raise(rb_eTypeError, "sequence is not contain %s or %s.", rb_class2name(cCvPoint::rb_class()), rb_class2name(cCvPoint2D32f::rb_class()));
188
+ }
189
+ }else if(rb_obj_is_kind_of(object, cCvMat::rb_class())){
190
+ /* to do */
191
+ rb_raise(rb_eNotImpError, "CvMat to CvSeq conversion not implemented.");
192
+ }else if(rb_obj_is_kind_of(object, rb_cArray)){
193
+ *pointset = (CvPoint*)cvAlloc(RARRAY(object)->len * sizeof(CvPoint));
194
+ for(int i = 0; i < RARRAY(object)->len; i++){
195
+ (*pointset)[i].x = NUM2INT(rb_funcall(rb_ary_entry(object, i), rb_intern("x"), 0));
196
+ (*pointset)[i].y = NUM2INT(rb_funcall(rb_ary_entry(object, i), rb_intern("y"), 0));
197
+ }
198
+ return RARRAY(object)->len;
199
+ }else{
200
+ rb_raise(rb_eTypeError, "Can't convert CvSeq(PointSet).");
201
+ }
202
+ }
203
+
204
+ CvSeq*
205
+ VALUE_TO_POINT_SET(VALUE object)
206
+ {
207
+ CvSeq *seq = 0;
208
+ VALUE tmp, storage;
209
+ int length;
210
+ CvPoint2D32f p32;
211
+ if(rb_obj_is_kind_of(object, cCvSeq::rb_class())){
212
+ seq = CVSEQ(object);
213
+ if(CV_IS_SEQ_POINT_SET(seq)){
214
+ return seq;
215
+ }else{
216
+ rb_raise(rb_eTypeError, "sequence is not contain %s or %s.", rb_class2name(cCvPoint::rb_class()), rb_class2name(cCvPoint2D32f::rb_class()));
217
+ }
218
+ }else if(rb_obj_is_kind_of(object, cCvMat::rb_class())){
219
+ /* to do */
220
+ rb_raise(rb_eNotImpError, "CvMat to CvSeq conversion not implemented.");
221
+ }else if(rb_obj_is_kind_of(object, rb_cArray)){
222
+ //pointset = cCvSeq::new_sequence(cCvSeq::rb_class(), )
223
+ length = RARRAY(object)->len;
224
+ storage = cCvMemStorage::new_object();
225
+ seq = cvCreateSeq(CV_SEQ_POINT_SET, sizeof(CvSeq), sizeof(CvPoint), CVMEMSTORAGE(storage));
226
+ for(int i = 0; i < RARRAY(object)->len; i++){
227
+ p32.x = NUM2DBL(rb_funcall(rb_ary_entry(object, i), rb_intern("x"), 0));
228
+ p32.y = NUM2DBL(rb_funcall(rb_ary_entry(object, i), rb_intern("y"), 0));
229
+ cvSeqPush(seq, &p32);
230
+ }
231
+ tmp = cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvPoint2D32f::rb_class(), storage);
232
+ return seq;
233
+ }else{
234
+ rb_raise(rb_eTypeError, "Can't convert CvSeq(PointSet).");
235
+ }
236
+ }
237
+
238
+ __NAMESPACE_END_OPENCV