bonanza-ruby-opencv 0.0.13.20140330211753
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.
- 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,293 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvmoments.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvmoments.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvMoments
|
13
|
+
*
|
14
|
+
* moments
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_CVMOMENTS
|
18
|
+
|
19
|
+
#define DEFINE_CVMOMENTS_ACCESSOR(elem) \
|
20
|
+
rb_define_method(rb_klass, #elem, RUBY_METHOD_FUNC(rb_##elem), 0)
|
21
|
+
|
22
|
+
#define CVMOMENTS_ACCESSOR(elem) \
|
23
|
+
VALUE rb_##elem(VALUE self) { return DBL2NUM(CVMOMENTS(self)->elem); }
|
24
|
+
|
25
|
+
VALUE rb_klass;
|
26
|
+
|
27
|
+
VALUE
|
28
|
+
rb_class()
|
29
|
+
{
|
30
|
+
return rb_klass;
|
31
|
+
}
|
32
|
+
|
33
|
+
VALUE
|
34
|
+
rb_allocate(VALUE klass)
|
35
|
+
{
|
36
|
+
CvMoments *ptr;
|
37
|
+
return Data_Make_Struct(klass, CvMoments, 0, -1, ptr);
|
38
|
+
}
|
39
|
+
/*
|
40
|
+
* call-seq:
|
41
|
+
* CvMoments.new(src[,is_binary = nil])
|
42
|
+
*
|
43
|
+
* Calculates all moments up to third order of a polygon or rasterized shape.
|
44
|
+
* <i>src</i> should be CvMat or CvPolygon.
|
45
|
+
*
|
46
|
+
* If is_binary = true, all the zero pixel values are treated as zeroes, all the others are treated as 1's.
|
47
|
+
*/
|
48
|
+
VALUE
|
49
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
50
|
+
{
|
51
|
+
VALUE src, is_binary;
|
52
|
+
rb_scan_args(argc, argv, "02", &src, &is_binary);
|
53
|
+
if (!NIL_P(src)) {
|
54
|
+
if (rb_obj_is_kind_of(src, cCvMat::rb_class()) || rb_obj_is_kind_of(src, cCvSeq::rb_class())) {
|
55
|
+
try {
|
56
|
+
cvMoments(CVARR(src), CVMOMENTS(self), TRUE_OR_FALSE(is_binary, 0));
|
57
|
+
}
|
58
|
+
catch (cv::Exception& e) {
|
59
|
+
raise_cverror(e);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
else
|
63
|
+
rb_raise(rb_eTypeError, "argument 1 (src) should be %s or %s.",
|
64
|
+
rb_class2name(cCvMat::rb_class()), rb_class2name(cCvSeq::rb_class()));
|
65
|
+
}
|
66
|
+
return self;
|
67
|
+
}
|
68
|
+
|
69
|
+
CVMOMENTS_ACCESSOR(m00);
|
70
|
+
CVMOMENTS_ACCESSOR(m10);
|
71
|
+
CVMOMENTS_ACCESSOR(m01);
|
72
|
+
CVMOMENTS_ACCESSOR(m20);
|
73
|
+
CVMOMENTS_ACCESSOR(m11);
|
74
|
+
CVMOMENTS_ACCESSOR(m02);
|
75
|
+
CVMOMENTS_ACCESSOR(m30);
|
76
|
+
CVMOMENTS_ACCESSOR(m21);
|
77
|
+
CVMOMENTS_ACCESSOR(m12);
|
78
|
+
CVMOMENTS_ACCESSOR(m03);
|
79
|
+
|
80
|
+
CVMOMENTS_ACCESSOR(mu20);
|
81
|
+
CVMOMENTS_ACCESSOR(mu11);
|
82
|
+
CVMOMENTS_ACCESSOR(mu02);
|
83
|
+
CVMOMENTS_ACCESSOR(mu30);
|
84
|
+
CVMOMENTS_ACCESSOR(mu21);
|
85
|
+
CVMOMENTS_ACCESSOR(mu12);
|
86
|
+
CVMOMENTS_ACCESSOR(mu03);
|
87
|
+
|
88
|
+
CVMOMENTS_ACCESSOR(inv_sqrt_m00);
|
89
|
+
|
90
|
+
/*
|
91
|
+
* call-seq:
|
92
|
+
* spatial -> float
|
93
|
+
*
|
94
|
+
* Retrieves spatial moment.
|
95
|
+
*
|
96
|
+
* which in case of image moments is defined as:
|
97
|
+
* Mx_order,y_order=sumx,y(I(x,y)*xx_order*yy_order)
|
98
|
+
* where I(x,y) is the intensity of the pixel (x, y).
|
99
|
+
*/
|
100
|
+
VALUE
|
101
|
+
rb_spatial(VALUE self, VALUE x_order, VALUE y_order)
|
102
|
+
{
|
103
|
+
double result = 0;
|
104
|
+
try {
|
105
|
+
result = cvGetSpatialMoment(CVMOMENTS(self), NUM2INT(x_order), NUM2INT(y_order));
|
106
|
+
}
|
107
|
+
catch (cv::Exception& e) {
|
108
|
+
raise_cverror(e);
|
109
|
+
}
|
110
|
+
return rb_float_new(result);
|
111
|
+
}
|
112
|
+
|
113
|
+
/*
|
114
|
+
* call-seq:
|
115
|
+
* central -> float
|
116
|
+
*
|
117
|
+
* Retrieves central moment.
|
118
|
+
*
|
119
|
+
* which in case of image moments is defined as:
|
120
|
+
* μx_order,y_order=sumx,y(I(x,y)*(x-xc)x_order*(y-yc)y_order),
|
121
|
+
* where xc=M10/M00, yc=M01/M00 - coordinates of the gravity center
|
122
|
+
*/
|
123
|
+
VALUE
|
124
|
+
rb_central(VALUE self, VALUE x_order, VALUE y_order)
|
125
|
+
{
|
126
|
+
double result = 0;
|
127
|
+
try {
|
128
|
+
result = cvGetCentralMoment(CVMOMENTS(self), NUM2INT(x_order), NUM2INT(y_order));
|
129
|
+
}
|
130
|
+
catch (cv::Exception& e) {
|
131
|
+
raise_cverror(e);
|
132
|
+
}
|
133
|
+
return rb_float_new(result);
|
134
|
+
}
|
135
|
+
|
136
|
+
/*
|
137
|
+
* call-seq:
|
138
|
+
* normalized_central -> float
|
139
|
+
*
|
140
|
+
* Retrieves normalized central moment.
|
141
|
+
*
|
142
|
+
* ηx_order,y_order= μx_order,y_order/M00((y_order+x_order)/2+1)
|
143
|
+
*/
|
144
|
+
VALUE
|
145
|
+
rb_normalized_central(VALUE self, VALUE x_order, VALUE y_order)
|
146
|
+
{
|
147
|
+
double result = 0;
|
148
|
+
try {
|
149
|
+
result = cvGetNormalizedCentralMoment(CVMOMENTS(self), NUM2INT(x_order), NUM2INT(y_order));
|
150
|
+
}
|
151
|
+
catch (cv::Exception& e) {
|
152
|
+
raise_cverror(e);
|
153
|
+
}
|
154
|
+
return rb_float_new(result);
|
155
|
+
}
|
156
|
+
|
157
|
+
/*
|
158
|
+
* call-seq:
|
159
|
+
* hu -> cvhumoments
|
160
|
+
*
|
161
|
+
* Calculates seven Hu invariants.
|
162
|
+
*
|
163
|
+
* seven Hu invariants that are defined as:
|
164
|
+
* h1=η20+η02
|
165
|
+
* h2=(η20-η02)²+4η11²
|
166
|
+
* h3=(η30-3η12)²+ (3η21-η03)²
|
167
|
+
* h4=(η30+η12)²+ (η21+η03)²
|
168
|
+
* h5=(η30-3η12)(η30+η12)[(η30+η12)²-3(η21+η03)²]+(3η21-η03)(η21+η03)[3(η30+η12)²-(η21+η03)²]
|
169
|
+
* h6=(η20-η02)[(η30+η12)²- (η21+η03)²]+4η11(η30+η12)(η21+η03)
|
170
|
+
* h7=(3η21-η03)(η21+η03)[3(η30+η12)²-(η21+η03)²]-(η30-3η12)(η21+η03)[3(η30+η12)²-(η21+η03)²]
|
171
|
+
* where ηi,j are normalized central moments of 2-nd and 3-rd orders. The computed values are proved to be invariant to the image scaling, rotation, and reflection except the seventh one, whose sign is changed by reflection.
|
172
|
+
*/
|
173
|
+
VALUE
|
174
|
+
rb_hu(VALUE self)
|
175
|
+
{
|
176
|
+
return cCvHuMoments::new_object(CVMOMENTS(self));
|
177
|
+
}
|
178
|
+
|
179
|
+
/*
|
180
|
+
* call-seq:
|
181
|
+
* gravity_center -> cvpoint2d32f
|
182
|
+
*
|
183
|
+
* Return gravity center.
|
184
|
+
*/
|
185
|
+
VALUE
|
186
|
+
rb_gravity_center(VALUE self)
|
187
|
+
{
|
188
|
+
CvMoments *moments = CVMOMENTS(self);
|
189
|
+
CvPoint2D32f point;
|
190
|
+
double m00 = 0, m01 = 0, m10 = 0;
|
191
|
+
try {
|
192
|
+
m00 = cvGetSpatialMoment(moments, 0, 0);
|
193
|
+
m10 = cvGetSpatialMoment(moments, 1, 0);
|
194
|
+
m01 = cvGetSpatialMoment(moments, 0, 1);
|
195
|
+
point = cvPoint2D32f(m10 / m00, m01 / m00);
|
196
|
+
}
|
197
|
+
catch (cv::Exception& e) {
|
198
|
+
raise_cverror(e);
|
199
|
+
}
|
200
|
+
return cCvPoint2D32f::new_object(point);
|
201
|
+
}
|
202
|
+
|
203
|
+
/*
|
204
|
+
* call-seq:
|
205
|
+
* angle -> float
|
206
|
+
*
|
207
|
+
* Return angle.
|
208
|
+
*/
|
209
|
+
VALUE
|
210
|
+
rb_angle(VALUE self)
|
211
|
+
{
|
212
|
+
CvMoments *moments = CVMOMENTS(self);
|
213
|
+
double m11 = 0, m20 = 0, m02 = 0;
|
214
|
+
try {
|
215
|
+
m11 = cvGetCentralMoment(moments, 1, 1);
|
216
|
+
m20 = cvGetCentralMoment(moments, 2, 0);
|
217
|
+
m02 = cvGetCentralMoment(moments, 0, 2);
|
218
|
+
}
|
219
|
+
catch (cv::Exception& e) {
|
220
|
+
raise_cverror(e);
|
221
|
+
}
|
222
|
+
double mangle = 0.5 * atan(2 * m11 / (m20 - m02));
|
223
|
+
if (cvIsNaN(mangle) || cvIsInf(mangle))
|
224
|
+
return Qnil;
|
225
|
+
else
|
226
|
+
return rb_float_new(mangle);
|
227
|
+
}
|
228
|
+
|
229
|
+
VALUE
|
230
|
+
new_object(CvArr *arr, int is_binary = 0)
|
231
|
+
{
|
232
|
+
VALUE object = rb_allocate(rb_klass);
|
233
|
+
try {
|
234
|
+
cvMoments(arr, CVMOMENTS(object), is_binary);
|
235
|
+
}
|
236
|
+
catch (cv::Exception& e) {
|
237
|
+
raise_cverror(e);
|
238
|
+
}
|
239
|
+
return object;
|
240
|
+
}
|
241
|
+
|
242
|
+
void
|
243
|
+
init_ruby_class()
|
244
|
+
{
|
245
|
+
#if 0
|
246
|
+
// For documentation using YARD
|
247
|
+
VALUE opencv = rb_define_module("OpenCV");
|
248
|
+
#endif
|
249
|
+
|
250
|
+
if (rb_klass)
|
251
|
+
return;
|
252
|
+
/*
|
253
|
+
* opencv = rb_define_module("OpenCV");
|
254
|
+
*
|
255
|
+
* note: this comment is used by rdoc.
|
256
|
+
*/
|
257
|
+
VALUE opencv = rb_module_opencv();
|
258
|
+
|
259
|
+
rb_klass = rb_define_class_under(opencv, "CvMoments", rb_cObject);
|
260
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
261
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
262
|
+
rb_define_method(rb_klass, "spatial", RUBY_METHOD_FUNC(rb_spatial), 2);
|
263
|
+
rb_define_method(rb_klass, "central", RUBY_METHOD_FUNC(rb_central), 2);
|
264
|
+
rb_define_method(rb_klass, "normalized_central", RUBY_METHOD_FUNC(rb_normalized_central), 2);
|
265
|
+
rb_define_method(rb_klass, "hu", RUBY_METHOD_FUNC(rb_hu), 0);
|
266
|
+
rb_define_method(rb_klass, "gravity_center", RUBY_METHOD_FUNC(rb_gravity_center), 0);
|
267
|
+
rb_define_method(rb_klass, "angle", RUBY_METHOD_FUNC(rb_angle), 0);
|
268
|
+
|
269
|
+
DEFINE_CVMOMENTS_ACCESSOR(m00);
|
270
|
+
DEFINE_CVMOMENTS_ACCESSOR(m10);
|
271
|
+
DEFINE_CVMOMENTS_ACCESSOR(m01);
|
272
|
+
DEFINE_CVMOMENTS_ACCESSOR(m20);
|
273
|
+
DEFINE_CVMOMENTS_ACCESSOR(m11);
|
274
|
+
DEFINE_CVMOMENTS_ACCESSOR(m02);
|
275
|
+
DEFINE_CVMOMENTS_ACCESSOR(m30);
|
276
|
+
DEFINE_CVMOMENTS_ACCESSOR(m21);
|
277
|
+
DEFINE_CVMOMENTS_ACCESSOR(m12);
|
278
|
+
DEFINE_CVMOMENTS_ACCESSOR(m03);
|
279
|
+
|
280
|
+
DEFINE_CVMOMENTS_ACCESSOR(mu20);
|
281
|
+
DEFINE_CVMOMENTS_ACCESSOR(mu11);
|
282
|
+
DEFINE_CVMOMENTS_ACCESSOR(mu02);
|
283
|
+
DEFINE_CVMOMENTS_ACCESSOR(mu30);
|
284
|
+
DEFINE_CVMOMENTS_ACCESSOR(mu21);
|
285
|
+
DEFINE_CVMOMENTS_ACCESSOR(mu12);
|
286
|
+
DEFINE_CVMOMENTS_ACCESSOR(mu03);
|
287
|
+
|
288
|
+
DEFINE_CVMOMENTS_ACCESSOR(inv_sqrt_m00);
|
289
|
+
}
|
290
|
+
|
291
|
+
__NAMESPACE_END_CVMOMENTS
|
292
|
+
__NAMESPACE_END_OPENCV
|
293
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvmoments.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVMOMENTS_H
|
11
|
+
#define RUBY_OPENCV_CVMOMENTS_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVMOMENTS namespace cCvMoments {
|
16
|
+
#define __NAMESPACE_END_CVMOMENTS }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVMOMENTS
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void init_ruby_class();
|
24
|
+
|
25
|
+
VALUE rb_allocate(VALUE klass);
|
26
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
27
|
+
VALUE rb_spatial(VALUE self, VALUE x_order, VALUE y_order);
|
28
|
+
VALUE rb_central(VALUE self, VALUE x_order, VALUE y_order);
|
29
|
+
VALUE rb_normalized_central(VALUE self, VALUE x_order, VALUE y_order);
|
30
|
+
VALUE rb_hu(VALUE self);
|
31
|
+
VALUE rb_gravity_center(VALUE self);
|
32
|
+
VALUE rb_angle(VALUE self);
|
33
|
+
|
34
|
+
VALUE rb_m00(VALUE self);
|
35
|
+
VALUE rb_m10(VALUE self);
|
36
|
+
VALUE rb_m01(VALUE self);
|
37
|
+
VALUE rb_m20(VALUE self);
|
38
|
+
VALUE rb_m11(VALUE self);
|
39
|
+
VALUE rb_m02(VALUE self);
|
40
|
+
VALUE rb_m30(VALUE self);
|
41
|
+
VALUE rb_m21(VALUE self);
|
42
|
+
VALUE rb_m12(VALUE self);
|
43
|
+
VALUE rb_m03(VALUE self);
|
44
|
+
VALUE rb_mu20(VALUE self);
|
45
|
+
VALUE rb_mu11(VALUE self);
|
46
|
+
VALUE rb_mu02(VALUE self);
|
47
|
+
VALUE rb_mu30(VALUE self);
|
48
|
+
VALUE rb_mu21(VALUE self);
|
49
|
+
VALUE rb_mu12(VALUE self);
|
50
|
+
VALUE rb_mu03(VALUE self);
|
51
|
+
VALUE rb_inv_sqrt_m00(VALUE self);
|
52
|
+
|
53
|
+
VALUE new_object(CvArr *arr, int is_binary);
|
54
|
+
|
55
|
+
__NAMESPACE_END_CVMOMENTS
|
56
|
+
|
57
|
+
inline CvMoments*
|
58
|
+
CVMOMENTS(VALUE object)
|
59
|
+
{
|
60
|
+
CvMoments *ptr;
|
61
|
+
Data_Get_Struct(object, CvMoments, ptr);
|
62
|
+
return ptr;
|
63
|
+
}
|
64
|
+
|
65
|
+
inline CvMoments*
|
66
|
+
CVMOMENTS_WITH_CHECK(VALUE object)
|
67
|
+
{
|
68
|
+
if (!rb_obj_is_kind_of(object, cCvMoments::rb_class()))
|
69
|
+
raise_typeerror(object, cCvMoments::rb_class());
|
70
|
+
return CVMOMENTS(object);
|
71
|
+
}
|
72
|
+
|
73
|
+
__NAMESPACE_END_OPENCV
|
74
|
+
|
75
|
+
#endif // RUBY_OPENCV_CVMOMENTS_H
|
@@ -0,0 +1,265 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvpoint.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvpoint.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvPoint
|
13
|
+
*
|
14
|
+
* This class means one point on X axis Y axis.
|
15
|
+
* X and Y takes the value of the Fixnum. see also CvPoint2D32F
|
16
|
+
*
|
17
|
+
* C structure is here, very simple.
|
18
|
+
* typdef struct CvPoint {
|
19
|
+
* int x;
|
20
|
+
* int y;
|
21
|
+
* }
|
22
|
+
*/
|
23
|
+
__NAMESPACE_BEGIN_OPENCV
|
24
|
+
__NAMESPACE_BEGIN_CVPOINT
|
25
|
+
|
26
|
+
VALUE rb_klass;
|
27
|
+
|
28
|
+
VALUE
|
29
|
+
rb_class()
|
30
|
+
{
|
31
|
+
return rb_klass;
|
32
|
+
}
|
33
|
+
|
34
|
+
/*
|
35
|
+
* call-seq:
|
36
|
+
* combatible?(obj)
|
37
|
+
*
|
38
|
+
* Return compatibility to CvPoint. Return true if object have method #x and #y.
|
39
|
+
*
|
40
|
+
* For example.
|
41
|
+
* class MyPoint
|
42
|
+
* def x
|
43
|
+
* 1
|
44
|
+
* end
|
45
|
+
* def y
|
46
|
+
* 2
|
47
|
+
* end
|
48
|
+
* end
|
49
|
+
* mp = MyPoint.new
|
50
|
+
* CvPoint.compatible?(mp) #=> true
|
51
|
+
* CvPoint.new(mp) #=> same as CvPoint(1, 2)
|
52
|
+
*/
|
53
|
+
VALUE
|
54
|
+
rb_compatible_q(VALUE klass, VALUE object)
|
55
|
+
{
|
56
|
+
return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y"))) ? Qtrue : Qfalse;
|
57
|
+
}
|
58
|
+
|
59
|
+
VALUE
|
60
|
+
rb_allocate(VALUE klass)
|
61
|
+
{
|
62
|
+
CvPoint *ptr;
|
63
|
+
return Data_Make_Struct(klass, CvPoint, 0, -1, ptr);
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* call-seq:
|
68
|
+
* new -> CvPoint.new(0, 0)
|
69
|
+
* new(obj) -> CvPoint.new(obj.x.to_i, obj.y.to_i)
|
70
|
+
* new(x, y)
|
71
|
+
*
|
72
|
+
* Create new 2D-coordinate, (x, y). It is dropped below the decimal point.
|
73
|
+
*
|
74
|
+
* new() is same as new(0, 0)
|
75
|
+
*
|
76
|
+
* new(obj) is same as new(obj.x.to_i, obj.y.to_i)
|
77
|
+
*/
|
78
|
+
VALUE
|
79
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
80
|
+
{
|
81
|
+
CvPoint* self_ptr = CVPOINT(self);
|
82
|
+
switch (argc) {
|
83
|
+
case 0:
|
84
|
+
break;
|
85
|
+
case 1: {
|
86
|
+
CvPoint point = VALUE_TO_CVPOINT(argv[0]);
|
87
|
+
self_ptr->x = point.x;
|
88
|
+
self_ptr->y = point.y;
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
case 2:
|
92
|
+
self_ptr->x = NUM2INT(argv[0]);
|
93
|
+
self_ptr->y = NUM2INT(argv[1]);
|
94
|
+
break;
|
95
|
+
default:
|
96
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
return self;
|
100
|
+
}
|
101
|
+
|
102
|
+
/*
|
103
|
+
* Return parameter on x-axis.
|
104
|
+
*/
|
105
|
+
VALUE
|
106
|
+
rb_x(VALUE self)
|
107
|
+
{
|
108
|
+
return INT2NUM(CVPOINT(self)->x);
|
109
|
+
}
|
110
|
+
|
111
|
+
/*
|
112
|
+
* call-seq:
|
113
|
+
* x = val
|
114
|
+
*
|
115
|
+
* Set x-axis parameter, return self.
|
116
|
+
* It is dropped below the decimal point.
|
117
|
+
* pt = CvPoint.new
|
118
|
+
* pt.x = 1.1
|
119
|
+
* pt.x #=> 1
|
120
|
+
* pt.x = 100.9
|
121
|
+
* pt.x #=> 100
|
122
|
+
*/
|
123
|
+
VALUE
|
124
|
+
rb_set_x(VALUE self, VALUE x)
|
125
|
+
{
|
126
|
+
CVPOINT(self)->x = NUM2INT(x);
|
127
|
+
return self;
|
128
|
+
}
|
129
|
+
|
130
|
+
/*
|
131
|
+
* Return parameter on y-axis.
|
132
|
+
*/
|
133
|
+
VALUE
|
134
|
+
rb_y(VALUE self)
|
135
|
+
{
|
136
|
+
return INT2NUM(CVPOINT(self)->y);
|
137
|
+
}
|
138
|
+
|
139
|
+
/*
|
140
|
+
* call-seq:
|
141
|
+
* y = val
|
142
|
+
*
|
143
|
+
* Set y-axis parameter, return self.
|
144
|
+
* It is dropped below the decimal point.
|
145
|
+
*/
|
146
|
+
VALUE
|
147
|
+
rb_set_y(VALUE self, VALUE y)
|
148
|
+
{
|
149
|
+
CVPOINT(self)->y = NUM2INT(y);
|
150
|
+
return self;
|
151
|
+
}
|
152
|
+
|
153
|
+
/*
|
154
|
+
* call-seq:
|
155
|
+
* rb_check_equality(val[,mask])
|
156
|
+
*
|
157
|
+
* Return true CvScalar if has same values as we do
|
158
|
+
*/
|
159
|
+
VALUE
|
160
|
+
rb_check_equality(VALUE self, VALUE compare_to) {
|
161
|
+
CvPoint compare = VALUE_TO_CVPOINT(compare_to);
|
162
|
+
CvPoint* self_ptr = CVPOINT(self);
|
163
|
+
|
164
|
+
return (self_ptr->x == compare.x && self_ptr->y == compare.y) ? Qtrue : Qfalse;
|
165
|
+
}
|
166
|
+
|
167
|
+
VALUE
|
168
|
+
rb_check_inequality(VALUE self, VALUE compare_to) {
|
169
|
+
CvPoint compare = VALUE_TO_CVPOINT(compare_to);
|
170
|
+
CvPoint* self_ptr = CVPOINT(self);
|
171
|
+
|
172
|
+
return (self_ptr->x != compare.x || self_ptr->y != compare.y) ? Qtrue : Qfalse;
|
173
|
+
}
|
174
|
+
|
175
|
+
VALUE
|
176
|
+
rb_hash(VALUE self) {
|
177
|
+
CvPoint* self_ptr = CVPOINT(self);
|
178
|
+
return INT2NUM(rb_memhash(self_ptr, sizeof(CvPoint)));
|
179
|
+
}
|
180
|
+
|
181
|
+
/*
|
182
|
+
* call-seq:
|
183
|
+
* to_s -> "<OpenCV::CvPoint:(self.x,self.y)>"
|
184
|
+
*
|
185
|
+
* Return x and y by String.
|
186
|
+
*/
|
187
|
+
VALUE
|
188
|
+
rb_to_s(VALUE self)
|
189
|
+
{
|
190
|
+
const int i = 4;
|
191
|
+
VALUE str[i];
|
192
|
+
str[0] = rb_str_new2("<%s:(%d,%d)>");
|
193
|
+
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
194
|
+
str[2] = rb_x(self);
|
195
|
+
str[3] = rb_y(self);
|
196
|
+
return rb_f_sprintf(i, str);
|
197
|
+
}
|
198
|
+
|
199
|
+
/*
|
200
|
+
* call-seq:
|
201
|
+
* to_ary -> [x, y]
|
202
|
+
*
|
203
|
+
* Return x and y by Array.
|
204
|
+
*/
|
205
|
+
VALUE
|
206
|
+
rb_to_ary(VALUE self)
|
207
|
+
{
|
208
|
+
CvPoint* self_ptr = CVPOINT(self);
|
209
|
+
return rb_ary_new3(2, INT2NUM(self_ptr->x), INT2NUM(self_ptr->y));
|
210
|
+
}
|
211
|
+
|
212
|
+
VALUE
|
213
|
+
new_object()
|
214
|
+
{
|
215
|
+
VALUE object = rb_allocate(rb_klass);
|
216
|
+
*CVPOINT(object) = cvPoint(0, 0);
|
217
|
+
return object;
|
218
|
+
}
|
219
|
+
|
220
|
+
|
221
|
+
VALUE
|
222
|
+
new_object(CvPoint point)
|
223
|
+
{
|
224
|
+
VALUE object = rb_allocate(rb_klass);
|
225
|
+
*CVPOINT(object) = point;
|
226
|
+
return object;
|
227
|
+
}
|
228
|
+
|
229
|
+
void
|
230
|
+
init_ruby_class()
|
231
|
+
{
|
232
|
+
#if 0
|
233
|
+
// For documentation using YARD
|
234
|
+
VALUE opencv = rb_define_module("OpenCV");
|
235
|
+
#endif
|
236
|
+
|
237
|
+
if (rb_klass)
|
238
|
+
return;
|
239
|
+
/*
|
240
|
+
* opencv = rb_define_module("OpenCV");
|
241
|
+
*
|
242
|
+
* note: this comment is used by rdoc.
|
243
|
+
*/
|
244
|
+
VALUE opencv = rb_module_opencv();
|
245
|
+
|
246
|
+
rb_klass = rb_define_class_under(opencv, "CvPoint", rb_cObject);
|
247
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
248
|
+
rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
|
249
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
250
|
+
rb_define_method(rb_klass, "==", RUBY_METHOD_FUNC(rb_check_equality), 1);
|
251
|
+
rb_define_method(rb_klass, "eql?", RUBY_METHOD_FUNC(rb_check_equality), 1);
|
252
|
+
rb_define_method(rb_klass, "hash", RUBY_METHOD_FUNC(rb_hash), 0);
|
253
|
+
rb_define_method(rb_klass, "!=", RUBY_METHOD_FUNC(rb_check_inequality), 1);
|
254
|
+
rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
|
255
|
+
rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
|
256
|
+
rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
|
257
|
+
rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);
|
258
|
+
|
259
|
+
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
260
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
261
|
+
rb_define_alias(rb_klass, "to_a", "to_ary");
|
262
|
+
}
|
263
|
+
|
264
|
+
__NAMESPACE_END_CVPOINT
|
265
|
+
__NAMESPACE_END_OPENCV
|