ruby-opencv 0.0.10-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +26 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +8 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +227 -0
- data/README.md +98 -0
- data/Rakefile +90 -0
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -0
- data/examples/box.png +0 -0
- data/examples/box_in_scene.png +0 -0
- data/examples/contours/bitmap-contours-with-labels.png +0 -0
- data/examples/contours/bitmap-contours.png +0 -0
- data/examples/contours/bounding-box-detect-canny.rb +62 -0
- data/examples/contours/contour_retrieval_modes.rb +139 -0
- data/examples/contours/rotated-boxes.jpg +0 -0
- data/examples/convexhull.rb +47 -0
- data/examples/face_detect.rb +20 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/lenna-rotated.jpg +0 -0
- data/examples/lenna.jpg +0 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/matching_to_many_images.rb +16 -0
- data/examples/matching_to_many_images/query.png +0 -0
- data/examples/matching_to_many_images/train/1.png +0 -0
- data/examples/matching_to_many_images/train/2.png +0 -0
- data/examples/matching_to_many_images/train/3.png +0 -0
- data/examples/matching_to_many_images/train/trainImages.txt +3 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/examples/stuff.jpg +0 -0
- data/examples/tiffany.jpg +0 -0
- data/ext/opencv/curve.cpp +112 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +67 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +197 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +506 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +233 -0
- data/ext/opencv/cvchain.h +46 -0
- data/ext/opencv/cvcircle32f.cpp +116 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvcondensation.cpp +282 -0
- data/ext/opencv/cvcondensation.h +49 -0
- data/ext/opencv/cvconnectedcomp.cpp +143 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +296 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +91 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +103 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +159 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +125 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +208 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +546 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +139 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +154 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +5848 -0
- data/ext/opencv/cvmat.h +284 -0
- data/ext/opencv/cvmatnd.cpp +44 -0
- data/ext/opencv/cvmatnd.h +28 -0
- data/ext/opencv/cvmemstorage.cpp +68 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +287 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +228 -0
- data/ext/opencv/cvpoint.h +64 -0
- data/ext/opencv/cvpoint2d32f.cpp +211 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +245 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +333 -0
- data/ext/opencv/cvrect.h +79 -0
- data/ext/opencv/cvscalar.cpp +236 -0
- data/ext/opencv/cvscalar.h +71 -0
- data/ext/opencv/cvseq.cpp +599 -0
- data/ext/opencv/cvseq.h +74 -0
- data/ext/opencv/cvsize.cpp +221 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +209 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +120 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsparsemat.cpp +44 -0
- data/ext/opencv/cvsparsemat.h +28 -0
- data/ext/opencv/cvsurfparams.cpp +199 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +223 -0
- data/ext/opencv/cvsurfpoint.h +52 -0
- data/ext/opencv/cvtermcriteria.cpp +192 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +116 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +192 -0
- data/ext/opencv/cvutils.h +30 -0
- data/ext/opencv/cvvideowriter.cpp +137 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/extconf.rb +83 -0
- data/ext/opencv/gui.cpp +68 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +192 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +644 -0
- data/ext/opencv/iplimage.h +73 -0
- data/ext/opencv/mouseevent.cpp +181 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +727 -0
- data/ext/opencv/opencv.h +400 -0
- data/ext/opencv/pointset.cpp +274 -0
- data/ext/opencv/pointset.h +68 -0
- data/ext/opencv/trackbar.cpp +121 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +357 -0
- data/ext/opencv/window.h +66 -0
- data/images/CvMat_sobel.png +0 -0
- data/images/CvMat_sub_rect.png +0 -0
- data/images/CvSeq_relationmap.png +0 -0
- data/images/face_detect_from_lena.jpg +0 -0
- data/lib/1.9/opencv.so +0 -0
- data/lib/2.0/opencv.so +0 -0
- data/lib/opencv.rb +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +3 -0
- data/ruby-opencv.gemspec +44 -0
- data/test/helper.rb +166 -0
- data/test/runner.rb +30 -0
- data/test/samples/airplane.jpg +0 -0
- data/test/samples/baboon.jpg +0 -0
- data/test/samples/baboon200.jpg +0 -0
- data/test/samples/baboon200_rotated.jpg +0 -0
- data/test/samples/blank0.jpg +0 -0
- data/test/samples/blank1.jpg +0 -0
- data/test/samples/blank2.jpg +0 -0
- data/test/samples/blank3.jpg +0 -0
- data/test/samples/blank4.jpg +0 -0
- data/test/samples/blank5.jpg +0 -0
- data/test/samples/blank6.jpg +0 -0
- data/test/samples/blank7.jpg +0 -0
- data/test/samples/blank8.jpg +0 -0
- data/test/samples/blank9.jpg +0 -0
- data/test/samples/cat.jpg +0 -0
- data/test/samples/chessboard.jpg +0 -0
- data/test/samples/contours.jpg +0 -0
- data/test/samples/fruits.jpg +0 -0
- data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
- data/test/samples/inpaint-mask.bmp +0 -0
- data/test/samples/lena-256x256.jpg +0 -0
- data/test/samples/lena-32x32.jpg +0 -0
- data/test/samples/lena-eyes.jpg +0 -0
- data/test/samples/lena-inpaint.jpg +0 -0
- data/test/samples/lena.jpg +0 -0
- data/test/samples/lines.jpg +0 -0
- data/test/samples/messy0.jpg +0 -0
- data/test/samples/messy1.jpg +0 -0
- data/test/samples/movie_sample.avi +0 -0
- data/test/samples/one_way_train_0000.jpg +0 -0
- data/test/samples/one_way_train_0001.jpg +0 -0
- data/test/samples/partially_blank0.jpg +0 -0
- data/test/samples/partially_blank1.jpg +0 -0
- data/test/samples/smooth0.jpg +0 -0
- data/test/samples/smooth1.jpg +0 -0
- data/test/samples/smooth2.jpg +0 -0
- data/test/samples/smooth3.jpg +0 -0
- data/test/samples/smooth4.jpg +0 -0
- data/test/samples/smooth5.jpg +0 -0
- data/test/samples/smooth6.jpg +0 -0
- data/test/samples/str-cv-rotated.jpg +0 -0
- data/test/samples/str-cv.jpg +0 -0
- data/test/samples/str-ov.jpg +0 -0
- data/test/samples/stuff.jpg +0 -0
- data/test/test_curve.rb +43 -0
- data/test/test_cvavgcomp.rb +24 -0
- data/test/test_cvbox2d.rb +76 -0
- data/test/test_cvcapture.rb +183 -0
- data/test/test_cvchain.rb +108 -0
- data/test/test_cvcircle32f.rb +41 -0
- data/test/test_cvconnectedcomp.rb +61 -0
- data/test/test_cvcontour.rb +150 -0
- data/test/test_cvcontourtree.rb +43 -0
- data/test/test_cverror.rb +50 -0
- data/test/test_cvfeaturetree.rb +65 -0
- data/test/test_cvfont.rb +58 -0
- data/test/test_cvhaarclassifiercascade.rb +63 -0
- data/test/test_cvhistogram.rb +271 -0
- data/test/test_cvhumoments.rb +83 -0
- data/test/test_cvline.rb +50 -0
- data/test/test_cvmat.rb +2947 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2015 -0
- data/test/test_cvmat_matching.rb +57 -0
- data/test/test_cvmoments.rb +180 -0
- data/test/test_cvpoint.rb +75 -0
- data/test/test_cvpoint2d32f.rb +75 -0
- data/test/test_cvpoint3d32f.rb +93 -0
- data/test/test_cvrect.rb +144 -0
- data/test/test_cvscalar.rb +113 -0
- data/test/test_cvseq.rb +295 -0
- data/test/test_cvsize.rb +75 -0
- data/test/test_cvsize2d32f.rb +75 -0
- data/test/test_cvslice.rb +31 -0
- data/test/test_cvsurfparams.rb +57 -0
- data/test/test_cvsurfpoint.rb +66 -0
- data/test/test_cvtermcriteria.rb +56 -0
- data/test/test_cvtwopoints.rb +40 -0
- data/test/test_cvvideowriter.rb +58 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +236 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +329 -0
- data/test/test_pointset.rb +126 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- metadata +386 -0
data/ext/opencv/cvseq.h
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvseq.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVSEQ_H
|
11
|
+
#define RUBY_OPENCV_CVSEQ_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVSEQ namespace cCvSeq {
|
16
|
+
#define __NAMESPACE_END_CVSEQ }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVSEQ
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
void define_ruby_class();
|
23
|
+
|
24
|
+
VALUE seqblock_class(void *ptr);
|
25
|
+
void register_elem_class(CvSeq *seq, VALUE klass);
|
26
|
+
void unregister_elem_class(void *ptr);
|
27
|
+
|
28
|
+
VALUE rb_allocate(VALUE klass);
|
29
|
+
|
30
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
31
|
+
VALUE rb_total(VALUE self);
|
32
|
+
VALUE rb_empty_q(VALUE self);
|
33
|
+
VALUE rb_aref(VALUE self, VALUE index);
|
34
|
+
VALUE rb_first(VALUE self);
|
35
|
+
VALUE rb_last(VALUE self);
|
36
|
+
VALUE rb_h_prev(VALUE self);
|
37
|
+
VALUE rb_h_next(VALUE self);
|
38
|
+
VALUE rb_v_prev(VALUE self);
|
39
|
+
VALUE rb_v_next(VALUE self);
|
40
|
+
VALUE rb_push(VALUE self, VALUE args);
|
41
|
+
VALUE rb_pop(VALUE self);
|
42
|
+
VALUE rb_unshift(VALUE self, VALUE args);
|
43
|
+
VALUE rb_shift(VALUE self);
|
44
|
+
VALUE rb_each(VALUE self);
|
45
|
+
VALUE rb_each_index(VALUE self);
|
46
|
+
VALUE rb_insert(VALUE self, VALUE index, VALUE object);
|
47
|
+
VALUE rb_remove(VALUE self, VALUE index);
|
48
|
+
VALUE rb_clear(VALUE self);
|
49
|
+
|
50
|
+
VALUE new_object(CvSeq *seq, VALUE klass);
|
51
|
+
VALUE new_object(CvSeq *seq, VALUE klass, VALUE storage);
|
52
|
+
VALUE new_sequence(VALUE klass, CvSeq *seq, VALUE element_klass, VALUE storage);
|
53
|
+
|
54
|
+
__NAMESPACE_END_CVSEQ
|
55
|
+
|
56
|
+
inline CvSeq*
|
57
|
+
CVSEQ(VALUE object)
|
58
|
+
{
|
59
|
+
CvSeq *ptr;
|
60
|
+
Data_Get_Struct(object, CvSeq, ptr);
|
61
|
+
return ptr;
|
62
|
+
}
|
63
|
+
|
64
|
+
inline CvSeq*
|
65
|
+
CVSEQ_WITH_CHECK(VALUE object)
|
66
|
+
{
|
67
|
+
if (!rb_obj_is_kind_of(object, cCvSeq::rb_class()))
|
68
|
+
raise_typeerror(object, cCvSeq::rb_class());
|
69
|
+
return CVSEQ(object);
|
70
|
+
}
|
71
|
+
|
72
|
+
__NAMESPACE_END_OPENCV
|
73
|
+
|
74
|
+
#endif // RUBY_OPENCV_CVSEQ_H
|
@@ -0,0 +1,221 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvsize.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvsize.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvSize
|
13
|
+
*
|
14
|
+
* This class means one size on X axis Y axis.
|
15
|
+
* X and Y takes the value of the Fixnum.
|
16
|
+
*
|
17
|
+
* C structure is here, very simple.
|
18
|
+
* typdef struct CvSize {
|
19
|
+
* int width;
|
20
|
+
* int height;
|
21
|
+
* }
|
22
|
+
*/
|
23
|
+
__NAMESPACE_BEGIN_OPENCV
|
24
|
+
__NAMESPACE_BEGIN_CVSIZE
|
25
|
+
|
26
|
+
VALUE rb_klass;
|
27
|
+
|
28
|
+
VALUE
|
29
|
+
rb_class()
|
30
|
+
{
|
31
|
+
return rb_klass;
|
32
|
+
}
|
33
|
+
|
34
|
+
void
|
35
|
+
define_ruby_class()
|
36
|
+
{
|
37
|
+
if (rb_klass)
|
38
|
+
return;
|
39
|
+
/*
|
40
|
+
* opencv = rb_define_module("OpenCV");
|
41
|
+
*
|
42
|
+
* note: this comment is used by rdoc.
|
43
|
+
*/
|
44
|
+
VALUE opencv = rb_module_opencv();
|
45
|
+
|
46
|
+
rb_klass = rb_define_class_under(opencv, "CvSize", rb_cObject);
|
47
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
48
|
+
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
49
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
50
|
+
rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
|
51
|
+
rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
|
52
|
+
rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
|
53
|
+
rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
|
54
|
+
|
55
|
+
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
56
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
57
|
+
rb_define_alias(rb_klass, "to_a", "to_ary");
|
58
|
+
}
|
59
|
+
|
60
|
+
/*
|
61
|
+
* call-seq:
|
62
|
+
* compatible?(obj)
|
63
|
+
*
|
64
|
+
* Return compatibility to CvSize. Return true if object have method #width and #height.
|
65
|
+
*
|
66
|
+
* For example.
|
67
|
+
* class MySize
|
68
|
+
* def width
|
69
|
+
* 10
|
70
|
+
* end
|
71
|
+
* def height
|
72
|
+
* 20
|
73
|
+
* end
|
74
|
+
* end
|
75
|
+
* mp = MySize.new
|
76
|
+
* CvSize.compatible?(mp) #=> true
|
77
|
+
* CvSize.new(mp) #=> same as CvSize(10, 20)
|
78
|
+
*/
|
79
|
+
VALUE
|
80
|
+
rb_compatible_q(VALUE klass, VALUE object)
|
81
|
+
{
|
82
|
+
return (rb_respond_to(object, rb_intern("width")) && rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
83
|
+
}
|
84
|
+
|
85
|
+
VALUE
|
86
|
+
rb_allocate(VALUE klass)
|
87
|
+
{
|
88
|
+
CvSize *ptr;
|
89
|
+
return Data_Make_Struct(klass, CvSize, 0, -1, ptr);
|
90
|
+
}
|
91
|
+
|
92
|
+
/*
|
93
|
+
* call-seq:
|
94
|
+
* new
|
95
|
+
* new(obj)
|
96
|
+
* new(width, height)
|
97
|
+
*
|
98
|
+
* Create new size of 2D, (width, height). It is dropped below the decimal point.
|
99
|
+
*
|
100
|
+
* new() is same as new(0, 0)
|
101
|
+
*
|
102
|
+
* new(obj) is same as new(obj.x.to_i, obj.y.to_i)
|
103
|
+
*/
|
104
|
+
VALUE
|
105
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
106
|
+
{
|
107
|
+
CvSize *self_ptr = CVSIZE(self);
|
108
|
+
switch (argc) {
|
109
|
+
case 0:
|
110
|
+
break;
|
111
|
+
case 1: {
|
112
|
+
CvSize size = VALUE_TO_CVSIZE(argv[0]);
|
113
|
+
self_ptr->width = size.width;
|
114
|
+
self_ptr->height = size.height;
|
115
|
+
break;
|
116
|
+
}
|
117
|
+
case 2:
|
118
|
+
self_ptr->width = NUM2INT(argv[0]);
|
119
|
+
self_ptr->height = NUM2INT(argv[1]);
|
120
|
+
break;
|
121
|
+
default:
|
122
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
123
|
+
break;
|
124
|
+
}
|
125
|
+
return self;
|
126
|
+
}
|
127
|
+
|
128
|
+
/*
|
129
|
+
* Return size of x-axis.
|
130
|
+
*/
|
131
|
+
VALUE
|
132
|
+
rb_width(VALUE self)
|
133
|
+
{
|
134
|
+
return INT2NUM(CVSIZE(self)->width);
|
135
|
+
}
|
136
|
+
|
137
|
+
/*
|
138
|
+
* call-seq:
|
139
|
+
* width = val
|
140
|
+
*
|
141
|
+
* Set x-axis size, return self.
|
142
|
+
* It is dropped below the decimal point.
|
143
|
+
*/
|
144
|
+
VALUE
|
145
|
+
rb_set_width(VALUE self, VALUE x)
|
146
|
+
{
|
147
|
+
CVSIZE(self)->width = NUM2INT(x);
|
148
|
+
return self;
|
149
|
+
}
|
150
|
+
|
151
|
+
/*
|
152
|
+
* Return size of yaxis.
|
153
|
+
*/
|
154
|
+
VALUE
|
155
|
+
rb_height(VALUE self)
|
156
|
+
{
|
157
|
+
return INT2NUM(CVSIZE(self)->height);
|
158
|
+
}
|
159
|
+
|
160
|
+
/*
|
161
|
+
* call-seq:
|
162
|
+
* height = val
|
163
|
+
*
|
164
|
+
* Set y-axis size, return self.
|
165
|
+
* It is dropped below the decimal point.
|
166
|
+
*/
|
167
|
+
VALUE
|
168
|
+
rb_set_height(VALUE self, VALUE y)
|
169
|
+
{
|
170
|
+
CVSIZE(self)->height = NUM2INT(y);
|
171
|
+
return self;
|
172
|
+
}
|
173
|
+
|
174
|
+
/*
|
175
|
+
* call-seq:
|
176
|
+
* to_s -> "<OpenCV::CvSize:widthxheight>"
|
177
|
+
*
|
178
|
+
* Return width and height by String.
|
179
|
+
*/
|
180
|
+
VALUE
|
181
|
+
rb_to_s(VALUE self)
|
182
|
+
{
|
183
|
+
const int i = 4;
|
184
|
+
VALUE str[i];
|
185
|
+
str[0] = rb_str_new2("<%s:%dx%d>");
|
186
|
+
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
187
|
+
str[2] = rb_width(self);
|
188
|
+
str[3] = rb_height(self);
|
189
|
+
return rb_f_sprintf(i, str);
|
190
|
+
}
|
191
|
+
|
192
|
+
/*
|
193
|
+
* call-seq:
|
194
|
+
* to_ary -> [width, height]
|
195
|
+
*
|
196
|
+
* Return width and height by Array.
|
197
|
+
*/
|
198
|
+
VALUE
|
199
|
+
rb_to_ary(VALUE self)
|
200
|
+
{
|
201
|
+
return rb_ary_new3(2, rb_width(self), rb_height(self));
|
202
|
+
}
|
203
|
+
|
204
|
+
VALUE
|
205
|
+
new_object()
|
206
|
+
{
|
207
|
+
VALUE object = rb_allocate(rb_klass);
|
208
|
+
*CVSIZE(object) = cvSize(0, 0);
|
209
|
+
return object;
|
210
|
+
}
|
211
|
+
|
212
|
+
VALUE
|
213
|
+
new_object(CvSize size)
|
214
|
+
{
|
215
|
+
VALUE object = rb_allocate(rb_klass);
|
216
|
+
*CVSIZE(object) = size;
|
217
|
+
return object;
|
218
|
+
}
|
219
|
+
|
220
|
+
__NAMESPACE_END_CVSIZE
|
221
|
+
__NAMESPACE_END_OPENCV
|
data/ext/opencv/cvsize.h
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvsize.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVSIZE_H
|
11
|
+
#define RUBY_OPENCV_CVSIZE_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVSIZE namespace cCvSize {
|
16
|
+
#define __NAMESPACE_END_CVSIZE }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVSIZE
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void define_ruby_class();
|
24
|
+
|
25
|
+
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
26
|
+
|
27
|
+
VALUE rb_allocate(VALUE klass);
|
28
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
29
|
+
VALUE rb_width(VALUE self);
|
30
|
+
VALUE rb_set_width(VALUE self, VALUE width);
|
31
|
+
VALUE rb_height(VALUE self);
|
32
|
+
VALUE rb_set_height(VALUE self, VALUE height);
|
33
|
+
|
34
|
+
VALUE rb_to_s(VALUE self);
|
35
|
+
VALUE rb_to_ary(VALUE self);
|
36
|
+
|
37
|
+
VALUE new_object();
|
38
|
+
VALUE new_object(CvSize size);
|
39
|
+
|
40
|
+
__NAMESPACE_END_CVSIZE
|
41
|
+
|
42
|
+
inline CvSize*
|
43
|
+
CVSIZE(VALUE object)
|
44
|
+
{
|
45
|
+
CvSize *ptr;
|
46
|
+
Data_Get_Struct(object, CvSize, ptr);
|
47
|
+
return ptr;
|
48
|
+
}
|
49
|
+
|
50
|
+
inline CvSize
|
51
|
+
VALUE_TO_CVSIZE(VALUE object)
|
52
|
+
{
|
53
|
+
if (cCvSize::rb_compatible_q(cCvSize::rb_class(), object)) {
|
54
|
+
return cvSize(NUM2INT(rb_funcall(object, rb_intern("width"), 0)),
|
55
|
+
NUM2INT(rb_funcall(object, rb_intern("height"), 0)));
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
raise_compatible_typeerror(object, cCvSize::rb_class());
|
59
|
+
}
|
60
|
+
throw "Should never reach here";
|
61
|
+
}
|
62
|
+
|
63
|
+
__NAMESPACE_END_OPENCV
|
64
|
+
|
65
|
+
#endif // RUBY_OPENCV_CVSIZE_H
|
@@ -0,0 +1,209 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvsize2d32f.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvsize2d32f.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvSize2D32f
|
13
|
+
*
|
14
|
+
* This class means one size on X axis Y axis.
|
15
|
+
* X and Y takes the value of the Float.
|
16
|
+
*
|
17
|
+
* C structure is here, very simple.
|
18
|
+
* typdef struct CvSize2D32f {
|
19
|
+
* float width;
|
20
|
+
* float height;
|
21
|
+
* } CvSize2D32f;
|
22
|
+
*/
|
23
|
+
__NAMESPACE_BEGIN_OPENCV
|
24
|
+
__NAMESPACE_BEGIN_CVSIZE2D32F
|
25
|
+
|
26
|
+
VALUE rb_klass;
|
27
|
+
|
28
|
+
VALUE
|
29
|
+
rb_class()
|
30
|
+
{
|
31
|
+
return rb_klass;
|
32
|
+
}
|
33
|
+
|
34
|
+
void
|
35
|
+
define_ruby_class()
|
36
|
+
{
|
37
|
+
if (rb_klass)
|
38
|
+
return;
|
39
|
+
/*
|
40
|
+
* opencv = rb_define_module("OpenCV");
|
41
|
+
*
|
42
|
+
* note: this comment is used by rdoc.
|
43
|
+
*/
|
44
|
+
VALUE opencv = rb_module_opencv();
|
45
|
+
|
46
|
+
rb_klass = rb_define_class_under(opencv, "CvSize2D32f", rb_cObject);
|
47
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
48
|
+
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
49
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
50
|
+
rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
|
51
|
+
rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
|
52
|
+
rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
|
53
|
+
rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
|
54
|
+
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
55
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
56
|
+
rb_define_alias(rb_klass, "to_a", "to_ary");
|
57
|
+
}
|
58
|
+
|
59
|
+
/*
|
60
|
+
* call-seq:
|
61
|
+
* compatible?(obj)
|
62
|
+
*
|
63
|
+
* Return compatibility to CvSize2D32f. Return true if object have method #width and #height.
|
64
|
+
*
|
65
|
+
* For example.
|
66
|
+
* class MySize
|
67
|
+
* def width
|
68
|
+
* 10.1
|
69
|
+
* end
|
70
|
+
* def height
|
71
|
+
* 20.2
|
72
|
+
* end
|
73
|
+
* end
|
74
|
+
* mp = MySize.new
|
75
|
+
* CvSize2D32f.compatible?(mp) #=> true
|
76
|
+
* CvSize2D32f.new(mp) #=> same as CvSize2D32f.new(10.1, 20.2)
|
77
|
+
*/
|
78
|
+
VALUE
|
79
|
+
rb_compatible_q(VALUE klass, VALUE object)
|
80
|
+
{
|
81
|
+
return (rb_respond_to(object, rb_intern("width")) && rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
82
|
+
}
|
83
|
+
|
84
|
+
VALUE
|
85
|
+
rb_allocate(VALUE klass)
|
86
|
+
{
|
87
|
+
CvSize2D32f *ptr;
|
88
|
+
return Data_Make_Struct(klass, CvSize2D32f, 0, -1, ptr);
|
89
|
+
}
|
90
|
+
|
91
|
+
/*
|
92
|
+
* call-seq:
|
93
|
+
* new
|
94
|
+
* new(obj)
|
95
|
+
* new(width, height)
|
96
|
+
*
|
97
|
+
* Create new size of 2D, (width, height).
|
98
|
+
*
|
99
|
+
* new() is same as new(0.0, 0.0)
|
100
|
+
*
|
101
|
+
* new(obj) is same as new(obj.x.to_f, obj.y.to_f)
|
102
|
+
*/
|
103
|
+
VALUE
|
104
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
105
|
+
{
|
106
|
+
CvSize2D32f *self_ptr = CVSIZE2D32F(self);
|
107
|
+
switch(argc){
|
108
|
+
case 0:
|
109
|
+
break;
|
110
|
+
case 1: {
|
111
|
+
CvSize2D32f size = VALUE_TO_CVSIZE2D32F(argv[0]);
|
112
|
+
self_ptr->width = size.width;
|
113
|
+
self_ptr->height = size.height;
|
114
|
+
break;
|
115
|
+
}
|
116
|
+
case 2:
|
117
|
+
self_ptr->width = NUM2DBL(argv[0]);
|
118
|
+
self_ptr->height = NUM2DBL(argv[1]);
|
119
|
+
break;
|
120
|
+
default:
|
121
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
122
|
+
}
|
123
|
+
return self;
|
124
|
+
}
|
125
|
+
|
126
|
+
/*
|
127
|
+
* Return size of x-axis.
|
128
|
+
*/
|
129
|
+
VALUE
|
130
|
+
rb_width(VALUE self)
|
131
|
+
{
|
132
|
+
return rb_float_new(CVSIZE2D32F(self)->width);
|
133
|
+
}
|
134
|
+
|
135
|
+
/*
|
136
|
+
* call-seq:
|
137
|
+
* width = val
|
138
|
+
*
|
139
|
+
* Set x-axis size, return self.
|
140
|
+
*/
|
141
|
+
VALUE
|
142
|
+
rb_set_width(VALUE self, VALUE x)
|
143
|
+
{
|
144
|
+
CVSIZE2D32F(self)->width = NUM2DBL(x);
|
145
|
+
return self;
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* Return size of yaxis.
|
150
|
+
*/
|
151
|
+
VALUE
|
152
|
+
rb_height(VALUE self)
|
153
|
+
{
|
154
|
+
return rb_float_new(CVSIZE2D32F(self)->height);
|
155
|
+
}
|
156
|
+
|
157
|
+
/*
|
158
|
+
* call-seq:
|
159
|
+
* height = val
|
160
|
+
*
|
161
|
+
* Set y-axis size, return self.
|
162
|
+
*/
|
163
|
+
VALUE
|
164
|
+
rb_set_height(VALUE self, VALUE y)
|
165
|
+
{
|
166
|
+
CVSIZE2D32F(self)->height = NUM2DBL(y);
|
167
|
+
return self;
|
168
|
+
}
|
169
|
+
|
170
|
+
/*
|
171
|
+
* call-seq:
|
172
|
+
* to_s -> "<OpenCV::CvSize2D32f:widthxheight>"
|
173
|
+
*
|
174
|
+
* Return width and height by String.
|
175
|
+
*/
|
176
|
+
VALUE
|
177
|
+
rb_to_s(VALUE self)
|
178
|
+
{
|
179
|
+
const int i = 4;
|
180
|
+
VALUE str[i];
|
181
|
+
str[0] = rb_str_new2("<%s:%gx%g>");
|
182
|
+
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
183
|
+
str[2] = rb_width(self);
|
184
|
+
str[3] = rb_height(self);
|
185
|
+
return rb_f_sprintf(i, str);
|
186
|
+
}
|
187
|
+
|
188
|
+
/*
|
189
|
+
* call-seq:
|
190
|
+
* to_ary -> [width, height]
|
191
|
+
*
|
192
|
+
* Return width and height by Array.
|
193
|
+
*/
|
194
|
+
VALUE
|
195
|
+
rb_to_ary(VALUE self)
|
196
|
+
{
|
197
|
+
return rb_ary_new3(2, rb_width(self), rb_height(self));
|
198
|
+
}
|
199
|
+
|
200
|
+
VALUE
|
201
|
+
new_object(CvSize2D32f size)
|
202
|
+
{
|
203
|
+
VALUE object = rb_allocate(rb_klass);
|
204
|
+
*CVSIZE2D32F(object) = size;
|
205
|
+
return object;
|
206
|
+
}
|
207
|
+
|
208
|
+
__NAMESPACE_END_CVSIZE2D32F
|
209
|
+
__NAMESPACE_END_OPENCV
|