jf-ruby-opencv 0.0.18
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 +94 -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 +633 -0
- data/ext/opencv/cvcapture.h +82 -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 +384 -0
- data/ext/opencv/cvcontour.h +51 -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 +717 -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 +6086 -0
- data/ext/opencv/cvmat.h +290 -0
- data/ext/opencv/cvmemstorage.cpp +73 -0
- data/ext/opencv/cvmemstorage.h +50 -0
- data/ext/opencv/cvmoments.cpp +293 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +234 -0
- data/ext/opencv/cvpoint.h +64 -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 +338 -0
- data/ext/opencv/cvrect.h +79 -0
- data/ext/opencv/cvscalar.cpp +241 -0
- data/ext/opencv/cvscalar.h +71 -0
- data/ext/opencv/cvseq.cpp +663 -0
- data/ext/opencv/cvseq.h +75 -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 +246 -0
- data/ext/opencv/cvsurfpoint.h +52 -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 +192 -0
- data/ext/opencv/cvutils.h +30 -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 +77 -0
- data/ext/opencv/facerecognizer.cpp +219 -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 +651 -0
- data/ext/opencv/iplimage.h +73 -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 +819 -0
- data/ext/opencv/opencv.h +408 -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 +3 -0
- data/ruby-opencv.gemspec +44 -0
- data/test/eigenfaces_save.xml +7524 -0
- data/test/fisherfaces_save.xml +7530 -0
- data/test/helper.rb +167 -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 +191 -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 +171 -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 +3036 -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 +311 -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 +166 -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 +352 -0
data/ext/opencv/cvmat.h
ADDED
@@ -0,0 +1,290 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvmat.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2007 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVMAT_H
|
11
|
+
#define RUBY_OPENCV_CVMAT_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
|
16
|
+
#define __NAMESPACE_BEGIN_CVMAT namespace cCvMat {
|
17
|
+
#define __NAMESPACE_END_CVMAT }
|
18
|
+
|
19
|
+
__NAMESPACE_BEGIN_OPENCV
|
20
|
+
__NAMESPACE_BEGIN_CVMAT
|
21
|
+
|
22
|
+
VALUE rb_class();
|
23
|
+
|
24
|
+
void init_ruby_class();
|
25
|
+
|
26
|
+
VALUE rb_allocate(VALUE klass);
|
27
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
28
|
+
VALUE rb_load_imageM(int argc, VALUE *argv, VALUE self);
|
29
|
+
VALUE rb_encode_imageM(int argc, VALUE *argv, VALUE self);
|
30
|
+
VALUE rb_decode_imageM(int argc, VALUE *argv, VALUE self);
|
31
|
+
|
32
|
+
VALUE rb_method_missing(int argc, VALUE *argv, VALUE self);
|
33
|
+
VALUE rb_to_s(VALUE self);
|
34
|
+
VALUE rb_inside_q(VALUE self, VALUE object);
|
35
|
+
VALUE rb_to_IplConvKernel(VALUE self, VALUE anchor);
|
36
|
+
VALUE rb_create_mask(VALUE self);
|
37
|
+
|
38
|
+
VALUE rb_width(VALUE self);
|
39
|
+
VALUE rb_height(VALUE self);
|
40
|
+
VALUE rb_depth(VALUE self);
|
41
|
+
VALUE rb_channel(VALUE self);
|
42
|
+
VALUE rb_data(VALUE self);
|
43
|
+
|
44
|
+
VALUE rb_clone(VALUE self);
|
45
|
+
VALUE rb_copy(int argc, VALUE *argv, VALUE self);
|
46
|
+
VALUE copy(VALUE mat);
|
47
|
+
|
48
|
+
VALUE rb_to_8u(VALUE self);
|
49
|
+
VALUE rb_to_8s(VALUE self);
|
50
|
+
VALUE rb_to_16u(VALUE self);
|
51
|
+
VALUE rb_to_16s(VALUE self);
|
52
|
+
VALUE rb_to_32s(VALUE self);
|
53
|
+
VALUE rb_to_32f(VALUE self);
|
54
|
+
VALUE rb_to_64f(VALUE self);
|
55
|
+
VALUE rb_vector_q(VALUE self);
|
56
|
+
VALUE rb_square_q(VALUE self);
|
57
|
+
// cxcore function
|
58
|
+
VALUE rb_to_CvMat(VALUE self);
|
59
|
+
VALUE rb_to_IplImage(VALUE self);
|
60
|
+
VALUE rb_sub_rect(VALUE self, VALUE args);
|
61
|
+
VALUE rb_get_rows(int argc, VALUE* argv, VALUE self);
|
62
|
+
VALUE rb_get_cols(VALUE self, VALUE col);
|
63
|
+
VALUE rb_each_row(VALUE self);
|
64
|
+
VALUE rb_each_col(VALUE self);
|
65
|
+
VALUE rb_diag(int argc, VALUE *argv, VALUE self);
|
66
|
+
VALUE rb_size(VALUE self);
|
67
|
+
VALUE rb_dims(VALUE self);
|
68
|
+
VALUE rb_dim_size(VALUE self, VALUE index);
|
69
|
+
VALUE rb_aref(VALUE self, VALUE args);
|
70
|
+
VALUE rb_aset(VALUE self, VALUE args);
|
71
|
+
VALUE rb_set_data(VALUE self, VALUE data);
|
72
|
+
VALUE rb_set(int argc, VALUE *argv, VALUE self);
|
73
|
+
VALUE rb_set_bang(int argc, VALUE *argv, VALUE self);
|
74
|
+
VALUE rb_set_zero(VALUE self);
|
75
|
+
VALUE rb_set_zero_bang(VALUE self);
|
76
|
+
VALUE rb_set_identity(int argc, VALUE *argv, VALUE self);
|
77
|
+
VALUE rb_set_identity_bang(int argc, VALUE *argv, VALUE self);
|
78
|
+
VALUE rb_range(VALUE self, VALUE start, VALUE end);
|
79
|
+
VALUE rb_range_bang(VALUE self, VALUE start, VALUE end);
|
80
|
+
/* Transforms and Permutations */
|
81
|
+
VALUE rb_reshape(int argc, VALUE *argv, VALUE self);
|
82
|
+
VALUE rb_repeat(VALUE self, VALUE object);
|
83
|
+
VALUE rb_flip(int argc, VALUE *argv, VALUE self);
|
84
|
+
VALUE rb_flip_bang(int argc, VALUE *argv, VALUE self);
|
85
|
+
VALUE rb_split(VALUE self);
|
86
|
+
VALUE rb_merge(VALUE klass, VALUE args);
|
87
|
+
VALUE rb_rand_shuffle(int argc, VALUE *argv, VALUE klass);
|
88
|
+
VALUE rb_rand_shuffle_bang(int argc, VALUE *argv, VALUE klass);
|
89
|
+
|
90
|
+
VALUE rb_lut(VALUE self, VALUE lut);
|
91
|
+
VALUE rb_convert_scale(VALUE self, VALUE hash);
|
92
|
+
VALUE rb_convert_scale_abs(VALUE self, VALUE hash);
|
93
|
+
VALUE rb_add(int argc, VALUE *argv, VALUE self);
|
94
|
+
VALUE rb_sub(int argc, VALUE *argv, VALUE self);
|
95
|
+
VALUE rb_mul(int argc, VALUE *argv, VALUE self);
|
96
|
+
VALUE rb_mat_mul(int argc, VALUE *argv, VALUE self);
|
97
|
+
VALUE rb_div(int argc, VALUE *argv, VALUE self);
|
98
|
+
VALUE rb_and(int argc, VALUE *argv, VALUE self);
|
99
|
+
VALUE rb_or(int argc, VALUE *argv, VALUE self);
|
100
|
+
VALUE rb_xor(int argc, VALUE *argv, VALUE self);
|
101
|
+
VALUE rb_not(VALUE self);
|
102
|
+
VALUE rb_not_bang(VALUE self);
|
103
|
+
VALUE rb_cmp_internal(VALUE self, VALUE val, int operand);
|
104
|
+
VALUE rb_eq(VALUE self, VALUE val);
|
105
|
+
VALUE rb_gt(VALUE self, VALUE val);
|
106
|
+
VALUE rb_ge(VALUE self, VALUE val);
|
107
|
+
VALUE rb_lt(VALUE self, VALUE val);
|
108
|
+
VALUE rb_le(VALUE self, VALUE val);
|
109
|
+
VALUE rb_ne(VALUE self, VALUE val);
|
110
|
+
VALUE rb_in_range(VALUE self, VALUE min, VALUE max);
|
111
|
+
VALUE rb_abs_diff(VALUE self, VALUE val);
|
112
|
+
VALUE rb_normalize(int argc, VALUE *argv, VALUE self);
|
113
|
+
VALUE rb_add_weighted(VALUE klass, VALUE src1, VALUE alpha, VALUE src2, VALUE beta, VALUE gamma);
|
114
|
+
/* Statistics */
|
115
|
+
VALUE rb_count_non_zero(VALUE self);
|
116
|
+
VALUE rb_sum(VALUE self);
|
117
|
+
VALUE rb_avg(int argc, VALUE *argv, VALUE self);
|
118
|
+
VALUE rb_avg_sdv(int argc, VALUE *argv, VALUE self);
|
119
|
+
VALUE rb_sdv(int argc, VALUE *argv, VALUE self);
|
120
|
+
VALUE rb_min_max_loc(int argc, VALUE *argv, VALUE self);
|
121
|
+
|
122
|
+
VALUE rb_norm(int argc, VALUE *argv, VALUE self);
|
123
|
+
VALUE rb_dot_product(VALUE self, VALUE mat);
|
124
|
+
VALUE rb_cross_product(VALUE self, VALUE mat);
|
125
|
+
// VALUE rb_gemm();
|
126
|
+
VALUE rb_transform(int argc, VALUE *argv, VALUE self);
|
127
|
+
VALUE rb_perspective_transform(VALUE self, VALUE mat);
|
128
|
+
VALUE rb_mul_transposed(int argc, VALUE *argv, VALUE self);
|
129
|
+
VALUE rb_trace(VALUE self);
|
130
|
+
VALUE rb_transpose(VALUE self);
|
131
|
+
VALUE rb_det(VALUE self);
|
132
|
+
VALUE rb_invert(int argc, VALUE *argv, VALUE self);
|
133
|
+
VALUE rb_solve(int argc, VALUE *argv, VALUE self);
|
134
|
+
VALUE rb_svd(int argc, VALUE *argv, VALUE self);
|
135
|
+
VALUE rb_eigenvv(int argc, VALUE *argv, VALUE self);
|
136
|
+
VALUE rb_eigenvv_bang(int argc, VALUE *argv, VALUE self);
|
137
|
+
|
138
|
+
VALUE rb_dft(int argc, VALUE *argv, VALUE self);
|
139
|
+
VALUE rb_dct(int argc, VALUE *argv, VALUE self);
|
140
|
+
|
141
|
+
/* drawing function*/
|
142
|
+
VALUE rb_line(int argc, VALUE *argv, VALUE self);
|
143
|
+
VALUE rb_line_bang(int argc, VALUE *argv, VALUE self);
|
144
|
+
VALUE rb_rectangle(int argc, VALUE *argv, VALUE self);
|
145
|
+
VALUE rb_rectangle_bang(int argc, VALUE *argv, VALUE self);
|
146
|
+
VALUE rb_circle(int argc, VALUE *argv, VALUE self);
|
147
|
+
VALUE rb_circle_bang(int argc, VALUE *argv, VALUE self);
|
148
|
+
VALUE rb_ellipse(int argc, VALUE *argv, VALUE self);
|
149
|
+
VALUE rb_ellipse_bang(int argc, VALUE *argv, VALUE self);
|
150
|
+
VALUE rb_ellipse_box(int argc, VALUE *argv, VALUE self);
|
151
|
+
VALUE rb_ellipse_box_bang(int argc, VALUE *argv, VALUE self);
|
152
|
+
VALUE rb_fill_poly(int argc, VALUE *argv, VALUE self);
|
153
|
+
VALUE rb_fill_poly_bang(int argc, VALUE *argv, VALUE self);
|
154
|
+
VALUE rb_fill_convex_poly(int argc, VALUE *argv, VALUE self);
|
155
|
+
VALUE rb_fill_convex_poly_bang(int argc, VALUE *argv, VALUE self);
|
156
|
+
VALUE rb_poly_line(int argc, VALUE *argv, VALUE self);
|
157
|
+
VALUE rb_poly_line_bang(int argc, VALUE *argv, VALUE self);
|
158
|
+
VALUE rb_put_text(int argc, VALUE *argv, VALUE self);
|
159
|
+
VALUE rb_put_text_bang(int argc, VALUE *argv, VALUE self);
|
160
|
+
|
161
|
+
/* cv function */
|
162
|
+
VALUE rb_sobel(int argc, VALUE *argv, VALUE self);
|
163
|
+
VALUE rb_laplace(int argc, VALUE *argv, VALUE self);
|
164
|
+
VALUE rb_canny(int argc, VALUE *argv, VALUE self);
|
165
|
+
VALUE rb_pre_corner_detect(int argc, VALUE *argv, VALUE self);
|
166
|
+
VALUE rb_corner_eigenvv(int argc, VALUE *argv, VALUE self);
|
167
|
+
VALUE rb_corner_min_eigen_val(int argc, VALUE *argv, VALUE self);
|
168
|
+
VALUE rb_corner_harris(int argc, VALUE *argv, VALUE self);
|
169
|
+
VALUE rb_find_chessboard_corners(int argc, VALUE *argv, VALUE self);
|
170
|
+
VALUE rb_find_corner_sub_pix(VALUE self, VALUE corners, VALUE win_size, VALUE zero_zone, VALUE criteria);
|
171
|
+
VALUE rb_good_features_to_track(int argc, VALUE *argv, VALUE self);
|
172
|
+
|
173
|
+
VALUE rb_rect_sub_pix(int argc, VALUE *argv, VALUE self);
|
174
|
+
VALUE rb_quadrangle_sub_pix(int argc, VALUE *argv, VALUE self);
|
175
|
+
VALUE rb_resize(int argc, VALUE *argv, VALUE self);
|
176
|
+
VALUE rb_warp_affine(int argc, VALUE *argv, VALUE self);
|
177
|
+
VALUE rb_rotation_matrix2D(VALUE self, VALUE center, VALUE angle, VALUE scale);
|
178
|
+
VALUE rb_get_perspective_transform(VALUE self, VALUE source, VALUE dest);
|
179
|
+
VALUE rb_warp_perspective(int argc, VALUE *argv, VALUE self);
|
180
|
+
VALUE rb_find_homography(int argc, VALUE *argv, VALUE self);
|
181
|
+
VALUE rb_remap(int argc, VALUE *argv, VALUE self);
|
182
|
+
VALUE rb_log_polar(int argc, VALUE *argv, VALUE self);
|
183
|
+
|
184
|
+
VALUE rb_erode(int argc, VALUE *argv, VALUE self);
|
185
|
+
VALUE rb_erode_bang(int argc, VALUE *argv, VALUE self);
|
186
|
+
VALUE rb_dilate(int argc, VALUE *argv, VALUE self);
|
187
|
+
VALUE rb_dilate_bang(int argc, VALUE *argv, VALUE self);
|
188
|
+
VALUE rb_morphology(int argc, VALUE *argv, VALUE self);
|
189
|
+
|
190
|
+
VALUE rb_smooth(int argc, VALUE *argv, VALUE self);
|
191
|
+
VALUE rb_copy_make_border(int argc, VALUE *argv, VALUE self);
|
192
|
+
VALUE rb_filter2d(int argc, VALUE *argv, VALUE self);
|
193
|
+
VALUE rb_integral(int argc, VALUE *argv, VALUE self);
|
194
|
+
VALUE rb_threshold(int argc, VALUE *argv, VALUE self);
|
195
|
+
VALUE rb_adaptive_threshold(int argc, VALUE *argv, VALUE self);
|
196
|
+
|
197
|
+
VALUE rb_pyr_down(int argc, VALUE *argv, VALUE self);
|
198
|
+
VALUE rb_pyr_up(int argc, VALUE *argv, VALUE self);
|
199
|
+
|
200
|
+
VALUE rb_flood_fill(int argc, VALUE *argv, VALUE self);
|
201
|
+
VALUE rb_flood_fill_bang(int argc, VALUE *argv, VALUE self);
|
202
|
+
VALUE rb_find_contours(int argc, VALUE *argv, VALUE self);
|
203
|
+
VALUE rb_find_contours_bang(int argc, VALUE *argv, VALUE self);
|
204
|
+
VALUE rb_draw_contours(int argc, VALUE *argv, VALUE self);
|
205
|
+
VALUE rb_draw_contours_bang(int argc, VALUE *argv, VALUE self);
|
206
|
+
VALUE rb_draw_chessboard_corners(VALUE self, VALUE pattern_size, VALUE corners, VALUE pattern_was_found);
|
207
|
+
VALUE rb_draw_chessboard_corners_bang(VALUE self, VALUE pattern_size, VALUE corners, VALUE pattern_was_found);
|
208
|
+
VALUE rb_pyr_mean_shift_filtering(int argc, VALUE *argv, VALUE self);
|
209
|
+
VALUE rb_watershed(VALUE self, VALUE markers);
|
210
|
+
VALUE rb_moments(int argc, VALUE *argv, VALUE self);
|
211
|
+
|
212
|
+
VALUE rb_hough_lines(int argc, VALUE *argv, VALUE self);
|
213
|
+
VALUE rb_hough_circles(int argc, VALUE *argv, VALUE self);
|
214
|
+
VALUE rb_dist_transform(int argc, VALUE *argv, VALUE self);
|
215
|
+
VALUE rb_inpaint(VALUE self, VALUE inpaint_method, VALUE mask, VALUE radius);
|
216
|
+
|
217
|
+
VALUE rb_equalize_hist(VALUE self);
|
218
|
+
|
219
|
+
VALUE rb_apply_color_map(VALUE self, VALUE colormap);
|
220
|
+
|
221
|
+
/* Matching*/
|
222
|
+
VALUE rb_match_template(int argc, VALUE *argv, VALUE self);
|
223
|
+
VALUE rb_match_shapes(int argc, VALUE *argv, VALUE self);
|
224
|
+
|
225
|
+
/* Object Tracking */
|
226
|
+
VALUE rb_mean_shift(VALUE self, VALUE window, VALUE criteria);
|
227
|
+
VALUE rb_cam_shift(VALUE self, VALUE window, VALUE criteria);
|
228
|
+
VALUE rb_snake_image(int argc, VALUE *argv, VALUE self);
|
229
|
+
/* Optical Flow */
|
230
|
+
VALUE rb_optical_flow_hs(int argc, VALUE *argv, VALUE self);
|
231
|
+
VALUE rb_optical_flow_lk(VALUE self, VALUE prev, VALUE win_size);
|
232
|
+
VALUE rb_optical_flow_bm(int argc, VALUE *argv, VALUE self);
|
233
|
+
VALUE rb_optical_flow_pyr_lk(int argc, VALUE *argv, VALUE self);
|
234
|
+
|
235
|
+
/* Epipolar Geometory */
|
236
|
+
VALUE rb_find_fundamental_mat(int argc, VALUE *argv, VALUE klass);
|
237
|
+
VALUE rb_compute_correspond_epilines(VALUE klass, VALUE points, VALUE which_image, VALUE fundamental_matrix);
|
238
|
+
|
239
|
+
/* Feature detection and description */
|
240
|
+
VALUE rb_extract_surf(int argc, VALUE *argv, VALUE self);
|
241
|
+
|
242
|
+
VALUE rb_subspace_project(VALUE self, VALUE w, VALUE mean);
|
243
|
+
VALUE rb_subspace_reconstruct(VALUE self, VALUE w, VALUE mean);
|
244
|
+
|
245
|
+
// HighGUI function
|
246
|
+
VALUE rb_save_image(int argc, VALUE *argv, VALUE self);
|
247
|
+
|
248
|
+
VALUE new_object(int rows, int cols, int type);
|
249
|
+
VALUE new_object(CvSize size, int type);
|
250
|
+
VALUE new_mat_kind_object(CvSize size, VALUE ref_obj);
|
251
|
+
VALUE new_mat_kind_object(CvSize size, VALUE ref_obj, int cvmat_depth, int channel);
|
252
|
+
|
253
|
+
CvMat* prepare_decoding(int argc, VALUE *argv, int* iscolor, int* need_release);
|
254
|
+
|
255
|
+
__NAMESPACE_END_CVMAT
|
256
|
+
|
257
|
+
inline CvMat*
|
258
|
+
CVMAT(VALUE object)
|
259
|
+
{
|
260
|
+
CvMat *ptr, stub;
|
261
|
+
Data_Get_Struct(object, CvMat, ptr);
|
262
|
+
return cvGetMat(ptr, &stub);
|
263
|
+
}
|
264
|
+
|
265
|
+
inline CvMat*
|
266
|
+
CVMAT_WITH_CHECK(VALUE object)
|
267
|
+
{
|
268
|
+
if (!rb_obj_is_kind_of(object, cCvMat::rb_class()))
|
269
|
+
raise_typeerror(object, cCvMat::rb_class());
|
270
|
+
return CVMAT(object);
|
271
|
+
}
|
272
|
+
|
273
|
+
inline CvMat*
|
274
|
+
MASK(VALUE object)
|
275
|
+
{
|
276
|
+
if (NIL_P(object))
|
277
|
+
return NULL;
|
278
|
+
else {
|
279
|
+
CvMat* obj_ptr = CVMAT_WITH_CHECK(object);
|
280
|
+
if (CV_MAT_DEPTH(obj_ptr->type) == CV_8UC1 &&
|
281
|
+
CV_MAT_CN(obj_ptr->type) == 1)
|
282
|
+
return obj_ptr;
|
283
|
+
else
|
284
|
+
rb_raise(rb_eTypeError, "Mask should be 8bit 1-channel matrix.");
|
285
|
+
}
|
286
|
+
}
|
287
|
+
|
288
|
+
__NAMESPACE_END_OPENCV
|
289
|
+
|
290
|
+
#endif // RUBY_OPENCV_CVMAT_H
|
@@ -0,0 +1,73 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvmemstorage.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvmemstorage.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvMemStorage
|
13
|
+
*
|
14
|
+
* Internal memory management class used by CvSeq.
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_CVMEMSTORAGE
|
18
|
+
|
19
|
+
VALUE rb_klass;
|
20
|
+
|
21
|
+
VALUE
|
22
|
+
rb_class()
|
23
|
+
{
|
24
|
+
return rb_klass;
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE
|
28
|
+
rb_allocate(VALUE klass)
|
29
|
+
{
|
30
|
+
CvMemStorage *storage = rb_cvCreateMemStorage(0);
|
31
|
+
return Data_Wrap_Struct(klass, 0, cvmemstorage_free, storage);
|
32
|
+
}
|
33
|
+
|
34
|
+
void
|
35
|
+
cvmemstorage_free(void *ptr)
|
36
|
+
{
|
37
|
+
try {
|
38
|
+
cvReleaseMemStorage((CvMemStorage**)&ptr);
|
39
|
+
}
|
40
|
+
catch (cv::Exception& e) {
|
41
|
+
raise_cverror(e);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
VALUE
|
46
|
+
new_object(int blocksize)
|
47
|
+
{
|
48
|
+
CvMemStorage *storage = rb_cvCreateMemStorage(blocksize);
|
49
|
+
return Data_Wrap_Struct(rb_klass, 0, cvmemstorage_free, storage);
|
50
|
+
}
|
51
|
+
|
52
|
+
void
|
53
|
+
init_ruby_class()
|
54
|
+
{
|
55
|
+
#if 0
|
56
|
+
// For documentation using YARD
|
57
|
+
VALUE opencv = rb_define_module("OpenCV");
|
58
|
+
#endif
|
59
|
+
|
60
|
+
if (rb_klass)
|
61
|
+
return;
|
62
|
+
/*
|
63
|
+
* opencv = rb_define_module("OpenCV");
|
64
|
+
*
|
65
|
+
* note: this comment is used by rdoc.
|
66
|
+
*/
|
67
|
+
VALUE opencv = rb_module_opencv();
|
68
|
+
rb_klass = rb_define_class_under(opencv, "CvMemStorage", rb_cObject);
|
69
|
+
}
|
70
|
+
|
71
|
+
__NAMESPACE_END_CVMEMSTORAGE
|
72
|
+
__NAMESPACE_END_OPENCV
|
73
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvmemstorage.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVMEMSTORAGE_H
|
11
|
+
#define RUBY_OPENCV_CVMEMSTORAGE_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVMEMSTORAGE namespace cCvMemStorage {
|
16
|
+
#define __NAMESPACE_END_CVMEMSTORAGE }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVMEMSTORAGE
|
20
|
+
|
21
|
+
void init_ruby_class();
|
22
|
+
|
23
|
+
VALUE rb_class();
|
24
|
+
VALUE rb_allocate(VALUE klass);
|
25
|
+
void cvmemstorage_free(void *ptr);
|
26
|
+
|
27
|
+
VALUE new_object(int blocksize = 0);
|
28
|
+
|
29
|
+
__NAMESPACE_END_CVMEMSTORAGE
|
30
|
+
|
31
|
+
inline CvMemStorage*
|
32
|
+
CVMEMSTORAGE(VALUE object)
|
33
|
+
{
|
34
|
+
CvMemStorage *ptr;
|
35
|
+
Data_Get_Struct(object, CvMemStorage, ptr);
|
36
|
+
return ptr;
|
37
|
+
}
|
38
|
+
|
39
|
+
inline VALUE
|
40
|
+
CHECK_CVMEMSTORAGE(VALUE object)
|
41
|
+
{
|
42
|
+
if (rb_obj_is_kind_of(object, cCvMemStorage::rb_class())) {
|
43
|
+
return object;
|
44
|
+
}
|
45
|
+
return cCvMemStorage::new_object();
|
46
|
+
}
|
47
|
+
|
48
|
+
__NAMESPACE_END_OPENCV
|
49
|
+
|
50
|
+
#endif // RUBY_OPENCV_CVMEMSTORAGE_H
|
@@ -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
|
+
|