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
data/examples/snake.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# snake.rb
|
3
|
+
require "rubygems"
|
4
|
+
require "opencv"
|
5
|
+
include OpenCV
|
6
|
+
|
7
|
+
puts <<USAGE
|
8
|
+
usage:
|
9
|
+
left-click: set a point
|
10
|
+
right-click: do snake
|
11
|
+
USAGE
|
12
|
+
|
13
|
+
window = GUI::Window.new "snake demo"
|
14
|
+
image = CvMat.new(256, 256, :cv8u, 1).clear!
|
15
|
+
image.circle!(CvPoint.new(128,128), 40, color: CvColor::White, thickness: -1)
|
16
|
+
display = image.GRAY2BGR
|
17
|
+
|
18
|
+
window.show display
|
19
|
+
|
20
|
+
points = []
|
21
|
+
|
22
|
+
window.on_mouse{|mouse|
|
23
|
+
case mouse.event
|
24
|
+
when :left_button_down
|
25
|
+
display.circle!(mouse, 1, color: CvColor::Red, thickness: 2)
|
26
|
+
puts "set point (#{mouse.x},#{mouse.y})"
|
27
|
+
points << CvPoint.new(mouse.x, mouse.y)
|
28
|
+
window.show display
|
29
|
+
when :right_button_down
|
30
|
+
if points.length < 3
|
31
|
+
puts "please set more point!"
|
32
|
+
next
|
33
|
+
end
|
34
|
+
snake_points = image.snake_image(points, 1.0, 0.5, 1.5, CvSize.new(3, 3), 100)
|
35
|
+
display = image.GRAY2BGR
|
36
|
+
display.poly_line!([snake_points], color: CvColor::Red, is_closed: true, thickness: 2)
|
37
|
+
window.show display
|
38
|
+
points.clear
|
39
|
+
end
|
40
|
+
}
|
41
|
+
|
42
|
+
GUI::wait_key
|
43
|
+
|
@@ -0,0 +1,291 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
algorithm.cpp -
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2013 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include <stdio.h>
|
11
|
+
#include "algorithm.h"
|
12
|
+
/*
|
13
|
+
* Document-class: OpenCV::Algorithm
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_ALGORITHM
|
18
|
+
|
19
|
+
VALUE rb_klass;
|
20
|
+
|
21
|
+
VALUE
|
22
|
+
rb_class()
|
23
|
+
{
|
24
|
+
return rb_klass;
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE
|
28
|
+
rb_set_int(VALUE self, VALUE parameter, VALUE value)
|
29
|
+
{
|
30
|
+
Check_Type(parameter, T_STRING);
|
31
|
+
try {
|
32
|
+
ALGORITHM(self)->setInt(StringValueCStr(parameter), NUM2INT(value));
|
33
|
+
}
|
34
|
+
catch (cv::Exception& e) {
|
35
|
+
raise_cverror(e);
|
36
|
+
}
|
37
|
+
|
38
|
+
return Qnil;
|
39
|
+
}
|
40
|
+
|
41
|
+
VALUE
|
42
|
+
rb_set_double(VALUE self, VALUE parameter, VALUE value)
|
43
|
+
{
|
44
|
+
Check_Type(parameter, T_STRING);
|
45
|
+
try {
|
46
|
+
ALGORITHM(self)->setDouble(StringValueCStr(parameter), NUM2DBL(value));
|
47
|
+
}
|
48
|
+
catch (cv::Exception& e) {
|
49
|
+
raise_cverror(e);
|
50
|
+
}
|
51
|
+
|
52
|
+
return Qnil;
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE
|
56
|
+
rb_set_bool(VALUE self, VALUE parameter, VALUE value)
|
57
|
+
{
|
58
|
+
Check_Type(parameter, T_STRING);
|
59
|
+
try {
|
60
|
+
bool val = TRUE_OR_FALSE(value) ? true : false;
|
61
|
+
ALGORITHM(self)->setBool(StringValueCStr(parameter), val);
|
62
|
+
}
|
63
|
+
catch (cv::Exception& e) {
|
64
|
+
raise_cverror(e);
|
65
|
+
}
|
66
|
+
|
67
|
+
return Qnil;
|
68
|
+
}
|
69
|
+
|
70
|
+
VALUE
|
71
|
+
rb_set_string(VALUE self, VALUE parameter, VALUE value)
|
72
|
+
{
|
73
|
+
Check_Type(parameter, T_STRING);
|
74
|
+
Check_Type(value, T_STRING);
|
75
|
+
try {
|
76
|
+
ALGORITHM(self)->setString(StringValueCStr(parameter), StringValueCStr(value));
|
77
|
+
}
|
78
|
+
catch (cv::Exception& e) {
|
79
|
+
raise_cverror(e);
|
80
|
+
}
|
81
|
+
|
82
|
+
return Qnil;
|
83
|
+
}
|
84
|
+
|
85
|
+
VALUE
|
86
|
+
rb_set_mat(VALUE self, VALUE parameter, VALUE value)
|
87
|
+
{
|
88
|
+
Check_Type(parameter, T_STRING);
|
89
|
+
try {
|
90
|
+
CvMat* val = CVMAT_WITH_CHECK(value);
|
91
|
+
cv::Mat mat(val);
|
92
|
+
ALGORITHM(self)->setMat(StringValueCStr(parameter), mat);
|
93
|
+
}
|
94
|
+
catch (cv::Exception& e) {
|
95
|
+
raise_cverror(e);
|
96
|
+
}
|
97
|
+
|
98
|
+
return Qnil;
|
99
|
+
}
|
100
|
+
|
101
|
+
VALUE
|
102
|
+
rb_set_matvector(VALUE self, VALUE parameter, VALUE value)
|
103
|
+
{
|
104
|
+
Check_Type(parameter, T_STRING);
|
105
|
+
Check_Type(value, T_ARRAY);
|
106
|
+
try {
|
107
|
+
long len = RARRAY_LEN(value);
|
108
|
+
VALUE* value_ptr = RARRAY_PTR(value);
|
109
|
+
std::vector<cv::Mat> mat_vector;
|
110
|
+
for (int i = 0; i < len; i++) {
|
111
|
+
CvMat* val = CVMAT_WITH_CHECK(value_ptr[i]);
|
112
|
+
cv::Mat mat(val);
|
113
|
+
mat_vector.push_back(mat);
|
114
|
+
}
|
115
|
+
ALGORITHM(self)->setMatVector(StringValueCStr(parameter), mat_vector);
|
116
|
+
}
|
117
|
+
catch (cv::Exception& e) {
|
118
|
+
raise_cverror(e);
|
119
|
+
}
|
120
|
+
|
121
|
+
return Qnil;
|
122
|
+
}
|
123
|
+
|
124
|
+
VALUE
|
125
|
+
rb_set_algorithm(VALUE self, VALUE parameter, VALUE value)
|
126
|
+
{
|
127
|
+
Check_Type(parameter, T_STRING);
|
128
|
+
try {
|
129
|
+
ALGORITHM(self)->setAlgorithm(StringValueCStr(parameter), ALGORITHM(value));
|
130
|
+
}
|
131
|
+
catch (cv::Exception& e) {
|
132
|
+
raise_cverror(e);
|
133
|
+
}
|
134
|
+
|
135
|
+
return Qnil;
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
VALUE
|
140
|
+
rb_get_int(VALUE self, VALUE parameter)
|
141
|
+
{
|
142
|
+
Check_Type(parameter, T_STRING);
|
143
|
+
int value = 0;
|
144
|
+
try {
|
145
|
+
value = ALGORITHM(self)->getInt(StringValueCStr(parameter));
|
146
|
+
}
|
147
|
+
catch (cv::Exception& e) {
|
148
|
+
raise_cverror(e);
|
149
|
+
}
|
150
|
+
|
151
|
+
return INT2NUM(value);
|
152
|
+
}
|
153
|
+
|
154
|
+
VALUE
|
155
|
+
rb_get_double(VALUE self, VALUE parameter)
|
156
|
+
{
|
157
|
+
Check_Type(parameter, T_STRING);
|
158
|
+
double value = 0.0;
|
159
|
+
try {
|
160
|
+
value = ALGORITHM(self)->getDouble(StringValueCStr(parameter));
|
161
|
+
}
|
162
|
+
catch (cv::Exception& e) {
|
163
|
+
raise_cverror(e);
|
164
|
+
}
|
165
|
+
|
166
|
+
return DBL2NUM(value);
|
167
|
+
}
|
168
|
+
|
169
|
+
VALUE
|
170
|
+
rb_get_bool(VALUE self, VALUE parameter)
|
171
|
+
{
|
172
|
+
Check_Type(parameter, T_STRING);
|
173
|
+
bool value = false;
|
174
|
+
try {
|
175
|
+
value = ALGORITHM(self)->getBool(StringValueCStr(parameter));
|
176
|
+
}
|
177
|
+
catch (cv::Exception& e) {
|
178
|
+
raise_cverror(e);
|
179
|
+
}
|
180
|
+
|
181
|
+
return value ? Qtrue : Qfalse;
|
182
|
+
}
|
183
|
+
|
184
|
+
VALUE
|
185
|
+
rb_get_string(VALUE self, VALUE parameter)
|
186
|
+
{
|
187
|
+
Check_Type(parameter, T_STRING);
|
188
|
+
std::string value = "";
|
189
|
+
try {
|
190
|
+
value = ALGORITHM(self)->getString(StringValueCStr(parameter));
|
191
|
+
}
|
192
|
+
catch (cv::Exception& e) {
|
193
|
+
raise_cverror(e);
|
194
|
+
}
|
195
|
+
|
196
|
+
return rb_str_new_cstr(value.c_str());
|
197
|
+
}
|
198
|
+
|
199
|
+
VALUE
|
200
|
+
rb_get_mat(VALUE self, VALUE parameter)
|
201
|
+
{
|
202
|
+
Check_Type(parameter, T_STRING);
|
203
|
+
VALUE mat = Qnil;
|
204
|
+
try {
|
205
|
+
cv::Mat value = ALGORITHM(self)->getMat(StringValueCStr(parameter));
|
206
|
+
cv::Size size = value.size();
|
207
|
+
mat = cCvMat::new_object(size.height, size.width, value.type());
|
208
|
+
cv::Mat dst(CVMAT(mat));
|
209
|
+
value.copyTo(dst);
|
210
|
+
}
|
211
|
+
catch (cv::Exception& e) {
|
212
|
+
raise_cverror(e);
|
213
|
+
}
|
214
|
+
return mat;
|
215
|
+
}
|
216
|
+
|
217
|
+
VALUE
|
218
|
+
rb_get_matvector(VALUE self, VALUE parameter)
|
219
|
+
{
|
220
|
+
Check_Type(parameter, T_STRING);
|
221
|
+
VALUE array = Qnil;
|
222
|
+
try {
|
223
|
+
std::vector<cv::Mat> value = ALGORITHM(self)->getMatVector(StringValueCStr(parameter));
|
224
|
+
int len = value.size();
|
225
|
+
array = rb_ary_new2(len);
|
226
|
+
for (int i = 0; i < len; i++) {
|
227
|
+
cv::Mat m = value[i];
|
228
|
+
cv::Size size = m.size();
|
229
|
+
VALUE mat = cCvMat::new_object(size.height, size.width, m.type());
|
230
|
+
cv::Mat dst(CVMAT(mat));
|
231
|
+
m.copyTo(dst);
|
232
|
+
rb_ary_store(array, i, mat);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
catch (cv::Exception& e) {
|
236
|
+
raise_cverror(e);
|
237
|
+
}
|
238
|
+
return array;
|
239
|
+
}
|
240
|
+
|
241
|
+
VALUE
|
242
|
+
rb_name(VALUE self)
|
243
|
+
{
|
244
|
+
VALUE name = Qnil;
|
245
|
+
try {
|
246
|
+
name = rb_str_new_cstr(ALGORITHM(self)->name().c_str());
|
247
|
+
}
|
248
|
+
catch (cv::Exception& e) {
|
249
|
+
raise_cverror(e);
|
250
|
+
}
|
251
|
+
return name;
|
252
|
+
}
|
253
|
+
|
254
|
+
void
|
255
|
+
init_ruby_class()
|
256
|
+
{
|
257
|
+
#if 0
|
258
|
+
// For documentation using YARD
|
259
|
+
VALUE opencv = rb_define_module("OpenCV");
|
260
|
+
#endif
|
261
|
+
|
262
|
+
if (rb_klass)
|
263
|
+
return;
|
264
|
+
/*
|
265
|
+
* opencv = rb_define_module("OpenCV");
|
266
|
+
*
|
267
|
+
* note: this comment is used by rdoc.
|
268
|
+
*/
|
269
|
+
VALUE opencv = rb_module_opencv();
|
270
|
+
rb_klass = rb_define_class_under(opencv, "Algorithm", rb_cObject);
|
271
|
+
rb_define_method(rb_klass, "set_int", RUBY_METHOD_FUNC(rb_set_int), 2);
|
272
|
+
rb_define_method(rb_klass, "set_double", RUBY_METHOD_FUNC(rb_set_double), 2);
|
273
|
+
rb_define_method(rb_klass, "set_bool", RUBY_METHOD_FUNC(rb_set_bool), 2);
|
274
|
+
rb_define_method(rb_klass, "set_string", RUBY_METHOD_FUNC(rb_set_string), 2);
|
275
|
+
rb_define_method(rb_klass, "set_mat", RUBY_METHOD_FUNC(rb_set_mat), 2);
|
276
|
+
rb_define_method(rb_klass, "set_matvector", RUBY_METHOD_FUNC(rb_set_matvector), 2);
|
277
|
+
rb_define_method(rb_klass, "set_algorithm", RUBY_METHOD_FUNC(rb_set_algorithm), 2);
|
278
|
+
|
279
|
+
rb_define_method(rb_klass, "get_int", RUBY_METHOD_FUNC(rb_get_int), 1);
|
280
|
+
rb_define_method(rb_klass, "get_double", RUBY_METHOD_FUNC(rb_get_double), 1);
|
281
|
+
rb_define_method(rb_klass, "get_bool", RUBY_METHOD_FUNC(rb_get_bool), 1);
|
282
|
+
rb_define_method(rb_klass, "get_string", RUBY_METHOD_FUNC(rb_get_string), 1);
|
283
|
+
rb_define_method(rb_klass, "get_mat", RUBY_METHOD_FUNC(rb_get_mat), 1);
|
284
|
+
rb_define_method(rb_klass, "get_matvector", RUBY_METHOD_FUNC(rb_get_matvector), 1);
|
285
|
+
|
286
|
+
rb_define_method(rb_klass, "name", RUBY_METHOD_FUNC(rb_name), 0);
|
287
|
+
}
|
288
|
+
|
289
|
+
__NAMESPACE_END_ALGORITM
|
290
|
+
__NAMESPACE_END_OPENCV
|
291
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
algorithm.h
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2013 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_ALGORITHM_H
|
11
|
+
#define RUBY_OPENCV_ALGORITHM_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_ALGORITHM namespace cAlgorithm {
|
16
|
+
#define __NAMESPACE_END_ALGORITM }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_ALGORITHM
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void init_ruby_class();
|
24
|
+
|
25
|
+
__NAMESPACE_END_ALGORITM
|
26
|
+
|
27
|
+
inline cv::Algorithm*
|
28
|
+
ALGORITHM(VALUE object)
|
29
|
+
{
|
30
|
+
cv::Algorithm *ptr;
|
31
|
+
Data_Get_Struct(object, cv::Algorithm, ptr);
|
32
|
+
return ptr;
|
33
|
+
}
|
34
|
+
|
35
|
+
__NAMESPACE_END_OPENCV
|
36
|
+
|
37
|
+
#endif // RUBY_OPENCV_ALGORITHM_H
|
38
|
+
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
curve.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "curve.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::Curve
|
13
|
+
*
|
14
|
+
* Curve sequence
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_CURVE
|
18
|
+
|
19
|
+
VALUE module;
|
20
|
+
|
21
|
+
VALUE
|
22
|
+
rb_module()
|
23
|
+
{
|
24
|
+
return module;
|
25
|
+
}
|
26
|
+
|
27
|
+
/*
|
28
|
+
* If the curve is closed, return true. Otherwise return false.
|
29
|
+
* @overload closed?
|
30
|
+
* @return [Boolean] Closed or not
|
31
|
+
* @opencv_func CV_IS_SEQ_CLOSED
|
32
|
+
*/
|
33
|
+
VALUE
|
34
|
+
rb_closed_q(VALUE self)
|
35
|
+
{
|
36
|
+
return CV_IS_SEQ_CLOSED(CVSEQ(self)) ? Qtrue : Qfalse;
|
37
|
+
}
|
38
|
+
|
39
|
+
/*
|
40
|
+
* If the curve is convex, return true. Otherwise return false.
|
41
|
+
* @overload convex?
|
42
|
+
* @return [Boolean] Convex or not
|
43
|
+
* @opencv_func CV_IS_SEQ_CONVEX
|
44
|
+
*/
|
45
|
+
VALUE
|
46
|
+
rb_convex_q(VALUE self)
|
47
|
+
{
|
48
|
+
return CV_IS_SEQ_CONVEX(CVSEQ(self)) ? Qtrue : Qfalse;
|
49
|
+
}
|
50
|
+
|
51
|
+
/*
|
52
|
+
* If the curve is hole(inner contour), return true. Otherwise return false.
|
53
|
+
* @overload hole?
|
54
|
+
* @return [Boolean] Hole or not
|
55
|
+
* @opencv_func CV_IS_SEQ_HOLE
|
56
|
+
*/
|
57
|
+
VALUE
|
58
|
+
rb_hole_q(VALUE self)
|
59
|
+
{
|
60
|
+
return CV_IS_SEQ_HOLE(CVSEQ(self)) ? Qtrue : Qfalse;
|
61
|
+
}
|
62
|
+
|
63
|
+
/*
|
64
|
+
* If the curve is simple, return true. Otherwise return false.
|
65
|
+
* @overload simple?
|
66
|
+
* @return [Boolean] Simple or not
|
67
|
+
* @opencv_func CV_IS_SEQ_SIMPLE
|
68
|
+
*/
|
69
|
+
VALUE
|
70
|
+
rb_simple_q(VALUE self)
|
71
|
+
{
|
72
|
+
return CV_IS_SEQ_SIMPLE(CVSEQ(self)) ? Qtrue : Qfalse;
|
73
|
+
}
|
74
|
+
|
75
|
+
/*
|
76
|
+
* Calculates length of a curve
|
77
|
+
* @overload arc_length(slice = nil, is_closed = nil)
|
78
|
+
* @param slice [Range,CvSlice,nil] Starting and ending points of the curve.
|
79
|
+
* By default, the whole curve length is calculated.
|
80
|
+
* @param is_closed [Boolean,nil] Indicates whether the curve is closed or not.
|
81
|
+
* There are 3 cases:
|
82
|
+
* * is_closed = true - the curve is assumed to be unclosed.
|
83
|
+
* * is_closed = false - the curve is assumed to be closed.
|
84
|
+
* * is_closed = nil (default) use self#closed?
|
85
|
+
* @return [Number] Length of the curve
|
86
|
+
* @opencv_func cvArcLength
|
87
|
+
*/
|
88
|
+
VALUE
|
89
|
+
rb_arc_length(int argc, VALUE *argv, VALUE self)
|
90
|
+
{
|
91
|
+
VALUE slice, is_closed;
|
92
|
+
rb_scan_args(argc, argv, "02", &slice, &is_closed);
|
93
|
+
double length = 0;
|
94
|
+
try {
|
95
|
+
length = cvArcLength(CVARR(self),
|
96
|
+
NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice),
|
97
|
+
TRUE_OR_FALSE(is_closed, -1));
|
98
|
+
}
|
99
|
+
catch (cv::Exception& e) {
|
100
|
+
raise_cverror(e);
|
101
|
+
}
|
102
|
+
return rb_float_new(length);
|
103
|
+
}
|
104
|
+
|
105
|
+
void
|
106
|
+
init_ruby_module()
|
107
|
+
{
|
108
|
+
#if 0
|
109
|
+
// For documentation using YARD
|
110
|
+
VALUE opencv = rb_define_module("OpenCV");
|
111
|
+
#endif
|
112
|
+
|
113
|
+
if (module)
|
114
|
+
return;
|
115
|
+
|
116
|
+
VALUE opencv = rb_module_opencv();
|
117
|
+
module = rb_define_module_under(opencv, "Curve");
|
118
|
+
rb_define_method(module, "closed?", RUBY_METHOD_FUNC(rb_closed_q), 0);
|
119
|
+
rb_define_method(module, "convex?", RUBY_METHOD_FUNC(rb_convex_q), 0);
|
120
|
+
rb_define_method(module, "hole?", RUBY_METHOD_FUNC(rb_hole_q), 0);
|
121
|
+
rb_define_method(module, "simple?", RUBY_METHOD_FUNC(rb_simple_q), 0);
|
122
|
+
rb_define_method(module, "arc_length", RUBY_METHOD_FUNC(rb_arc_length), -1);
|
123
|
+
}
|
124
|
+
|
125
|
+
__NAMESPACE_END_CURVE
|
126
|
+
__NAMESPACE_END_OPENCV
|
127
|
+
|