bonanza-ruby-opencv 0.0.13.20140330211753
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.yardopts +3 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +9 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +239 -0
- data/README.md +98 -0
- data/Rakefile +99 -0
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -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/facerec/create_csv.rb +43 -0
- data/examples/facerec/facerec_eigenfaces.rb +132 -0
- data/examples/facerec/facerec_fisherfaces.rb +131 -0
- data/examples/facerec/facerec_lbph.rb +116 -0
- data/examples/facerec/readme.md +111 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/images/box.png +0 -0
- data/examples/images/box_in_scene.png +0 -0
- data/examples/images/inpaint.png +0 -0
- data/examples/images/lena-256x256.jpg +0 -0
- data/examples/images/lena-eyes.jpg +0 -0
- data/examples/images/lenna-rotated.jpg +0 -0
- data/examples/images/lenna.jpg +0 -0
- data/examples/images/stuff.jpg +0 -0
- data/examples/images/tiffany.jpg +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/match_template.rb +26 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/ext/opencv/algorithm.cpp +291 -0
- data/ext/opencv/algorithm.h +38 -0
- data/ext/opencv/curve.cpp +127 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +64 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +195 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +607 -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 +126 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvconnectedcomp.cpp +156 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +332 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +96 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +92 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +115 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +123 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +228 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +148 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +715 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +178 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +159 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +6829 -0
- data/ext/opencv/cvmat.h +323 -0
- data/ext/opencv/cvmemstorage.cpp +73 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +293 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +265 -0
- data/ext/opencv/cvpoint.h +67 -0
- data/ext/opencv/cvpoint2d32f.cpp +216 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +252 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +441 -0
- data/ext/opencv/cvrect.h +88 -0
- data/ext/opencv/cvscalar.cpp +301 -0
- data/ext/opencv/cvscalar.h +76 -0
- data/ext/opencv/cvseq.cpp +605 -0
- data/ext/opencv/cvseq.h +74 -0
- data/ext/opencv/cvsize.cpp +227 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +215 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +126 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsurfparams.cpp +208 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +279 -0
- data/ext/opencv/cvsurfpoint.h +54 -0
- data/ext/opencv/cvtermcriteria.cpp +198 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +122 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +221 -0
- data/ext/opencv/cvutils.h +31 -0
- data/ext/opencv/cvvideowriter.cpp +142 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/eigenfaces.cpp +75 -0
- data/ext/opencv/eigenfaces.h +30 -0
- data/ext/opencv/extconf.rb +82 -0
- data/ext/opencv/facerecognizer.cpp +181 -0
- data/ext/opencv/facerecognizer.h +46 -0
- data/ext/opencv/fisherfaces.cpp +75 -0
- data/ext/opencv/fisherfaces.h +30 -0
- data/ext/opencv/gui.cpp +71 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +198 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +666 -0
- data/ext/opencv/iplimage.h +75 -0
- data/ext/opencv/lbph.cpp +78 -0
- data/ext/opencv/lbph.h +30 -0
- data/ext/opencv/mouseevent.cpp +186 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +833 -0
- data/ext/opencv/opencv.h +405 -0
- data/ext/opencv/pointset.cpp +280 -0
- data/ext/opencv/pointset.h +68 -0
- data/ext/opencv/trackbar.cpp +127 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +377 -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/lib/opencv.rb +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +4 -0
- data/test/eigenfaces_save.xml +7524 -0
- data/test/fisherfaces_save.xml +7530 -0
- data/test/helper.rb +166 -0
- data/test/lbph_save.xml +4304 -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 +3003 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2085 -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_eigenfaces.rb +93 -0
- data/test/test_fisherfaces.rb +93 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +232 -0
- data/test/test_lbph.rb +152 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +360 -0
- data/test/test_pointset.rb +128 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- data/yard_extension.rb +5 -0
- metadata +399 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvpoint3d32f.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2008 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVPOINT3D32F_H
|
11
|
+
#define RUBY_OPENCV_CVPOINT3D32F_H
|
12
|
+
|
13
|
+
#define __NAMESPACE_BEGIN_CVPOINT3D32F namespace cCvPoint3D32f {
|
14
|
+
#define __NAMESPACE_END_CVPOINT3D32F }
|
15
|
+
|
16
|
+
#include "opencv.h"
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVPOINT3D32F
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void init_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_x(VALUE self);
|
30
|
+
VALUE rb_set_x(VALUE self, VALUE x);
|
31
|
+
VALUE rb_y(VALUE self);
|
32
|
+
VALUE rb_set_y(VALUE self, VALUE y);
|
33
|
+
VALUE rb_z(VALUE self);
|
34
|
+
VALUE rb_set_z(VALUE self, VALUE z);
|
35
|
+
|
36
|
+
VALUE rb_to_s(VALUE self);
|
37
|
+
VALUE rb_to_ary(VALUE self);
|
38
|
+
|
39
|
+
VALUE new_object(CvPoint3D32f point);
|
40
|
+
|
41
|
+
__NAMESPACE_END_CVPOINT3D32F
|
42
|
+
|
43
|
+
inline CvPoint3D32f*
|
44
|
+
CVPOINT3D32F(VALUE object)
|
45
|
+
{
|
46
|
+
CvPoint3D32f *ptr;
|
47
|
+
Data_Get_Struct(object, CvPoint3D32f, ptr);
|
48
|
+
return ptr;
|
49
|
+
}
|
50
|
+
|
51
|
+
inline CvPoint3D32f
|
52
|
+
VALUE_TO_CVPOINT3D32F(VALUE object)
|
53
|
+
{
|
54
|
+
if (cCvPoint3D32f::rb_compatible_q(cCvPoint3D32f::rb_class(), object)) {
|
55
|
+
return cvPoint3D32f(NUM2DBL(rb_funcall(object, rb_intern("x"), 0)),
|
56
|
+
NUM2DBL(rb_funcall(object, rb_intern("y"), 0)),
|
57
|
+
NUM2DBL(rb_funcall(object, rb_intern("z"), 0)));
|
58
|
+
}
|
59
|
+
else {
|
60
|
+
raise_compatible_typeerror(object, cCvPoint3D32f::rb_class());
|
61
|
+
}
|
62
|
+
throw "Should never reach here";
|
63
|
+
}
|
64
|
+
|
65
|
+
__NAMESPACE_END_OPENCV
|
66
|
+
#endif // RUBY_OPENCV_CVPOINT3D32F_H
|
@@ -0,0 +1,441 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvrect.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvrect.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvRect
|
13
|
+
*
|
14
|
+
* This class have coordinate of top-left point(x, y) and size, width and height.
|
15
|
+
*
|
16
|
+
*
|
17
|
+
* C stracture is here, very simple.
|
18
|
+
* typdef struct CvRect {
|
19
|
+
* int x;
|
20
|
+
* int y;
|
21
|
+
* int width;
|
22
|
+
* int height;
|
23
|
+
* }
|
24
|
+
*
|
25
|
+
*/
|
26
|
+
__NAMESPACE_BEGIN_OPENCV
|
27
|
+
__NAMESPACE_BEGIN_CVRECT
|
28
|
+
|
29
|
+
VALUE rb_klass;
|
30
|
+
|
31
|
+
VALUE
|
32
|
+
rb_class()
|
33
|
+
{
|
34
|
+
return rb_klass;
|
35
|
+
}
|
36
|
+
|
37
|
+
/*
|
38
|
+
* call-seq:
|
39
|
+
* combatible?(obj)
|
40
|
+
*
|
41
|
+
* Return compatibility to CvRect. Return true if object have method #x and #y and #width and #height.
|
42
|
+
*
|
43
|
+
* For example.
|
44
|
+
* class MyRect
|
45
|
+
* def x
|
46
|
+
* 1
|
47
|
+
* end
|
48
|
+
* def y
|
49
|
+
* 2
|
50
|
+
* end
|
51
|
+
* def width
|
52
|
+
* 10
|
53
|
+
* end
|
54
|
+
* def height
|
55
|
+
* 20
|
56
|
+
* end
|
57
|
+
* end
|
58
|
+
* mr = MyRect.new
|
59
|
+
* CvRect.compatible?(mp) #=> true
|
60
|
+
* CvRect.new(mp) #=> same as CvRect(1, 2, 10, 20)
|
61
|
+
*/
|
62
|
+
VALUE
|
63
|
+
rb_compatible_q(VALUE klass, VALUE object)
|
64
|
+
{
|
65
|
+
return (rb_respond_to(object, rb_intern("x")) &&
|
66
|
+
rb_respond_to(object, rb_intern("y")) &&
|
67
|
+
rb_respond_to(object, rb_intern("width")) &&
|
68
|
+
rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* call-seq:
|
73
|
+
* max_rect(rect1, rect2) -> cvrect
|
74
|
+
*
|
75
|
+
* Finds bounding rectangle for given rectangles.
|
76
|
+
*/
|
77
|
+
VALUE
|
78
|
+
rb_max_rect(VALUE klass, VALUE rect1, VALUE rect2)
|
79
|
+
{
|
80
|
+
return cCvRect::new_object(cvMaxRect(CVRECT(rect1), CVRECT(rect2)));
|
81
|
+
}
|
82
|
+
|
83
|
+
VALUE
|
84
|
+
rb_allocate(VALUE klass)
|
85
|
+
{
|
86
|
+
CvRect *ptr;
|
87
|
+
return Data_Make_Struct(klass, CvRect, 0, -1, ptr);
|
88
|
+
}
|
89
|
+
|
90
|
+
/*
|
91
|
+
* call-seq:
|
92
|
+
* new -> CvRect.new(0, 0, 0, 0)
|
93
|
+
* new(obj) -> CvRect.new(obj.x.to_i, obj.y.to_i, obj.width.to_i, obj.height.to_i)
|
94
|
+
* new(x, y, width, height)
|
95
|
+
*
|
96
|
+
* Create new rectangle area. (x, y) is top-left point, and width, height is size of area.
|
97
|
+
* It is dropped below the decimal point.
|
98
|
+
*
|
99
|
+
* new() is same as new(0, 0, 0, 0)
|
100
|
+
*
|
101
|
+
* new(obj) is same as new(obj.x.to_i, obj.y.to_i, obj.width.to_i, obj.height.to_i)
|
102
|
+
*/
|
103
|
+
VALUE
|
104
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
105
|
+
{
|
106
|
+
CvRect *self_ptr = CVRECT(self);
|
107
|
+
switch (argc) {
|
108
|
+
case 0:
|
109
|
+
break;
|
110
|
+
case 1: {
|
111
|
+
CvRect rect = VALUE_TO_CVRECT(argv[0]);
|
112
|
+
self_ptr->x = rect.x;
|
113
|
+
self_ptr->y = rect.y;
|
114
|
+
self_ptr->width = rect.width;
|
115
|
+
self_ptr->height = rect.height;
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
case 4:
|
119
|
+
self_ptr->x = NUM2INT(argv[0]);
|
120
|
+
self_ptr->y = NUM2INT(argv[1]);
|
121
|
+
self_ptr->width = NUM2INT(argv[2]);
|
122
|
+
self_ptr->height = NUM2INT(argv[3]);
|
123
|
+
break;
|
124
|
+
default:
|
125
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
126
|
+
break;
|
127
|
+
}
|
128
|
+
return self;
|
129
|
+
}
|
130
|
+
|
131
|
+
/*
|
132
|
+
* call-seq:
|
133
|
+
* rb_check_equality(val)
|
134
|
+
*
|
135
|
+
* Return true if CvRect has same values as we do
|
136
|
+
*/
|
137
|
+
VALUE
|
138
|
+
rb_check_equality(VALUE self, VALUE compare_to) {
|
139
|
+
CvRect compare = VALUE_TO_CVRECT(compare_to);
|
140
|
+
CvRect* self_ptr = CVRECT(self);
|
141
|
+
|
142
|
+
return (self_ptr->x == compare.x && self_ptr->y == compare.y && self_ptr->width == compare.width && self_ptr->height == compare.height) ? Qtrue : Qfalse;
|
143
|
+
}
|
144
|
+
|
145
|
+
/*
|
146
|
+
* call-seq:
|
147
|
+
* rb_check_inequality(val)
|
148
|
+
*
|
149
|
+
* Return true if CvRect does not have same values as we do
|
150
|
+
*/
|
151
|
+
VALUE
|
152
|
+
rb_check_inequality(VALUE self, VALUE compare_to) {
|
153
|
+
CvRect compare = VALUE_TO_CVRECT(compare_to);
|
154
|
+
CvRect* self_ptr = CVRECT(self);
|
155
|
+
|
156
|
+
return (self_ptr->x != compare.x || self_ptr->y != compare.y || self_ptr->width != compare.width || self_ptr->height != compare.height) ? Qtrue : Qfalse;
|
157
|
+
}
|
158
|
+
|
159
|
+
VALUE
|
160
|
+
rb_hash(VALUE self) {
|
161
|
+
CvRect* self_ptr = CVRECT(self);
|
162
|
+
return INT2NUM(rb_memhash(self_ptr, sizeof(CvRect)));
|
163
|
+
}
|
164
|
+
|
165
|
+
/*
|
166
|
+
* call-seq:
|
167
|
+
* to_s -> "<OpenCV::CvRect:(self.x,self.y,self.widthxself.height)>"
|
168
|
+
*
|
169
|
+
* Return x, y, width, and height by String.
|
170
|
+
*/
|
171
|
+
VALUE
|
172
|
+
rb_to_s(VALUE self)
|
173
|
+
{
|
174
|
+
const int i = 6;
|
175
|
+
VALUE str[i];
|
176
|
+
str[0] = rb_str_new2("<%s:(%d,%d,%dx%d)>");
|
177
|
+
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
178
|
+
str[2] = rb_x(self);
|
179
|
+
str[3] = rb_y(self);
|
180
|
+
str[4] = rb_width(self);
|
181
|
+
str[5] = rb_height(self);
|
182
|
+
return rb_f_sprintf(i, str);
|
183
|
+
}
|
184
|
+
|
185
|
+
/*
|
186
|
+
* Return parameter on x-axis of top-left point.
|
187
|
+
*/
|
188
|
+
VALUE
|
189
|
+
rb_x(VALUE self)
|
190
|
+
{
|
191
|
+
return INT2NUM(CVRECT(self)->x);
|
192
|
+
}
|
193
|
+
|
194
|
+
/*
|
195
|
+
* call-seq:
|
196
|
+
* x = val
|
197
|
+
*
|
198
|
+
* Set x-axis parameter of top-left point, return self.
|
199
|
+
* It is dropped below the decimal point.
|
200
|
+
*/
|
201
|
+
VALUE
|
202
|
+
rb_set_x(VALUE self, VALUE x)
|
203
|
+
{
|
204
|
+
CVRECT(self)->x = NUM2INT(x);
|
205
|
+
return self;
|
206
|
+
}
|
207
|
+
|
208
|
+
/*
|
209
|
+
* Return parameter on y-axis of top-left point.
|
210
|
+
*/
|
211
|
+
VALUE
|
212
|
+
rb_y(VALUE self)
|
213
|
+
{
|
214
|
+
return INT2NUM(CVRECT(self)->y);
|
215
|
+
}
|
216
|
+
|
217
|
+
/*
|
218
|
+
* call-seq:
|
219
|
+
* y = val
|
220
|
+
*
|
221
|
+
* Set y-axis parameter of top-left point, return self.
|
222
|
+
* It is dropped below the decimal point.
|
223
|
+
*/
|
224
|
+
VALUE
|
225
|
+
rb_set_y(VALUE self, VALUE y)
|
226
|
+
{
|
227
|
+
CVRECT(self)->y = NUM2INT(y);
|
228
|
+
return self;
|
229
|
+
}
|
230
|
+
|
231
|
+
/*
|
232
|
+
* Return size of x-axis.
|
233
|
+
*/
|
234
|
+
VALUE
|
235
|
+
rb_width(VALUE self)
|
236
|
+
{
|
237
|
+
return INT2NUM(CVRECT(self)->width);
|
238
|
+
}
|
239
|
+
|
240
|
+
/*
|
241
|
+
* call-seq:
|
242
|
+
* width = val
|
243
|
+
*
|
244
|
+
* Set x-axis size, return self.
|
245
|
+
* It is dropped below the decimal point.
|
246
|
+
*/
|
247
|
+
VALUE
|
248
|
+
rb_set_width(VALUE self, VALUE x)
|
249
|
+
{
|
250
|
+
CVRECT(self)->width = NUM2INT(x);
|
251
|
+
return self;
|
252
|
+
}
|
253
|
+
|
254
|
+
/*
|
255
|
+
* Return size of y-axis.
|
256
|
+
*/
|
257
|
+
VALUE
|
258
|
+
rb_height(VALUE self)
|
259
|
+
{
|
260
|
+
return INT2NUM(CVRECT(self)->height);
|
261
|
+
}
|
262
|
+
|
263
|
+
/*
|
264
|
+
* call-seq:
|
265
|
+
* height = val
|
266
|
+
*
|
267
|
+
* Set y-axis size, return self.
|
268
|
+
* It is dropped below the decimal point.
|
269
|
+
*/
|
270
|
+
VALUE
|
271
|
+
rb_set_height(VALUE self, VALUE y)
|
272
|
+
{
|
273
|
+
CVRECT(self)->height = NUM2INT(y);
|
274
|
+
return self;
|
275
|
+
}
|
276
|
+
|
277
|
+
/*
|
278
|
+
* Return center point of rectangle.
|
279
|
+
*/
|
280
|
+
VALUE
|
281
|
+
rb_center(VALUE self)
|
282
|
+
{
|
283
|
+
CvRect *rect = CVRECT(self);
|
284
|
+
return cCvPoint2D32f::new_object(cvPoint2D32f((float)rect->x + (float)rect->width / 2.0,
|
285
|
+
(float)rect->y + (float)rect->height / 2.0));
|
286
|
+
}
|
287
|
+
|
288
|
+
/*
|
289
|
+
* Return 4 points (top-left, bottom-left, bottom-right, top-right)
|
290
|
+
*/
|
291
|
+
VALUE
|
292
|
+
rb_points(VALUE self)
|
293
|
+
{
|
294
|
+
CvRect *rect = CVRECT(self);
|
295
|
+
return rb_ary_new3(4,
|
296
|
+
cCvPoint::new_object(cvPoint(rect->x, rect->y)),
|
297
|
+
cCvPoint::new_object(cvPoint(rect->x, rect->y + rect->height)),
|
298
|
+
cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y + rect->height)),
|
299
|
+
cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y))
|
300
|
+
);
|
301
|
+
}
|
302
|
+
|
303
|
+
/*
|
304
|
+
* Return top-left point of rectangle.
|
305
|
+
*/
|
306
|
+
VALUE
|
307
|
+
rb_top_left(VALUE self)
|
308
|
+
{
|
309
|
+
CvRect* rect = CVRECT(self);
|
310
|
+
return cCvPoint::new_object(cvPoint(rect->x, rect->y));
|
311
|
+
}
|
312
|
+
|
313
|
+
/*
|
314
|
+
* Return top-right point of rectangle.
|
315
|
+
*/
|
316
|
+
VALUE
|
317
|
+
rb_top_right(VALUE self)
|
318
|
+
{
|
319
|
+
CvRect* rect = CVRECT(self);
|
320
|
+
return cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y));
|
321
|
+
}
|
322
|
+
|
323
|
+
/*
|
324
|
+
* Return bottom-left point of rectangle.
|
325
|
+
*/
|
326
|
+
VALUE
|
327
|
+
rb_bottom_left(VALUE self)
|
328
|
+
{
|
329
|
+
CvRect* rect = CVRECT(self);
|
330
|
+
return cCvPoint::new_object(cvPoint(rect->x,
|
331
|
+
rect->y + rect->height));
|
332
|
+
}
|
333
|
+
|
334
|
+
/*
|
335
|
+
* Return bottom-right point of rectangle.
|
336
|
+
*/
|
337
|
+
VALUE
|
338
|
+
rb_bottom_right(VALUE self)
|
339
|
+
{
|
340
|
+
CvRect* rect = CVRECT(self);
|
341
|
+
return cCvPoint::new_object(cvPoint(rect->x + rect->width,
|
342
|
+
rect->y + rect->height));
|
343
|
+
}
|
344
|
+
|
345
|
+
/*
|
346
|
+
* Return top-center point of rectangle.
|
347
|
+
*/
|
348
|
+
VALUE
|
349
|
+
rb_top_center(VALUE self)
|
350
|
+
{
|
351
|
+
CvRect* rect = CVRECT(self);
|
352
|
+
return cCvPoint::new_object(cvPoint(rect->x + rect->width / 2, rect->y));
|
353
|
+
}
|
354
|
+
|
355
|
+
/*
|
356
|
+
* Return bottom-center point of rectangle.
|
357
|
+
*/
|
358
|
+
VALUE
|
359
|
+
rb_bottom_center(VALUE self)
|
360
|
+
{
|
361
|
+
CvRect* rect = CVRECT(self);
|
362
|
+
return cCvPoint::new_object(cvPoint(rect->x + rect->width / 2, rect->y + rect->height));
|
363
|
+
}
|
364
|
+
|
365
|
+
/*
|
366
|
+
* Return center-right point of rectangle.
|
367
|
+
*/
|
368
|
+
VALUE
|
369
|
+
rb_center_right(VALUE self)
|
370
|
+
{
|
371
|
+
CvRect* rect = CVRECT(self);
|
372
|
+
return cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y + rect->height / 2));
|
373
|
+
}
|
374
|
+
|
375
|
+
/*
|
376
|
+
* Return center-left point of rectangle.
|
377
|
+
*/
|
378
|
+
VALUE
|
379
|
+
rb_center_left(VALUE self)
|
380
|
+
{
|
381
|
+
CvRect* rect = CVRECT(self);
|
382
|
+
return cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y));
|
383
|
+
}
|
384
|
+
|
385
|
+
VALUE
|
386
|
+
new_object(CvRect rect)
|
387
|
+
{
|
388
|
+
VALUE object = rb_allocate(rb_klass);
|
389
|
+
*CVRECT(object) = rect;
|
390
|
+
return object;
|
391
|
+
}
|
392
|
+
|
393
|
+
void
|
394
|
+
init_ruby_class()
|
395
|
+
{
|
396
|
+
#if 0
|
397
|
+
// For documentation using YARD
|
398
|
+
VALUE opencv = rb_define_module("OpenCV");
|
399
|
+
#endif
|
400
|
+
|
401
|
+
if (rb_klass)
|
402
|
+
return;
|
403
|
+
/*
|
404
|
+
* opencv = rb_define_module("OpenCV");
|
405
|
+
*
|
406
|
+
* note: this comment is used by rdoc.
|
407
|
+
*/
|
408
|
+
VALUE opencv = rb_module_opencv();
|
409
|
+
rb_klass = rb_define_class_under(opencv, "CvRect", rb_cObject);
|
410
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
411
|
+
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
412
|
+
rb_define_singleton_method(rb_klass, "max_rect", RUBY_METHOD_FUNC(rb_max_rect), 2);
|
413
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
414
|
+
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
415
|
+
rb_define_method(rb_klass, "==", RUBY_METHOD_FUNC(rb_check_equality), 1);
|
416
|
+
rb_define_method(rb_klass, "!=", RUBY_METHOD_FUNC(rb_check_inequality), 1);
|
417
|
+
rb_define_method(rb_klass, "eql?", RUBY_METHOD_FUNC(rb_check_equality), 1);
|
418
|
+
rb_define_method(rb_klass, "hash", RUBY_METHOD_FUNC(rb_hash), 0);
|
419
|
+
|
420
|
+
rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
|
421
|
+
rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
|
422
|
+
rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
|
423
|
+
rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
|
424
|
+
rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
|
425
|
+
rb_define_method(rb_klass, "width=", RUBY_METHOD_FUNC(rb_set_width), 1);
|
426
|
+
rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
|
427
|
+
rb_define_method(rb_klass, "height=", RUBY_METHOD_FUNC(rb_set_height), 1);
|
428
|
+
rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
|
429
|
+
rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
|
430
|
+
rb_define_method(rb_klass, "top_left", RUBY_METHOD_FUNC(rb_top_left), 0);
|
431
|
+
rb_define_method(rb_klass, "top_center", RUBY_METHOD_FUNC(rb_top_left), 0);
|
432
|
+
rb_define_method(rb_klass, "top_right", RUBY_METHOD_FUNC(rb_top_right), 0);
|
433
|
+
rb_define_method(rb_klass, "bottom_left", RUBY_METHOD_FUNC(rb_bottom_left), 0);
|
434
|
+
rb_define_method(rb_klass, "bottom_center", RUBY_METHOD_FUNC(rb_top_left), 0);
|
435
|
+
rb_define_method(rb_klass, "bottom_right", RUBY_METHOD_FUNC(rb_bottom_right), 0);
|
436
|
+
rb_define_method(rb_klass, "center_left", RUBY_METHOD_FUNC(rb_bottom_right), 0);
|
437
|
+
rb_define_method(rb_klass, "center_right", RUBY_METHOD_FUNC(rb_bottom_right), 0);
|
438
|
+
}
|
439
|
+
|
440
|
+
__NAMESPACE_END_CVRECT
|
441
|
+
__NAMESPACE_END_OPENCV
|