ruby-opencv 0.0.9-x86-mswin32 → 0.0.10.pre-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/History.txt +5 -5
- data/README.md +1 -1
- data/examples/contours/contour_retrieval_modes.rb +139 -139
- data/examples/face_detect.rb +20 -20
- data/examples/houghcircle.rb +22 -22
- data/examples/paint.rb +70 -70
- data/examples/snake.rb +43 -43
- data/ext/opencv/cvcondensation.cpp +282 -282
- data/ext/opencv/cvcondensation.h +49 -49
- data/ext/opencv/cvmat.cpp +6 -6
- data/ext/opencv/cvmatnd.cpp +44 -44
- data/ext/opencv/cvmatnd.h +28 -28
- data/ext/opencv/cvmemstorage.cpp +68 -68
- data/ext/opencv/cvmemstorage.h +53 -53
- data/ext/opencv/cvmoments.h +75 -75
- data/ext/opencv/cvpoint.h +64 -64
- data/ext/opencv/cvpoint2d32f.h +63 -63
- data/ext/opencv/cvpoint3d32f.h +66 -66
- data/ext/opencv/cvrect.h +79 -79
- data/ext/opencv/cvscalar.h +71 -71
- data/ext/opencv/cvsize.h +65 -65
- data/ext/opencv/cvsize2d32f.h +64 -64
- data/ext/opencv/cvslice.h +61 -61
- data/ext/opencv/cvsparsemat.cpp +44 -44
- data/ext/opencv/cvsparsemat.h +28 -28
- data/ext/opencv/cvsurfparams.h +58 -58
- data/ext/opencv/cvsurfpoint.h +52 -52
- data/ext/opencv/cvtermcriteria.h +71 -71
- data/ext/opencv/cvtwopoints.cpp +116 -116
- data/ext/opencv/cvtwopoints.h +51 -51
- data/ext/opencv/cvvideowriter.h +43 -43
- data/ext/opencv/gui.cpp +68 -68
- data/ext/opencv/gui.h +30 -30
- data/ext/opencv/iplconvkernel.h +71 -71
- data/ext/opencv/mouseevent.cpp +181 -181
- data/ext/opencv/mouseevent.h +56 -56
- data/ext/opencv/opencv.cpp +5 -0
- data/ext/opencv/trackbar.h +69 -69
- data/ext/opencv/window.h +66 -66
- data/lib/opencv/version.rb +1 -1
- data/ruby-opencv.gemspec +7 -7
- data/test/test_cvmat_imageprocessing.rb +15 -25
- data/test/test_opencv.rb +7 -2
- metadata +7 -7
data/examples/snake.rb
CHANGED
@@ -1,43 +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
|
-
|
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
|
+
|
@@ -1,282 +1,282 @@
|
|
1
|
-
/************************************************************
|
2
|
-
|
3
|
-
cvcondensation.cpp -
|
4
|
-
|
5
|
-
$Author: lsxi $
|
6
|
-
|
7
|
-
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
-
|
9
|
-
************************************************************/
|
10
|
-
#include "cvcondensation.h"
|
11
|
-
/*
|
12
|
-
* Document-class: OpenCV::CvConDensation
|
13
|
-
*
|
14
|
-
*/
|
15
|
-
__NAMESPACE_BEGIN_OPENCV
|
16
|
-
__NAMESPACE_BEGIN_CVCONDENSATION
|
17
|
-
|
18
|
-
VALUE rb_klass;
|
19
|
-
|
20
|
-
VALUE
|
21
|
-
rb_class()
|
22
|
-
{
|
23
|
-
return rb_klass;
|
24
|
-
}
|
25
|
-
|
26
|
-
void
|
27
|
-
define_ruby_class()
|
28
|
-
{
|
29
|
-
if (rb_klass)
|
30
|
-
return;
|
31
|
-
/*
|
32
|
-
* opencv = rb_define_module("OpenCV");
|
33
|
-
*
|
34
|
-
* note: this comment is used by rdoc.
|
35
|
-
*/
|
36
|
-
VALUE opencv = rb_module_opencv();
|
37
|
-
rb_klass = rb_define_class_under(opencv, "CvConDensation", rb_cObject);
|
38
|
-
rb_define_method(rb_klass, "dp", RUBY_METHOD_FUNC(rb_dp), 0);
|
39
|
-
rb_define_method(rb_klass, "mp", RUBY_METHOD_FUNC(rb_mp), 0);
|
40
|
-
rb_define_method(rb_klass, "dynamic_matrix", RUBY_METHOD_FUNC(rb_dynamic_matrix), 0);
|
41
|
-
rb_define_method(rb_klass, "confidence", RUBY_METHOD_FUNC(rb_confidence), 0);
|
42
|
-
rb_define_method(rb_klass, "cumulative", RUBY_METHOD_FUNC(rb_cumulative), 0);
|
43
|
-
rb_define_method(rb_klass, "state", RUBY_METHOD_FUNC(rb_state), 0);
|
44
|
-
rb_define_method(rb_klass, "samples_num", RUBY_METHOD_FUNC(rb_samples_num), 0);
|
45
|
-
rb_define_method(rb_klass, "init_sample_set", RUBY_METHOD_FUNC(rb_init_sample_set), 2);
|
46
|
-
rb_define_method(rb_klass, "update_by_time", RUBY_METHOD_FUNC(rb_update_by_time), 0);
|
47
|
-
rb_define_alias(rb_klass, "update", "update_by_time");
|
48
|
-
rb_define_method(rb_klass, "each_sample", RUBY_METHOD_FUNC(rb_each_sample), 0);
|
49
|
-
rb_define_method(rb_klass, "calculate_confidence", RUBY_METHOD_FUNC(rb_calculate_confidence), 0);
|
50
|
-
}
|
51
|
-
|
52
|
-
/*
|
53
|
-
* call-seq:
|
54
|
-
* dp -> int
|
55
|
-
*
|
56
|
-
* Return dimension of state vector
|
57
|
-
*/
|
58
|
-
VALUE
|
59
|
-
rb_dp(VALUE self)
|
60
|
-
{
|
61
|
-
return INT2NUM(CVCONDENSATION(self)->DP);
|
62
|
-
}
|
63
|
-
|
64
|
-
/*
|
65
|
-
* call-seq:
|
66
|
-
* mp -> int
|
67
|
-
*
|
68
|
-
* Return demension of measurement vector.
|
69
|
-
*/
|
70
|
-
VALUE
|
71
|
-
rb_mp(VALUE self)
|
72
|
-
{
|
73
|
-
return INT2NUM(CVCONDENSATION(self)->MP);
|
74
|
-
}
|
75
|
-
|
76
|
-
/*
|
77
|
-
* call-seq:
|
78
|
-
* dynamic_matrix -> mat
|
79
|
-
*
|
80
|
-
* Return matrix of the linear Dynamics system.
|
81
|
-
*/
|
82
|
-
VALUE
|
83
|
-
rb_dynamic_matrix(VALUE self)
|
84
|
-
{
|
85
|
-
CvConDensation *cd = CVCONDENSATION(self);
|
86
|
-
CvMat* mat = NULL;
|
87
|
-
try {
|
88
|
-
mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, cd->DP, CV_MAKETYPE(CV_32F, 1), cd->DynamMatr);
|
89
|
-
}
|
90
|
-
catch (cv::Exception& e) {
|
91
|
-
raise_cverror(e);
|
92
|
-
}
|
93
|
-
return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
|
94
|
-
}
|
95
|
-
|
96
|
-
/*
|
97
|
-
* call-seq:
|
98
|
-
* confidence -> mat
|
99
|
-
*
|
100
|
-
* Return confidence for each sample.
|
101
|
-
*/
|
102
|
-
VALUE
|
103
|
-
rb_confidence(VALUE self)
|
104
|
-
{
|
105
|
-
CvConDensation *cd = CVCONDENSATION(self);
|
106
|
-
CvMat* mat = NULL;
|
107
|
-
try {
|
108
|
-
mat = cvInitMatHeader(ALLOC(CvMat), cd->SamplesNum, 1, CV_MAKETYPE(CV_32F, 1), cd->flConfidence);
|
109
|
-
}
|
110
|
-
catch (cv::Exception& e) {
|
111
|
-
raise_cverror(e);
|
112
|
-
}
|
113
|
-
return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
|
114
|
-
}
|
115
|
-
|
116
|
-
/*
|
117
|
-
* call-seq:
|
118
|
-
* cumulative -> mat
|
119
|
-
*
|
120
|
-
* Return cumulative confidence.
|
121
|
-
*/
|
122
|
-
VALUE
|
123
|
-
rb_cumulative(VALUE self)
|
124
|
-
{
|
125
|
-
CvConDensation *cd = CVCONDENSATION(self);
|
126
|
-
CvMat* mat = NULL;
|
127
|
-
try {
|
128
|
-
mat = cvInitMatHeader(ALLOC(CvMat), cd->SamplesNum, 1, CV_MAKETYPE(CV_32F, 1), cd->flCumulative);
|
129
|
-
}
|
130
|
-
catch (cv::Exception& e) {
|
131
|
-
raise_cverror(e);
|
132
|
-
}
|
133
|
-
return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
|
134
|
-
}
|
135
|
-
|
136
|
-
/*
|
137
|
-
* call-seq:
|
138
|
-
* state -> mat
|
139
|
-
*
|
140
|
-
* Return vector of state
|
141
|
-
*/
|
142
|
-
VALUE
|
143
|
-
rb_state(VALUE self)
|
144
|
-
{
|
145
|
-
CvConDensation *cd = CVCONDENSATION(self);
|
146
|
-
CvMat* mat = NULL;
|
147
|
-
try {
|
148
|
-
mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, 1, CV_MAKETYPE(CV_32F, 1), cd->State);
|
149
|
-
}
|
150
|
-
catch (cv::Exception& e) {
|
151
|
-
raise_cverror(e);
|
152
|
-
}
|
153
|
-
return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
|
154
|
-
}
|
155
|
-
|
156
|
-
/*
|
157
|
-
* call-seq:
|
158
|
-
* samples_num -> int
|
159
|
-
*
|
160
|
-
* Return number of the samples
|
161
|
-
*/
|
162
|
-
VALUE
|
163
|
-
rb_samples_num(VALUE self)
|
164
|
-
{
|
165
|
-
return INT2NUM(CVCONDENSATION(self)->SamplesNum);
|
166
|
-
}
|
167
|
-
|
168
|
-
/*
|
169
|
-
* call-seq:
|
170
|
-
* init_sample_set(upper, lower)
|
171
|
-
*
|
172
|
-
* Initializes sample set for ConDensation algorithm.
|
173
|
-
* Fills the samples with values within specified(lower to upper) ranges.
|
174
|
-
*/
|
175
|
-
VALUE
|
176
|
-
rb_init_sample_set(VALUE self, VALUE lower, VALUE upper)
|
177
|
-
{
|
178
|
-
CvConDensation *cd = CVCONDENSATION(self);
|
179
|
-
CvMat *lower_bound = CVMAT_WITH_CHECK(lower), *upper_bound = CVMAT_WITH_CHECK(upper), lb_stub, ub_stub;
|
180
|
-
int lower_type = lower_bound->type, upper_type = lower_bound->type;
|
181
|
-
try {
|
182
|
-
if (lower_type != CV_32FC1 || lower_bound->cols != 1) {
|
183
|
-
if (CV_MAT_DEPTH(lower_type) == CV_32F) {
|
184
|
-
lower_bound = cvReshape(lower_bound, &lb_stub, 1, lower_bound->rows * lower_bound->cols);
|
185
|
-
}
|
186
|
-
else {
|
187
|
-
lower = cCvMat::new_object(cvSize(lower_bound->rows * lower_bound->cols, 1), CV_MAKETYPE(CV_32S, 1));
|
188
|
-
cvConvertScale(lower_bound, CVARR(lower));
|
189
|
-
lower_bound = CVMAT(lower);
|
190
|
-
}
|
191
|
-
}
|
192
|
-
if (upper_type != CV_32FC1 || upper_bound->cols != 1) {
|
193
|
-
if (CV_MAT_DEPTH(upper_type) == CV_32F) {
|
194
|
-
upper_bound = cvReshape(upper_bound, &ub_stub, 1, upper_bound->rows * upper_bound->cols);
|
195
|
-
}
|
196
|
-
else {
|
197
|
-
upper = cCvMat::new_object(cvSize(upper_bound->rows * upper_bound->cols, 1), CV_MAKETYPE(CV_32F, 1));
|
198
|
-
cvConvertScale(upper_bound, CVARR(upper));
|
199
|
-
upper_bound = CVMAT(upper);
|
200
|
-
}
|
201
|
-
}
|
202
|
-
if (lower_bound->rows != cd->DP || upper_bound->rows != cd->DP) {
|
203
|
-
rb_raise(rb_eTypeError, "sample matrix step unmatch.");
|
204
|
-
}
|
205
|
-
cvConDensInitSampleSet(cd, lower_bound, upper_bound);
|
206
|
-
}
|
207
|
-
catch (cv::Exception& e) {
|
208
|
-
raise_cverror(e);
|
209
|
-
}
|
210
|
-
return self;
|
211
|
-
}
|
212
|
-
|
213
|
-
/*
|
214
|
-
* call-seq:
|
215
|
-
* update_by_time
|
216
|
-
*
|
217
|
-
* Estimates subsequent model state.
|
218
|
-
*/
|
219
|
-
VALUE
|
220
|
-
rb_update_by_time(VALUE self)
|
221
|
-
{
|
222
|
-
try {
|
223
|
-
cvConDensUpdateByTime(CVCONDENSATION(self));
|
224
|
-
}
|
225
|
-
catch (cv::Exception& e) {
|
226
|
-
raise_cverror(e);
|
227
|
-
}
|
228
|
-
return self;
|
229
|
-
}
|
230
|
-
|
231
|
-
/*
|
232
|
-
* call-seq:
|
233
|
-
* each_sample {|mat| ... }
|
234
|
-
*
|
235
|
-
* Evaluate each sample by given block.
|
236
|
-
*/
|
237
|
-
VALUE
|
238
|
-
rb_each_sample(VALUE self)
|
239
|
-
{
|
240
|
-
CvConDensation *cd = CVCONDENSATION(self);
|
241
|
-
if (rb_block_given_p()) {
|
242
|
-
try {
|
243
|
-
for (int i = 0; i < cd->SamplesNum; ++i) {
|
244
|
-
CvMat* mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, 1, CV_MAKETYPE(CV_32F, 1), cd->flSamples[i]);
|
245
|
-
rb_yield(DEPEND_OBJECT(cCvMat::rb_class(), mat, self));
|
246
|
-
}
|
247
|
-
}
|
248
|
-
catch (cv::Exception& e) {
|
249
|
-
raise_cverror(e);
|
250
|
-
}
|
251
|
-
}
|
252
|
-
return self;
|
253
|
-
}
|
254
|
-
|
255
|
-
/*
|
256
|
-
* call-seq:
|
257
|
-
* calculate_confidence {|value| ... }
|
258
|
-
*
|
259
|
-
* Evalute each sample by given block, then return value set to confidence.
|
260
|
-
*/
|
261
|
-
VALUE
|
262
|
-
rb_calculate_confidence(VALUE self)
|
263
|
-
{
|
264
|
-
VALUE value;
|
265
|
-
CvConDensation *cd = CVCONDENSATION(self);
|
266
|
-
if (rb_block_given_p()) {
|
267
|
-
try {
|
268
|
-
for (int i = 0; i < cd->SamplesNum; ++i) {
|
269
|
-
CvMat* mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, 1, CV_MAKETYPE(CV_32F, 1), cd->flSamples[i]);
|
270
|
-
value = rb_yield(DEPEND_OBJECT(cCvMat::rb_class(), mat, self));
|
271
|
-
cd->flConfidence[i] = NUM2DBL(value);
|
272
|
-
}
|
273
|
-
}
|
274
|
-
catch (cv::Exception& e) {
|
275
|
-
raise_cverror(e);
|
276
|
-
}
|
277
|
-
}
|
278
|
-
return self;
|
279
|
-
}
|
280
|
-
|
281
|
-
__NAMESPACE_END_CVCONDENSATION
|
282
|
-
__NAMESPACE_END_OPENCV
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvcondensation.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvcondensation.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvConDensation
|
13
|
+
*
|
14
|
+
*/
|
15
|
+
__NAMESPACE_BEGIN_OPENCV
|
16
|
+
__NAMESPACE_BEGIN_CVCONDENSATION
|
17
|
+
|
18
|
+
VALUE rb_klass;
|
19
|
+
|
20
|
+
VALUE
|
21
|
+
rb_class()
|
22
|
+
{
|
23
|
+
return rb_klass;
|
24
|
+
}
|
25
|
+
|
26
|
+
void
|
27
|
+
define_ruby_class()
|
28
|
+
{
|
29
|
+
if (rb_klass)
|
30
|
+
return;
|
31
|
+
/*
|
32
|
+
* opencv = rb_define_module("OpenCV");
|
33
|
+
*
|
34
|
+
* note: this comment is used by rdoc.
|
35
|
+
*/
|
36
|
+
VALUE opencv = rb_module_opencv();
|
37
|
+
rb_klass = rb_define_class_under(opencv, "CvConDensation", rb_cObject);
|
38
|
+
rb_define_method(rb_klass, "dp", RUBY_METHOD_FUNC(rb_dp), 0);
|
39
|
+
rb_define_method(rb_klass, "mp", RUBY_METHOD_FUNC(rb_mp), 0);
|
40
|
+
rb_define_method(rb_klass, "dynamic_matrix", RUBY_METHOD_FUNC(rb_dynamic_matrix), 0);
|
41
|
+
rb_define_method(rb_klass, "confidence", RUBY_METHOD_FUNC(rb_confidence), 0);
|
42
|
+
rb_define_method(rb_klass, "cumulative", RUBY_METHOD_FUNC(rb_cumulative), 0);
|
43
|
+
rb_define_method(rb_klass, "state", RUBY_METHOD_FUNC(rb_state), 0);
|
44
|
+
rb_define_method(rb_klass, "samples_num", RUBY_METHOD_FUNC(rb_samples_num), 0);
|
45
|
+
rb_define_method(rb_klass, "init_sample_set", RUBY_METHOD_FUNC(rb_init_sample_set), 2);
|
46
|
+
rb_define_method(rb_klass, "update_by_time", RUBY_METHOD_FUNC(rb_update_by_time), 0);
|
47
|
+
rb_define_alias(rb_klass, "update", "update_by_time");
|
48
|
+
rb_define_method(rb_klass, "each_sample", RUBY_METHOD_FUNC(rb_each_sample), 0);
|
49
|
+
rb_define_method(rb_klass, "calculate_confidence", RUBY_METHOD_FUNC(rb_calculate_confidence), 0);
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* call-seq:
|
54
|
+
* dp -> int
|
55
|
+
*
|
56
|
+
* Return dimension of state vector
|
57
|
+
*/
|
58
|
+
VALUE
|
59
|
+
rb_dp(VALUE self)
|
60
|
+
{
|
61
|
+
return INT2NUM(CVCONDENSATION(self)->DP);
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
* call-seq:
|
66
|
+
* mp -> int
|
67
|
+
*
|
68
|
+
* Return demension of measurement vector.
|
69
|
+
*/
|
70
|
+
VALUE
|
71
|
+
rb_mp(VALUE self)
|
72
|
+
{
|
73
|
+
return INT2NUM(CVCONDENSATION(self)->MP);
|
74
|
+
}
|
75
|
+
|
76
|
+
/*
|
77
|
+
* call-seq:
|
78
|
+
* dynamic_matrix -> mat
|
79
|
+
*
|
80
|
+
* Return matrix of the linear Dynamics system.
|
81
|
+
*/
|
82
|
+
VALUE
|
83
|
+
rb_dynamic_matrix(VALUE self)
|
84
|
+
{
|
85
|
+
CvConDensation *cd = CVCONDENSATION(self);
|
86
|
+
CvMat* mat = NULL;
|
87
|
+
try {
|
88
|
+
mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, cd->DP, CV_MAKETYPE(CV_32F, 1), cd->DynamMatr);
|
89
|
+
}
|
90
|
+
catch (cv::Exception& e) {
|
91
|
+
raise_cverror(e);
|
92
|
+
}
|
93
|
+
return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
* call-seq:
|
98
|
+
* confidence -> mat
|
99
|
+
*
|
100
|
+
* Return confidence for each sample.
|
101
|
+
*/
|
102
|
+
VALUE
|
103
|
+
rb_confidence(VALUE self)
|
104
|
+
{
|
105
|
+
CvConDensation *cd = CVCONDENSATION(self);
|
106
|
+
CvMat* mat = NULL;
|
107
|
+
try {
|
108
|
+
mat = cvInitMatHeader(ALLOC(CvMat), cd->SamplesNum, 1, CV_MAKETYPE(CV_32F, 1), cd->flConfidence);
|
109
|
+
}
|
110
|
+
catch (cv::Exception& e) {
|
111
|
+
raise_cverror(e);
|
112
|
+
}
|
113
|
+
return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
|
114
|
+
}
|
115
|
+
|
116
|
+
/*
|
117
|
+
* call-seq:
|
118
|
+
* cumulative -> mat
|
119
|
+
*
|
120
|
+
* Return cumulative confidence.
|
121
|
+
*/
|
122
|
+
VALUE
|
123
|
+
rb_cumulative(VALUE self)
|
124
|
+
{
|
125
|
+
CvConDensation *cd = CVCONDENSATION(self);
|
126
|
+
CvMat* mat = NULL;
|
127
|
+
try {
|
128
|
+
mat = cvInitMatHeader(ALLOC(CvMat), cd->SamplesNum, 1, CV_MAKETYPE(CV_32F, 1), cd->flCumulative);
|
129
|
+
}
|
130
|
+
catch (cv::Exception& e) {
|
131
|
+
raise_cverror(e);
|
132
|
+
}
|
133
|
+
return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
|
134
|
+
}
|
135
|
+
|
136
|
+
/*
|
137
|
+
* call-seq:
|
138
|
+
* state -> mat
|
139
|
+
*
|
140
|
+
* Return vector of state
|
141
|
+
*/
|
142
|
+
VALUE
|
143
|
+
rb_state(VALUE self)
|
144
|
+
{
|
145
|
+
CvConDensation *cd = CVCONDENSATION(self);
|
146
|
+
CvMat* mat = NULL;
|
147
|
+
try {
|
148
|
+
mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, 1, CV_MAKETYPE(CV_32F, 1), cd->State);
|
149
|
+
}
|
150
|
+
catch (cv::Exception& e) {
|
151
|
+
raise_cverror(e);
|
152
|
+
}
|
153
|
+
return DEPEND_OBJECT(cCvMat::rb_class(), mat, self);
|
154
|
+
}
|
155
|
+
|
156
|
+
/*
|
157
|
+
* call-seq:
|
158
|
+
* samples_num -> int
|
159
|
+
*
|
160
|
+
* Return number of the samples
|
161
|
+
*/
|
162
|
+
VALUE
|
163
|
+
rb_samples_num(VALUE self)
|
164
|
+
{
|
165
|
+
return INT2NUM(CVCONDENSATION(self)->SamplesNum);
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* call-seq:
|
170
|
+
* init_sample_set(upper, lower)
|
171
|
+
*
|
172
|
+
* Initializes sample set for ConDensation algorithm.
|
173
|
+
* Fills the samples with values within specified(lower to upper) ranges.
|
174
|
+
*/
|
175
|
+
VALUE
|
176
|
+
rb_init_sample_set(VALUE self, VALUE lower, VALUE upper)
|
177
|
+
{
|
178
|
+
CvConDensation *cd = CVCONDENSATION(self);
|
179
|
+
CvMat *lower_bound = CVMAT_WITH_CHECK(lower), *upper_bound = CVMAT_WITH_CHECK(upper), lb_stub, ub_stub;
|
180
|
+
int lower_type = lower_bound->type, upper_type = lower_bound->type;
|
181
|
+
try {
|
182
|
+
if (lower_type != CV_32FC1 || lower_bound->cols != 1) {
|
183
|
+
if (CV_MAT_DEPTH(lower_type) == CV_32F) {
|
184
|
+
lower_bound = cvReshape(lower_bound, &lb_stub, 1, lower_bound->rows * lower_bound->cols);
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
lower = cCvMat::new_object(cvSize(lower_bound->rows * lower_bound->cols, 1), CV_MAKETYPE(CV_32S, 1));
|
188
|
+
cvConvertScale(lower_bound, CVARR(lower));
|
189
|
+
lower_bound = CVMAT(lower);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
if (upper_type != CV_32FC1 || upper_bound->cols != 1) {
|
193
|
+
if (CV_MAT_DEPTH(upper_type) == CV_32F) {
|
194
|
+
upper_bound = cvReshape(upper_bound, &ub_stub, 1, upper_bound->rows * upper_bound->cols);
|
195
|
+
}
|
196
|
+
else {
|
197
|
+
upper = cCvMat::new_object(cvSize(upper_bound->rows * upper_bound->cols, 1), CV_MAKETYPE(CV_32F, 1));
|
198
|
+
cvConvertScale(upper_bound, CVARR(upper));
|
199
|
+
upper_bound = CVMAT(upper);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
if (lower_bound->rows != cd->DP || upper_bound->rows != cd->DP) {
|
203
|
+
rb_raise(rb_eTypeError, "sample matrix step unmatch.");
|
204
|
+
}
|
205
|
+
cvConDensInitSampleSet(cd, lower_bound, upper_bound);
|
206
|
+
}
|
207
|
+
catch (cv::Exception& e) {
|
208
|
+
raise_cverror(e);
|
209
|
+
}
|
210
|
+
return self;
|
211
|
+
}
|
212
|
+
|
213
|
+
/*
|
214
|
+
* call-seq:
|
215
|
+
* update_by_time
|
216
|
+
*
|
217
|
+
* Estimates subsequent model state.
|
218
|
+
*/
|
219
|
+
VALUE
|
220
|
+
rb_update_by_time(VALUE self)
|
221
|
+
{
|
222
|
+
try {
|
223
|
+
cvConDensUpdateByTime(CVCONDENSATION(self));
|
224
|
+
}
|
225
|
+
catch (cv::Exception& e) {
|
226
|
+
raise_cverror(e);
|
227
|
+
}
|
228
|
+
return self;
|
229
|
+
}
|
230
|
+
|
231
|
+
/*
|
232
|
+
* call-seq:
|
233
|
+
* each_sample {|mat| ... }
|
234
|
+
*
|
235
|
+
* Evaluate each sample by given block.
|
236
|
+
*/
|
237
|
+
VALUE
|
238
|
+
rb_each_sample(VALUE self)
|
239
|
+
{
|
240
|
+
CvConDensation *cd = CVCONDENSATION(self);
|
241
|
+
if (rb_block_given_p()) {
|
242
|
+
try {
|
243
|
+
for (int i = 0; i < cd->SamplesNum; ++i) {
|
244
|
+
CvMat* mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, 1, CV_MAKETYPE(CV_32F, 1), cd->flSamples[i]);
|
245
|
+
rb_yield(DEPEND_OBJECT(cCvMat::rb_class(), mat, self));
|
246
|
+
}
|
247
|
+
}
|
248
|
+
catch (cv::Exception& e) {
|
249
|
+
raise_cverror(e);
|
250
|
+
}
|
251
|
+
}
|
252
|
+
return self;
|
253
|
+
}
|
254
|
+
|
255
|
+
/*
|
256
|
+
* call-seq:
|
257
|
+
* calculate_confidence {|value| ... }
|
258
|
+
*
|
259
|
+
* Evalute each sample by given block, then return value set to confidence.
|
260
|
+
*/
|
261
|
+
VALUE
|
262
|
+
rb_calculate_confidence(VALUE self)
|
263
|
+
{
|
264
|
+
VALUE value;
|
265
|
+
CvConDensation *cd = CVCONDENSATION(self);
|
266
|
+
if (rb_block_given_p()) {
|
267
|
+
try {
|
268
|
+
for (int i = 0; i < cd->SamplesNum; ++i) {
|
269
|
+
CvMat* mat = cvInitMatHeader(ALLOC(CvMat), cd->DP, 1, CV_MAKETYPE(CV_32F, 1), cd->flSamples[i]);
|
270
|
+
value = rb_yield(DEPEND_OBJECT(cCvMat::rb_class(), mat, self));
|
271
|
+
cd->flConfidence[i] = NUM2DBL(value);
|
272
|
+
}
|
273
|
+
}
|
274
|
+
catch (cv::Exception& e) {
|
275
|
+
raise_cverror(e);
|
276
|
+
}
|
277
|
+
}
|
278
|
+
return self;
|
279
|
+
}
|
280
|
+
|
281
|
+
__NAMESPACE_END_CVCONDENSATION
|
282
|
+
__NAMESPACE_END_OPENCV
|