ruby-opencv 0.0.8.pre-mswin32 → 0.0.9.pre2-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +1 -1
- data/License.txt +30 -30
- data/Manifest.txt +7 -5
- data/README.md +98 -0
- data/Rakefile +63 -5
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -21
- data/examples/find_obj.rb +169 -169
- data/examples/match_kdtree.rb +88 -88
- data/ext/opencv/cvcapture.cpp +19 -12
- data/ext/opencv/cvutils.cpp +192 -194
- data/ext/opencv/cvutils.h +30 -29
- data/{extconf.rb → ext/opencv/extconf.rb} +12 -4
- data/lib/opencv.rb +12 -3
- data/lib/opencv/psyched_yaml.rb +22 -22
- data/lib/opencv/version.rb +1 -1
- data/ruby-opencv.gemspec +44 -43
- data/test/helper.rb +1 -1
- data/test/runner.rb +30 -30
- data/test/test_curve.rb +1 -1
- data/test/test_cvavgcomp.rb +24 -24
- data/test/test_cvbox2d.rb +76 -76
- data/test/test_cvcapture.rb +183 -183
- data/test/test_cvchain.rb +108 -108
- data/test/test_cvcircle32f.rb +41 -41
- data/test/test_cvconnectedcomp.rb +61 -61
- data/test/test_cvcontour.rb +150 -150
- data/test/test_cvcontourtree.rb +43 -43
- data/test/test_cverror.rb +1 -1
- data/test/test_cvfeaturetree.rb +65 -65
- data/test/test_cvfont.rb +58 -58
- data/test/test_cvhaarclassifiercascade.rb +63 -63
- data/test/test_cvhistogram.rb +1 -1
- data/test/test_cvhumoments.rb +83 -83
- data/test/test_cvline.rb +50 -50
- data/test/test_cvmat.rb +1 -1
- data/test/test_cvmat_drawing.rb +1 -1
- data/test/test_cvmat_dxt.rb +1 -1
- data/test/test_cvmat_imageprocessing.rb +1 -1
- data/test/test_cvmat_matching.rb +1 -1
- data/test/test_cvmoments.rb +180 -180
- data/test/test_cvpoint.rb +75 -75
- data/test/test_cvpoint2d32f.rb +75 -75
- data/test/test_cvpoint3d32f.rb +93 -93
- data/test/test_cvrect.rb +144 -144
- data/test/test_cvscalar.rb +113 -113
- data/test/test_cvseq.rb +295 -295
- data/test/test_cvsize.rb +75 -75
- data/test/test_cvsize2d32f.rb +75 -75
- data/test/test_cvslice.rb +31 -31
- data/test/test_cvsurfparams.rb +57 -57
- data/test/test_cvsurfpoint.rb +66 -66
- data/test/test_cvtermcriteria.rb +56 -56
- data/test/test_cvtwopoints.rb +40 -40
- data/test/test_cvvideowriter.rb +58 -58
- data/test/test_iplconvkernel.rb +54 -54
- data/test/test_iplimage.rb +1 -1
- data/test/test_mouseevent.rb +17 -17
- data/test/test_opencv.rb +1 -1
- data/test/test_pointset.rb +1 -1
- data/test/test_preliminary.rb +130 -130
- data/test/test_trackbar.rb +47 -47
- data/test/test_window.rb +115 -115
- metadata +28 -56
- data/README.rdoc +0 -149
- data/ext/opencv/lib/opencv.rb +0 -3
- data/ext/opencv/lib/opencv/psyched_yaml.rb +0 -22
- data/ext/opencv/lib/opencv/version.rb +0 -3
data/test/test_cvrect.rb
CHANGED
@@ -1,144 +1,144 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- mode: ruby; coding: utf-8
|
3
|
-
require 'test/unit'
|
4
|
-
require 'opencv'
|
5
|
-
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
6
|
-
|
7
|
-
include OpenCV
|
8
|
-
|
9
|
-
# Tests for OpenCV::CvRect
|
10
|
-
class TestCvRect < OpenCVTestCase
|
11
|
-
class MyRect; end
|
12
|
-
|
13
|
-
def test_x
|
14
|
-
rect = CvRect.new
|
15
|
-
rect.x = 100
|
16
|
-
assert_equal(100, rect.x)
|
17
|
-
rect.x = 200
|
18
|
-
assert_equal(200, rect.x)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_y
|
22
|
-
rect = CvRect.new
|
23
|
-
rect.y = 100
|
24
|
-
assert_equal(100, rect.y)
|
25
|
-
rect.y = 200
|
26
|
-
assert_equal(200, rect.y)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_width
|
30
|
-
rect = CvRect.new
|
31
|
-
rect.width = 100
|
32
|
-
assert_equal(100, rect.width)
|
33
|
-
rect.width = 200
|
34
|
-
assert_equal(200, rect.width)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_height
|
38
|
-
rect = CvRect.new
|
39
|
-
rect.height = 100
|
40
|
-
assert_equal(100, rect.height)
|
41
|
-
rect.height = 200
|
42
|
-
assert_equal(200, rect.height)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_compatible
|
46
|
-
assert(!(CvRect.compatible? MyRect.new))
|
47
|
-
MyRect.class_eval { def x; end }
|
48
|
-
assert(!(CvRect.compatible? MyRect.new))
|
49
|
-
MyRect.class_eval { def y; end }
|
50
|
-
assert(!(CvRect.compatible? MyRect.new))
|
51
|
-
MyRect.class_eval { def width; end }
|
52
|
-
assert(!(CvRect.compatible? MyRect.new))
|
53
|
-
MyRect.class_eval { def height; end }
|
54
|
-
assert(CvRect.compatible? MyRect.new)
|
55
|
-
assert(CvRect.compatible? CvRect.new)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_initialize
|
59
|
-
rect = CvRect.new
|
60
|
-
assert_equal(0, rect.x)
|
61
|
-
assert_equal(0, rect.y)
|
62
|
-
assert_equal(0, rect.width)
|
63
|
-
assert_equal(0, rect.height)
|
64
|
-
|
65
|
-
rect = CvRect.new(10, 20, 30, 40)
|
66
|
-
assert_equal(10, rect.x)
|
67
|
-
assert_equal(20, rect.y)
|
68
|
-
assert_equal(30, rect.width)
|
69
|
-
assert_equal(40, rect.height)
|
70
|
-
|
71
|
-
rect = CvRect.new(CvRect.new(10, 20, 30, 40))
|
72
|
-
assert_equal(10, rect.x)
|
73
|
-
assert_equal(20, rect.y)
|
74
|
-
assert_equal(30, rect.width)
|
75
|
-
assert_equal(40, rect.height)
|
76
|
-
|
77
|
-
assert_raise(TypeError) {
|
78
|
-
CvRect.new(DUMMY_OBJ)
|
79
|
-
}
|
80
|
-
assert_raise(ArgumentError) {
|
81
|
-
CvRect.new(1, 2)
|
82
|
-
}
|
83
|
-
assert_raise(ArgumentError) {
|
84
|
-
CvRect.new(1, 2, 3)
|
85
|
-
}
|
86
|
-
assert_raise(ArgumentError) {
|
87
|
-
CvRect.new(1, 2, 3, 4, 5)
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_center
|
92
|
-
center = CvRect.new(10, 20, 35, 45).center
|
93
|
-
assert_in_delta(27.5, center.x, 0.01)
|
94
|
-
assert_in_delta(42.5, center.y, 0.01)
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_points
|
98
|
-
points = CvRect.new(10, 20, 35, 45).points
|
99
|
-
assert_equal(4, points.size)
|
100
|
-
assert_in_delta(10, points[0].x, 0.01)
|
101
|
-
assert_in_delta(20, points[0].y, 0.01)
|
102
|
-
assert_in_delta(10, points[1].x, 0.01)
|
103
|
-
assert_in_delta(65, points[1].y, 0.01)
|
104
|
-
assert_in_delta(45, points[2].x, 0.01)
|
105
|
-
assert_in_delta(65, points[2].y, 0.01)
|
106
|
-
assert_in_delta(45, points[3].x, 0.01)
|
107
|
-
assert_in_delta(20, points[3].y, 0.01)
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_top_left
|
111
|
-
tl = CvRect.new(10, 20, 35, 45).top_left
|
112
|
-
assert_equal(10, tl.x)
|
113
|
-
assert_equal(20, tl.y)
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_top_right
|
117
|
-
tr = CvRect.new(10, 20, 35, 45).top_right
|
118
|
-
assert_equal(45, tr.x)
|
119
|
-
assert_equal(20, tr.y)
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_bottom_left
|
123
|
-
bl = CvRect.new(10, 20, 35, 45).bottom_left
|
124
|
-
assert_equal(10, bl.x)
|
125
|
-
assert_equal(65, bl.y)
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_bottom_right
|
129
|
-
br = CvRect.new(10, 20, 35, 45).bottom_right
|
130
|
-
assert_equal(45, br.x)
|
131
|
-
assert_equal(65, br.y)
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_max_rect
|
135
|
-
rect1 = CvRect.new(10, 20, 30, 40)
|
136
|
-
rect2 = CvRect.new(30, 40, 70, 80)
|
137
|
-
rect3 = CvRect.max_rect(rect1, rect2)
|
138
|
-
assert_equal(10, rect3.x)
|
139
|
-
assert_equal(20, rect3.y)
|
140
|
-
assert_equal(90, rect3.width)
|
141
|
-
assert_equal(100, rect3.height)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
3
|
+
require 'test/unit'
|
4
|
+
require 'opencv'
|
5
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
6
|
+
|
7
|
+
include OpenCV
|
8
|
+
|
9
|
+
# Tests for OpenCV::CvRect
|
10
|
+
class TestCvRect < OpenCVTestCase
|
11
|
+
class MyRect; end
|
12
|
+
|
13
|
+
def test_x
|
14
|
+
rect = CvRect.new
|
15
|
+
rect.x = 100
|
16
|
+
assert_equal(100, rect.x)
|
17
|
+
rect.x = 200
|
18
|
+
assert_equal(200, rect.x)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_y
|
22
|
+
rect = CvRect.new
|
23
|
+
rect.y = 100
|
24
|
+
assert_equal(100, rect.y)
|
25
|
+
rect.y = 200
|
26
|
+
assert_equal(200, rect.y)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_width
|
30
|
+
rect = CvRect.new
|
31
|
+
rect.width = 100
|
32
|
+
assert_equal(100, rect.width)
|
33
|
+
rect.width = 200
|
34
|
+
assert_equal(200, rect.width)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_height
|
38
|
+
rect = CvRect.new
|
39
|
+
rect.height = 100
|
40
|
+
assert_equal(100, rect.height)
|
41
|
+
rect.height = 200
|
42
|
+
assert_equal(200, rect.height)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_compatible
|
46
|
+
assert(!(CvRect.compatible? MyRect.new))
|
47
|
+
MyRect.class_eval { def x; end }
|
48
|
+
assert(!(CvRect.compatible? MyRect.new))
|
49
|
+
MyRect.class_eval { def y; end }
|
50
|
+
assert(!(CvRect.compatible? MyRect.new))
|
51
|
+
MyRect.class_eval { def width; end }
|
52
|
+
assert(!(CvRect.compatible? MyRect.new))
|
53
|
+
MyRect.class_eval { def height; end }
|
54
|
+
assert(CvRect.compatible? MyRect.new)
|
55
|
+
assert(CvRect.compatible? CvRect.new)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_initialize
|
59
|
+
rect = CvRect.new
|
60
|
+
assert_equal(0, rect.x)
|
61
|
+
assert_equal(0, rect.y)
|
62
|
+
assert_equal(0, rect.width)
|
63
|
+
assert_equal(0, rect.height)
|
64
|
+
|
65
|
+
rect = CvRect.new(10, 20, 30, 40)
|
66
|
+
assert_equal(10, rect.x)
|
67
|
+
assert_equal(20, rect.y)
|
68
|
+
assert_equal(30, rect.width)
|
69
|
+
assert_equal(40, rect.height)
|
70
|
+
|
71
|
+
rect = CvRect.new(CvRect.new(10, 20, 30, 40))
|
72
|
+
assert_equal(10, rect.x)
|
73
|
+
assert_equal(20, rect.y)
|
74
|
+
assert_equal(30, rect.width)
|
75
|
+
assert_equal(40, rect.height)
|
76
|
+
|
77
|
+
assert_raise(TypeError) {
|
78
|
+
CvRect.new(DUMMY_OBJ)
|
79
|
+
}
|
80
|
+
assert_raise(ArgumentError) {
|
81
|
+
CvRect.new(1, 2)
|
82
|
+
}
|
83
|
+
assert_raise(ArgumentError) {
|
84
|
+
CvRect.new(1, 2, 3)
|
85
|
+
}
|
86
|
+
assert_raise(ArgumentError) {
|
87
|
+
CvRect.new(1, 2, 3, 4, 5)
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_center
|
92
|
+
center = CvRect.new(10, 20, 35, 45).center
|
93
|
+
assert_in_delta(27.5, center.x, 0.01)
|
94
|
+
assert_in_delta(42.5, center.y, 0.01)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_points
|
98
|
+
points = CvRect.new(10, 20, 35, 45).points
|
99
|
+
assert_equal(4, points.size)
|
100
|
+
assert_in_delta(10, points[0].x, 0.01)
|
101
|
+
assert_in_delta(20, points[0].y, 0.01)
|
102
|
+
assert_in_delta(10, points[1].x, 0.01)
|
103
|
+
assert_in_delta(65, points[1].y, 0.01)
|
104
|
+
assert_in_delta(45, points[2].x, 0.01)
|
105
|
+
assert_in_delta(65, points[2].y, 0.01)
|
106
|
+
assert_in_delta(45, points[3].x, 0.01)
|
107
|
+
assert_in_delta(20, points[3].y, 0.01)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_top_left
|
111
|
+
tl = CvRect.new(10, 20, 35, 45).top_left
|
112
|
+
assert_equal(10, tl.x)
|
113
|
+
assert_equal(20, tl.y)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_top_right
|
117
|
+
tr = CvRect.new(10, 20, 35, 45).top_right
|
118
|
+
assert_equal(45, tr.x)
|
119
|
+
assert_equal(20, tr.y)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_bottom_left
|
123
|
+
bl = CvRect.new(10, 20, 35, 45).bottom_left
|
124
|
+
assert_equal(10, bl.x)
|
125
|
+
assert_equal(65, bl.y)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_bottom_right
|
129
|
+
br = CvRect.new(10, 20, 35, 45).bottom_right
|
130
|
+
assert_equal(45, br.x)
|
131
|
+
assert_equal(65, br.y)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_max_rect
|
135
|
+
rect1 = CvRect.new(10, 20, 30, 40)
|
136
|
+
rect2 = CvRect.new(30, 40, 70, 80)
|
137
|
+
rect3 = CvRect.max_rect(rect1, rect2)
|
138
|
+
assert_equal(10, rect3.x)
|
139
|
+
assert_equal(20, rect3.y)
|
140
|
+
assert_equal(90, rect3.width)
|
141
|
+
assert_equal(100, rect3.height)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
data/test/test_cvscalar.rb
CHANGED
@@ -1,113 +1,113 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- mode: ruby; coding: utf-8
|
3
|
-
require 'test/unit'
|
4
|
-
require 'opencv'
|
5
|
-
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
6
|
-
|
7
|
-
include OpenCV
|
8
|
-
|
9
|
-
# Tests for OpenCV::CvScalar
|
10
|
-
class TestCvScalar < OpenCVTestCase
|
11
|
-
def test_initialize
|
12
|
-
s = CvScalar.new
|
13
|
-
assert_in_delta([0, 0, 0, 0], s, 0.01)
|
14
|
-
|
15
|
-
s = CvScalar.new(1.1)
|
16
|
-
assert_in_delta([1.1, 0, 0, 0], s, 0.01)
|
17
|
-
|
18
|
-
s = CvScalar.new(1.1, 2.2)
|
19
|
-
assert_in_delta([1.1, 2.2, 0, 0], s, 0.01)
|
20
|
-
|
21
|
-
s = CvScalar.new(1.1, 2.2, 3.3)
|
22
|
-
assert_in_delta([1.1, 2.2, 3.3, 0], s, 0.01)
|
23
|
-
|
24
|
-
s = CvScalar.new(1.1, 2.2, 3.3, 4.4)
|
25
|
-
assert_in_delta([1.1, 2.2, 3.3, 4.4], s, 0.01)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_aref
|
29
|
-
assert_in_delta([0, 0, 0, 0], CvScalar.new, 0.01)
|
30
|
-
assert_in_delta([10, 20, 30, 40], CvScalar.new(10, 20, 30, 40), 0.01)
|
31
|
-
assert_in_delta([0.1, 0.2, 0.3, 0.4], CvScalar.new(0.1, 0.2, 0.3, 0.4), 0.01)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_aset
|
35
|
-
s = CvScalar.new
|
36
|
-
[10, 20, 30, 40].each_with_index { |x, i|
|
37
|
-
s[i] = x
|
38
|
-
}
|
39
|
-
assert_in_delta([10, 20, 30, 40], s, 0.01)
|
40
|
-
|
41
|
-
s = CvScalar.new
|
42
|
-
[0.1, 0.2, 0.3, 0.4].each_with_index { |x, i|
|
43
|
-
s[i] = x
|
44
|
-
}
|
45
|
-
assert_in_delta([0.1, 0.2, 0.3, 0.4], s, 0.01)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_sub
|
49
|
-
s1 = CvScalar.new(10, 20, 30, 40)
|
50
|
-
s2 = CvScalar.new(2, 4, 6, 8)
|
51
|
-
[s1.sub(s2), s1 - s2].each { |s|
|
52
|
-
assert_in_delta([8, 16, 24, 32], s, 0.01)
|
53
|
-
}
|
54
|
-
|
55
|
-
s3 = CvScalar.new(0.2, 0.4, 0.6, 0.8)
|
56
|
-
[s2.sub(s3), s2 - s3].each { |s|
|
57
|
-
assert_in_delta([1.8, 3.6, 5.4, 7.2], s, 0.01)
|
58
|
-
}
|
59
|
-
|
60
|
-
mat = CvMat.new(5, 5)
|
61
|
-
mask = CvMat.new(5, 5, :cv8u, 1)
|
62
|
-
mat.height.times { |j|
|
63
|
-
mat.width.times { |i|
|
64
|
-
mat[i, j] = CvScalar.new(1.5)
|
65
|
-
mask[i, j] = (i < 2 and j < 3) ? 1 : 0
|
66
|
-
}
|
67
|
-
}
|
68
|
-
mat = CvScalar.new(0.1).sub(mat, mask)
|
69
|
-
|
70
|
-
[CvMat.new(5, 5, :cv16u, 1), CvMat.new(5, 5, :cv8u, 3)].each { |msk|
|
71
|
-
assert_raise(TypeError) {
|
72
|
-
CvScalar.new.sub(mat, msk)
|
73
|
-
}
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_to_s
|
78
|
-
assert_equal("<OpenCV::CvScalar:10,20,30,40>", CvScalar.new(10, 20, 30, 40).to_s)
|
79
|
-
assert_equal("<OpenCV::CvScalar:0.1,0.2,0.3,0.4>", CvScalar.new(0.1, 0.2, 0.3, 0.4).to_s)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_to_ary
|
83
|
-
[[10, 20, 30, 40], [0.1, 0.2, 0.3, 0.4]].each { |a|
|
84
|
-
s = CvScalar.new(*a)
|
85
|
-
b = s.to_ary
|
86
|
-
c = s.to_a # Alias
|
87
|
-
[b, c].each { |x|
|
88
|
-
assert_equal(Array, x.class)
|
89
|
-
assert_in_delta(a, x, 0.01)
|
90
|
-
}
|
91
|
-
}
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_cvcolor
|
95
|
-
assert_cvscalar_equal(CvColor::Black, CvScalar.new(0x0, 0x0, 0x0, 0))
|
96
|
-
assert_cvscalar_equal(CvColor::Silver, CvScalar.new(0x0c, 0x0c, 0x0c, 0))
|
97
|
-
assert_cvscalar_equal(CvColor::Gray, CvScalar.new(0x80, 0x80, 0x80, 0))
|
98
|
-
assert_cvscalar_equal(CvColor::White, CvScalar.new(0xff, 0xff, 0xff, 0))
|
99
|
-
assert_cvscalar_equal(CvColor::Maroon, CvScalar.new(0x0, 0x0, 0x80, 0))
|
100
|
-
assert_cvscalar_equal(CvColor::Red, CvScalar.new(0x0, 0x0, 0xff, 0))
|
101
|
-
assert_cvscalar_equal(CvColor::Purple, CvScalar.new(0x80, 0x0, 0x80, 0))
|
102
|
-
assert_cvscalar_equal(CvColor::Fuchsia, CvScalar.new(0xff, 0x0, 0xff, 0))
|
103
|
-
assert_cvscalar_equal(CvColor::Green, CvScalar.new(0x0, 0x80, 0x0, 0))
|
104
|
-
assert_cvscalar_equal(CvColor::Lime, CvScalar.new(0x0, 0xff, 0x0, 0))
|
105
|
-
assert_cvscalar_equal(CvColor::Olive, CvScalar.new(0x0, 0x80, 0x80, 0))
|
106
|
-
assert_cvscalar_equal(CvColor::Yellow, CvScalar.new(0x0, 0xff, 0xff, 0))
|
107
|
-
assert_cvscalar_equal(CvColor::Navy, CvScalar.new(0x80, 0x0, 0x0, 0))
|
108
|
-
assert_cvscalar_equal(CvColor::Blue, CvScalar.new(0xff, 0x0, 0x0, 0))
|
109
|
-
assert_cvscalar_equal(CvColor::Teal, CvScalar.new(0x80, 0x80, 0x0, 0))
|
110
|
-
assert_cvscalar_equal(CvColor::Aqua, CvScalar.new(0xff, 0xff, 0x0, 0))
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
3
|
+
require 'test/unit'
|
4
|
+
require 'opencv'
|
5
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
6
|
+
|
7
|
+
include OpenCV
|
8
|
+
|
9
|
+
# Tests for OpenCV::CvScalar
|
10
|
+
class TestCvScalar < OpenCVTestCase
|
11
|
+
def test_initialize
|
12
|
+
s = CvScalar.new
|
13
|
+
assert_in_delta([0, 0, 0, 0], s, 0.01)
|
14
|
+
|
15
|
+
s = CvScalar.new(1.1)
|
16
|
+
assert_in_delta([1.1, 0, 0, 0], s, 0.01)
|
17
|
+
|
18
|
+
s = CvScalar.new(1.1, 2.2)
|
19
|
+
assert_in_delta([1.1, 2.2, 0, 0], s, 0.01)
|
20
|
+
|
21
|
+
s = CvScalar.new(1.1, 2.2, 3.3)
|
22
|
+
assert_in_delta([1.1, 2.2, 3.3, 0], s, 0.01)
|
23
|
+
|
24
|
+
s = CvScalar.new(1.1, 2.2, 3.3, 4.4)
|
25
|
+
assert_in_delta([1.1, 2.2, 3.3, 4.4], s, 0.01)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_aref
|
29
|
+
assert_in_delta([0, 0, 0, 0], CvScalar.new, 0.01)
|
30
|
+
assert_in_delta([10, 20, 30, 40], CvScalar.new(10, 20, 30, 40), 0.01)
|
31
|
+
assert_in_delta([0.1, 0.2, 0.3, 0.4], CvScalar.new(0.1, 0.2, 0.3, 0.4), 0.01)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_aset
|
35
|
+
s = CvScalar.new
|
36
|
+
[10, 20, 30, 40].each_with_index { |x, i|
|
37
|
+
s[i] = x
|
38
|
+
}
|
39
|
+
assert_in_delta([10, 20, 30, 40], s, 0.01)
|
40
|
+
|
41
|
+
s = CvScalar.new
|
42
|
+
[0.1, 0.2, 0.3, 0.4].each_with_index { |x, i|
|
43
|
+
s[i] = x
|
44
|
+
}
|
45
|
+
assert_in_delta([0.1, 0.2, 0.3, 0.4], s, 0.01)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_sub
|
49
|
+
s1 = CvScalar.new(10, 20, 30, 40)
|
50
|
+
s2 = CvScalar.new(2, 4, 6, 8)
|
51
|
+
[s1.sub(s2), s1 - s2].each { |s|
|
52
|
+
assert_in_delta([8, 16, 24, 32], s, 0.01)
|
53
|
+
}
|
54
|
+
|
55
|
+
s3 = CvScalar.new(0.2, 0.4, 0.6, 0.8)
|
56
|
+
[s2.sub(s3), s2 - s3].each { |s|
|
57
|
+
assert_in_delta([1.8, 3.6, 5.4, 7.2], s, 0.01)
|
58
|
+
}
|
59
|
+
|
60
|
+
mat = CvMat.new(5, 5)
|
61
|
+
mask = CvMat.new(5, 5, :cv8u, 1)
|
62
|
+
mat.height.times { |j|
|
63
|
+
mat.width.times { |i|
|
64
|
+
mat[i, j] = CvScalar.new(1.5)
|
65
|
+
mask[i, j] = (i < 2 and j < 3) ? 1 : 0
|
66
|
+
}
|
67
|
+
}
|
68
|
+
mat = CvScalar.new(0.1).sub(mat, mask)
|
69
|
+
|
70
|
+
[CvMat.new(5, 5, :cv16u, 1), CvMat.new(5, 5, :cv8u, 3)].each { |msk|
|
71
|
+
assert_raise(TypeError) {
|
72
|
+
CvScalar.new.sub(mat, msk)
|
73
|
+
}
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_to_s
|
78
|
+
assert_equal("<OpenCV::CvScalar:10,20,30,40>", CvScalar.new(10, 20, 30, 40).to_s)
|
79
|
+
assert_equal("<OpenCV::CvScalar:0.1,0.2,0.3,0.4>", CvScalar.new(0.1, 0.2, 0.3, 0.4).to_s)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_to_ary
|
83
|
+
[[10, 20, 30, 40], [0.1, 0.2, 0.3, 0.4]].each { |a|
|
84
|
+
s = CvScalar.new(*a)
|
85
|
+
b = s.to_ary
|
86
|
+
c = s.to_a # Alias
|
87
|
+
[b, c].each { |x|
|
88
|
+
assert_equal(Array, x.class)
|
89
|
+
assert_in_delta(a, x, 0.01)
|
90
|
+
}
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_cvcolor
|
95
|
+
assert_cvscalar_equal(CvColor::Black, CvScalar.new(0x0, 0x0, 0x0, 0))
|
96
|
+
assert_cvscalar_equal(CvColor::Silver, CvScalar.new(0x0c, 0x0c, 0x0c, 0))
|
97
|
+
assert_cvscalar_equal(CvColor::Gray, CvScalar.new(0x80, 0x80, 0x80, 0))
|
98
|
+
assert_cvscalar_equal(CvColor::White, CvScalar.new(0xff, 0xff, 0xff, 0))
|
99
|
+
assert_cvscalar_equal(CvColor::Maroon, CvScalar.new(0x0, 0x0, 0x80, 0))
|
100
|
+
assert_cvscalar_equal(CvColor::Red, CvScalar.new(0x0, 0x0, 0xff, 0))
|
101
|
+
assert_cvscalar_equal(CvColor::Purple, CvScalar.new(0x80, 0x0, 0x80, 0))
|
102
|
+
assert_cvscalar_equal(CvColor::Fuchsia, CvScalar.new(0xff, 0x0, 0xff, 0))
|
103
|
+
assert_cvscalar_equal(CvColor::Green, CvScalar.new(0x0, 0x80, 0x0, 0))
|
104
|
+
assert_cvscalar_equal(CvColor::Lime, CvScalar.new(0x0, 0xff, 0x0, 0))
|
105
|
+
assert_cvscalar_equal(CvColor::Olive, CvScalar.new(0x0, 0x80, 0x80, 0))
|
106
|
+
assert_cvscalar_equal(CvColor::Yellow, CvScalar.new(0x0, 0xff, 0xff, 0))
|
107
|
+
assert_cvscalar_equal(CvColor::Navy, CvScalar.new(0x80, 0x0, 0x0, 0))
|
108
|
+
assert_cvscalar_equal(CvColor::Blue, CvScalar.new(0xff, 0x0, 0x0, 0))
|
109
|
+
assert_cvscalar_equal(CvColor::Teal, CvScalar.new(0x80, 0x80, 0x0, 0))
|
110
|
+
assert_cvscalar_equal(CvColor::Aqua, CvScalar.new(0xff, 0xff, 0x0, 0))
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|