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