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_cvhistogram.rb
CHANGED
data/test/test_cvhumoments.rb
CHANGED
@@ -1,83 +1,83 @@
|
|
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::CvHuMoment
|
10
|
-
class TestCvHuMoments < OpenCVTestCase
|
11
|
-
def setup
|
12
|
-
@mat = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
13
|
-
if j >= 32 and j < 96 and i >= 16 and i < 112
|
14
|
-
CvScalar.new(0)
|
15
|
-
elsif j >= 16 and j < 112 and i >= 16 and i < 112
|
16
|
-
CvScalar.new(128)
|
17
|
-
else
|
18
|
-
CvScalar.new(255)
|
19
|
-
end
|
20
|
-
}
|
21
|
-
@moment1 = CvMoments.new
|
22
|
-
@moment2 = CvMoments.new(nil, true)
|
23
|
-
@moment3 = CvMoments.new(@mat)
|
24
|
-
@moment4 = CvMoments.new(@mat, true)
|
25
|
-
|
26
|
-
@hu_moments1 = CvHuMoments.new(@moment1)
|
27
|
-
@hu_moments2 = CvHuMoments.new(@moment2)
|
28
|
-
@hu_moments3 = CvHuMoments.new(@moment3)
|
29
|
-
@hu_moments4 = CvHuMoments.new(@moment4)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_initialize
|
33
|
-
[@hu_moments1, @hu_moments2, @hu_moments3, @hu_moments4].each { |m|
|
34
|
-
assert_not_nil(m)
|
35
|
-
assert_equal(CvHuMoments, m.class)
|
36
|
-
}
|
37
|
-
|
38
|
-
assert_raise(TypeError) {
|
39
|
-
CvHuMoments.new('foo')
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_huX
|
44
|
-
hu_moments = [@hu_moments1.hu1, @hu_moments1.hu2, @hu_moments1.hu3, @hu_moments1.hu4,
|
45
|
-
@hu_moments1.hu5, @hu_moments1.hu6, @hu_moments1.hu7]
|
46
|
-
hu_moments.each { |hu|
|
47
|
-
assert_in_delta(0.0, hu, 0.000001)
|
48
|
-
}
|
49
|
-
|
50
|
-
hu_moments = [@hu_moments2.hu1, @hu_moments2.hu2, @hu_moments2.hu3, @hu_moments2.hu4,
|
51
|
-
@hu_moments2.hu5, @hu_moments2.hu6, @hu_moments2.hu7]
|
52
|
-
hu_moments.each { |hu|
|
53
|
-
assert_in_delta(0.0, hu, 0.000001)
|
54
|
-
}
|
55
|
-
|
56
|
-
hu_moments = [@hu_moments3.hu2, @hu_moments3.hu3, @hu_moments3.hu4,
|
57
|
-
@hu_moments3.hu5, @hu_moments3.hu6, @hu_moments3.hu7]
|
58
|
-
assert_in_delta(0.001771, @hu_moments3.hu1, 0.000001)
|
59
|
-
hu_moments.each { |hu|
|
60
|
-
assert_in_delta(0.0, hu, 0.000001)
|
61
|
-
}
|
62
|
-
|
63
|
-
hu_moments = [@hu_moments4.hu3, @hu_moments4.hu4,
|
64
|
-
@hu_moments4.hu5, @hu_moments4.hu6, @hu_moments4.hu7]
|
65
|
-
assert_in_delta(0.361650, @hu_moments4.hu1, 0.000001)
|
66
|
-
assert_in_delta(0.000625, @hu_moments4.hu2, 0.000001)
|
67
|
-
hu_moments.each { |hu|
|
68
|
-
assert_in_delta(0.0, hu, 0.000001)
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_to_ary
|
73
|
-
[@hu_moments4.to_ary, @hu_moments4.to_a].each { |hu_moments|
|
74
|
-
assert_equal(7, hu_moments.size)
|
75
|
-
assert_in_delta(0.361650, hu_moments[0], 0.000001)
|
76
|
-
assert_in_delta(0.000625, hu_moments[1], 0.000001)
|
77
|
-
hu_moments[2..7].each { |hu|
|
78
|
-
assert_in_delta(0.0, hu, 0.000001)
|
79
|
-
}
|
80
|
-
}
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
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::CvHuMoment
|
10
|
+
class TestCvHuMoments < OpenCVTestCase
|
11
|
+
def setup
|
12
|
+
@mat = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
13
|
+
if j >= 32 and j < 96 and i >= 16 and i < 112
|
14
|
+
CvScalar.new(0)
|
15
|
+
elsif j >= 16 and j < 112 and i >= 16 and i < 112
|
16
|
+
CvScalar.new(128)
|
17
|
+
else
|
18
|
+
CvScalar.new(255)
|
19
|
+
end
|
20
|
+
}
|
21
|
+
@moment1 = CvMoments.new
|
22
|
+
@moment2 = CvMoments.new(nil, true)
|
23
|
+
@moment3 = CvMoments.new(@mat)
|
24
|
+
@moment4 = CvMoments.new(@mat, true)
|
25
|
+
|
26
|
+
@hu_moments1 = CvHuMoments.new(@moment1)
|
27
|
+
@hu_moments2 = CvHuMoments.new(@moment2)
|
28
|
+
@hu_moments3 = CvHuMoments.new(@moment3)
|
29
|
+
@hu_moments4 = CvHuMoments.new(@moment4)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_initialize
|
33
|
+
[@hu_moments1, @hu_moments2, @hu_moments3, @hu_moments4].each { |m|
|
34
|
+
assert_not_nil(m)
|
35
|
+
assert_equal(CvHuMoments, m.class)
|
36
|
+
}
|
37
|
+
|
38
|
+
assert_raise(TypeError) {
|
39
|
+
CvHuMoments.new('foo')
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_huX
|
44
|
+
hu_moments = [@hu_moments1.hu1, @hu_moments1.hu2, @hu_moments1.hu3, @hu_moments1.hu4,
|
45
|
+
@hu_moments1.hu5, @hu_moments1.hu6, @hu_moments1.hu7]
|
46
|
+
hu_moments.each { |hu|
|
47
|
+
assert_in_delta(0.0, hu, 0.000001)
|
48
|
+
}
|
49
|
+
|
50
|
+
hu_moments = [@hu_moments2.hu1, @hu_moments2.hu2, @hu_moments2.hu3, @hu_moments2.hu4,
|
51
|
+
@hu_moments2.hu5, @hu_moments2.hu6, @hu_moments2.hu7]
|
52
|
+
hu_moments.each { |hu|
|
53
|
+
assert_in_delta(0.0, hu, 0.000001)
|
54
|
+
}
|
55
|
+
|
56
|
+
hu_moments = [@hu_moments3.hu2, @hu_moments3.hu3, @hu_moments3.hu4,
|
57
|
+
@hu_moments3.hu5, @hu_moments3.hu6, @hu_moments3.hu7]
|
58
|
+
assert_in_delta(0.001771, @hu_moments3.hu1, 0.000001)
|
59
|
+
hu_moments.each { |hu|
|
60
|
+
assert_in_delta(0.0, hu, 0.000001)
|
61
|
+
}
|
62
|
+
|
63
|
+
hu_moments = [@hu_moments4.hu3, @hu_moments4.hu4,
|
64
|
+
@hu_moments4.hu5, @hu_moments4.hu6, @hu_moments4.hu7]
|
65
|
+
assert_in_delta(0.361650, @hu_moments4.hu1, 0.000001)
|
66
|
+
assert_in_delta(0.000625, @hu_moments4.hu2, 0.000001)
|
67
|
+
hu_moments.each { |hu|
|
68
|
+
assert_in_delta(0.0, hu, 0.000001)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_to_ary
|
73
|
+
[@hu_moments4.to_ary, @hu_moments4.to_a].each { |hu_moments|
|
74
|
+
assert_equal(7, hu_moments.size)
|
75
|
+
assert_in_delta(0.361650, hu_moments[0], 0.000001)
|
76
|
+
assert_in_delta(0.000625, hu_moments[1], 0.000001)
|
77
|
+
hu_moments[2..7].each { |hu|
|
78
|
+
assert_in_delta(0.0, hu, 0.000001)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
data/test/test_cvline.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
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::CvLine
|
10
|
-
class TestCvLine < OpenCVTestCase
|
11
|
-
def setup
|
12
|
-
@line = CvLine.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_initialize
|
16
|
-
assert_not_nil(@line)
|
17
|
-
assert_equal(CvLine, @line.class)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_rho
|
21
|
-
@line.rho = 0.0
|
22
|
-
assert_in_delta(0.0, @line.rho, 0.001)
|
23
|
-
@line.rho = 3.14
|
24
|
-
assert_in_delta(3.14, @line.rho, 0.001)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_theta
|
28
|
-
@line.theta = 0.0
|
29
|
-
assert_in_delta(0.0, @line.theta, 0.001)
|
30
|
-
@line.theta = 3.14
|
31
|
-
assert_in_delta(3.14, @line.theta, 0.001)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_aref_aset
|
35
|
-
@line[0] = 0.0
|
36
|
-
@line[1] = 0.0
|
37
|
-
assert_in_delta(0.0, @line[0], 0.001)
|
38
|
-
assert_in_delta(0.0, @line[1], 0.001)
|
39
|
-
|
40
|
-
@line[0] = 3.14
|
41
|
-
@line[1] = 2.71
|
42
|
-
assert_in_delta(3.14, @line[0], 0.001)
|
43
|
-
assert_in_delta(2.71, @line[1], 0.001)
|
44
|
-
|
45
|
-
assert_raise(IndexError) {
|
46
|
-
@line[2] = 1
|
47
|
-
}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
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::CvLine
|
10
|
+
class TestCvLine < OpenCVTestCase
|
11
|
+
def setup
|
12
|
+
@line = CvLine.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialize
|
16
|
+
assert_not_nil(@line)
|
17
|
+
assert_equal(CvLine, @line.class)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_rho
|
21
|
+
@line.rho = 0.0
|
22
|
+
assert_in_delta(0.0, @line.rho, 0.001)
|
23
|
+
@line.rho = 3.14
|
24
|
+
assert_in_delta(3.14, @line.rho, 0.001)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_theta
|
28
|
+
@line.theta = 0.0
|
29
|
+
assert_in_delta(0.0, @line.theta, 0.001)
|
30
|
+
@line.theta = 3.14
|
31
|
+
assert_in_delta(3.14, @line.theta, 0.001)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_aref_aset
|
35
|
+
@line[0] = 0.0
|
36
|
+
@line[1] = 0.0
|
37
|
+
assert_in_delta(0.0, @line[0], 0.001)
|
38
|
+
assert_in_delta(0.0, @line[1], 0.001)
|
39
|
+
|
40
|
+
@line[0] = 3.14
|
41
|
+
@line[1] = 2.71
|
42
|
+
assert_in_delta(3.14, @line[0], 0.001)
|
43
|
+
assert_in_delta(2.71, @line[1], 0.001)
|
44
|
+
|
45
|
+
assert_raise(IndexError) {
|
46
|
+
@line[2] = 1
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/test/test_cvmat.rb
CHANGED
data/test/test_cvmat_drawing.rb
CHANGED
data/test/test_cvmat_dxt.rb
CHANGED
data/test/test_cvmat_matching.rb
CHANGED
data/test/test_cvmoments.rb
CHANGED
@@ -1,180 +1,180 @@
|
|
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::CvMoment
|
10
|
-
class TestCvMoments < OpenCVTestCase
|
11
|
-
def setup
|
12
|
-
@mat = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
13
|
-
if j >= 32 and j < 96 and i >= 16 and i < 112
|
14
|
-
CvScalar.new(0)
|
15
|
-
elsif j >= 16 and j < 112 and i >= 16 and i < 112
|
16
|
-
CvScalar.new(128)
|
17
|
-
else
|
18
|
-
CvScalar.new(255)
|
19
|
-
end
|
20
|
-
}
|
21
|
-
@moment1 = CvMoments.new
|
22
|
-
@moment2 = CvMoments.new(nil, true)
|
23
|
-
@moment3 = CvMoments.new(@mat)
|
24
|
-
@moment4 = CvMoments.new(@mat, true)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_initialize
|
28
|
-
[@moment1, @moment2, @moment3, @moment4].each { |m|
|
29
|
-
assert_not_nil(m)
|
30
|
-
assert_equal(CvMoments, m.class)
|
31
|
-
}
|
32
|
-
|
33
|
-
assert_raise(TypeError) {
|
34
|
-
CvMoments.new('foo')
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_spatial
|
39
|
-
assert_in_delta(0, @moment1.spatial(0, 0), 0.1)
|
40
|
-
assert_in_delta(0, @moment2.spatial(0, 0), 0.1)
|
41
|
-
assert_in_delta(2221056, @moment3.spatial(0, 0), 0.1)
|
42
|
-
assert_in_delta(10240, @moment4.spatial(0, 0), 0.1)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_central
|
46
|
-
assert_in_delta(0, @moment1.central(0, 0), 0.1)
|
47
|
-
assert_in_delta(0, @moment2.central(0, 0), 0.1)
|
48
|
-
assert_in_delta(2221056, @moment3.central(0, 0), 0.1)
|
49
|
-
assert_in_delta(10240, @moment4.central(0, 0), 0.1)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_normalized_central
|
53
|
-
assert_in_delta(0, @moment1.normalized_central(0, 0), 0.1)
|
54
|
-
assert_in_delta(0, @moment2.normalized_central(0, 0), 0.1)
|
55
|
-
assert_in_delta(1, @moment3.normalized_central(0, 0), 0.1)
|
56
|
-
assert_in_delta(1, @moment4.normalized_central(0, 0), 0.1)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_hu
|
60
|
-
hu_moments = @moment1.hu
|
61
|
-
assert_equal(CvHuMoments, hu_moments.class)
|
62
|
-
hu_moments.to_a.each { |hu|
|
63
|
-
assert_in_delta(0.0, hu, 0.000001)
|
64
|
-
}
|
65
|
-
|
66
|
-
hu_moments = @moment2.hu
|
67
|
-
assert_equal(CvHuMoments, hu_moments.class)
|
68
|
-
hu_moments.to_a.each { |hu|
|
69
|
-
assert_in_delta(0.0, hu, 0.000001)
|
70
|
-
}
|
71
|
-
|
72
|
-
hu_moments = @moment3.hu
|
73
|
-
assert_equal(CvHuMoments, hu_moments.class)
|
74
|
-
assert_in_delta(0.001771, hu_moments.hu1, 0.000001)
|
75
|
-
hu_moments.to_a[1..7].each { |hu|
|
76
|
-
assert_in_delta(0.0, hu, 0.000001)
|
77
|
-
}
|
78
|
-
|
79
|
-
hu_moments = @moment4.hu
|
80
|
-
assert_equal(CvHuMoments, hu_moments.class)
|
81
|
-
assert_in_delta(0.361650, hu_moments.hu1, 0.000001)
|
82
|
-
assert_in_delta(0.000625, hu_moments.hu2, 0.000001)
|
83
|
-
hu_moments.to_a[2..7].each { |hu|
|
84
|
-
assert_in_delta(0.0, hu, 0.000001)
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_gravity_center
|
89
|
-
center = @moment1.gravity_center
|
90
|
-
assert_equal(CvPoint2D32f, center.class)
|
91
|
-
assert(center.x.nan?)
|
92
|
-
assert(center.y.nan?)
|
93
|
-
|
94
|
-
center = @moment2.gravity_center
|
95
|
-
assert_equal(CvPoint2D32f, center.class)
|
96
|
-
assert(center.x.nan?)
|
97
|
-
assert(center.y.nan?)
|
98
|
-
|
99
|
-
center = @moment3.gravity_center
|
100
|
-
assert_equal(CvPoint2D32f, center.class)
|
101
|
-
assert_in_delta(63.5, center.x, 0.001)
|
102
|
-
assert_in_delta(63.5, center.y, 0.001)
|
103
|
-
|
104
|
-
center = @moment4.gravity_center
|
105
|
-
assert_equal(CvPoint2D32f, center.class)
|
106
|
-
assert_in_delta(63.5, center.x, 0.001)
|
107
|
-
assert_in_delta(63.5, center.y, 0.001)
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_angle
|
111
|
-
[@moment1, @moment2].each { |m|
|
112
|
-
assert_nil(m.angle)
|
113
|
-
}
|
114
|
-
[@moment3, @moment4].each { |m|
|
115
|
-
assert_in_delta(0, m.angle, 0.001)
|
116
|
-
}
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_mXX
|
120
|
-
[@moment1, @moment2].each { |m|
|
121
|
-
assert_in_delta(0, m.m00, 0.001)
|
122
|
-
assert_in_delta(0, m.m10, 0.001)
|
123
|
-
assert_in_delta(0, m.m01, 0.001)
|
124
|
-
assert_in_delta(0, m.m20, 0.001)
|
125
|
-
assert_in_delta(0, m.m11, 0.001)
|
126
|
-
assert_in_delta(0, m.m02, 0.001)
|
127
|
-
assert_in_delta(0, m.m30, 0.001)
|
128
|
-
assert_in_delta(0, m.m21, 0.001)
|
129
|
-
assert_in_delta(0, m.m12, 0.001)
|
130
|
-
assert_in_delta(0, m.m03, 0.001)
|
131
|
-
assert_in_delta(0, m.mu20, 0.001)
|
132
|
-
assert_in_delta(0, m.mu11, 0.001)
|
133
|
-
assert_in_delta(0, m.mu02, 0.001)
|
134
|
-
assert_in_delta(0, m.mu30, 0.001)
|
135
|
-
assert_in_delta(0, m.mu21, 0.001)
|
136
|
-
assert_in_delta(0, m.mu12, 0.001)
|
137
|
-
assert_in_delta(0, m.mu03, 0.001)
|
138
|
-
assert_in_delta(0, m.inv_sqrt_m00, 0.001)
|
139
|
-
}
|
140
|
-
|
141
|
-
assert_in_delta(2221056, @moment3.m00, 0.001)
|
142
|
-
assert_in_delta(141037056, @moment3.m10, 0.001)
|
143
|
-
assert_in_delta(141037056, @moment3.m01, 0.001)
|
144
|
-
assert_in_delta(13157049856, @moment3.m20, 0.001)
|
145
|
-
assert_in_delta(8955853056, @moment3.m11, 0.001)
|
146
|
-
assert_in_delta(13492594176, @moment3.m02, 0.001)
|
147
|
-
assert_in_delta(1369024659456, @moment3.m30, 0.001)
|
148
|
-
assert_in_delta(835472665856, @moment3.m21, 0.001)
|
149
|
-
assert_in_delta(856779730176, @moment3.m12, 0.001)
|
150
|
-
assert_in_delta(1432945852416, @moment3.m03, 0.001)
|
151
|
-
assert_in_delta(4201196800, @moment3.mu20, 0.001)
|
152
|
-
assert_in_delta(0, @moment3.mu11, 0.001)
|
153
|
-
assert_in_delta(4536741120, @moment3.mu02, 0.001)
|
154
|
-
assert_in_delta(0, @moment3.mu30, 0.001)
|
155
|
-
assert_in_delta(0, @moment3.mu21, 0.001)
|
156
|
-
assert_in_delta(0, @moment3.mu12, 0.001)
|
157
|
-
assert_in_delta(0, @moment3.mu03, 0.001)
|
158
|
-
assert_in_delta(0.000671, @moment3.inv_sqrt_m00, 0.000001)
|
159
|
-
|
160
|
-
assert_in_delta(10240, @moment4.m00, 0.001)
|
161
|
-
assert_in_delta(650240, @moment4.m10, 0.001)
|
162
|
-
assert_in_delta(650240, @moment4.m01, 0.001)
|
163
|
-
assert_in_delta(58940416, @moment4.m20, 0.001)
|
164
|
-
assert_in_delta(41290240, @moment4.m11, 0.001)
|
165
|
-
assert_in_delta(61561856, @moment4.m02, 0.001)
|
166
|
-
assert_in_delta(5984288768, @moment4.m30, 0.001)
|
167
|
-
assert_in_delta(3742716416, @moment4.m21, 0.001)
|
168
|
-
assert_in_delta(3909177856, @moment4.m12, 0.001)
|
169
|
-
assert_in_delta(6483673088, @moment4.m03, 0.001)
|
170
|
-
assert_in_delta(17650176, @moment4.mu20, 0.001)
|
171
|
-
assert_in_delta(0, @moment4.mu11, 0.001)
|
172
|
-
assert_in_delta(20271616, @moment4.mu02, 0.001)
|
173
|
-
assert_in_delta(0, @moment4.mu30, 0.001)
|
174
|
-
assert_in_delta(0, @moment4.mu21, 0.001)
|
175
|
-
assert_in_delta(0, @moment4.mu12, 0.001)
|
176
|
-
assert_in_delta(0, @moment4.mu03, 0.001)
|
177
|
-
assert_in_delta(0.009882, @moment4.inv_sqrt_m00, 0.000001)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
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::CvMoment
|
10
|
+
class TestCvMoments < OpenCVTestCase
|
11
|
+
def setup
|
12
|
+
@mat = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
13
|
+
if j >= 32 and j < 96 and i >= 16 and i < 112
|
14
|
+
CvScalar.new(0)
|
15
|
+
elsif j >= 16 and j < 112 and i >= 16 and i < 112
|
16
|
+
CvScalar.new(128)
|
17
|
+
else
|
18
|
+
CvScalar.new(255)
|
19
|
+
end
|
20
|
+
}
|
21
|
+
@moment1 = CvMoments.new
|
22
|
+
@moment2 = CvMoments.new(nil, true)
|
23
|
+
@moment3 = CvMoments.new(@mat)
|
24
|
+
@moment4 = CvMoments.new(@mat, true)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_initialize
|
28
|
+
[@moment1, @moment2, @moment3, @moment4].each { |m|
|
29
|
+
assert_not_nil(m)
|
30
|
+
assert_equal(CvMoments, m.class)
|
31
|
+
}
|
32
|
+
|
33
|
+
assert_raise(TypeError) {
|
34
|
+
CvMoments.new('foo')
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_spatial
|
39
|
+
assert_in_delta(0, @moment1.spatial(0, 0), 0.1)
|
40
|
+
assert_in_delta(0, @moment2.spatial(0, 0), 0.1)
|
41
|
+
assert_in_delta(2221056, @moment3.spatial(0, 0), 0.1)
|
42
|
+
assert_in_delta(10240, @moment4.spatial(0, 0), 0.1)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_central
|
46
|
+
assert_in_delta(0, @moment1.central(0, 0), 0.1)
|
47
|
+
assert_in_delta(0, @moment2.central(0, 0), 0.1)
|
48
|
+
assert_in_delta(2221056, @moment3.central(0, 0), 0.1)
|
49
|
+
assert_in_delta(10240, @moment4.central(0, 0), 0.1)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_normalized_central
|
53
|
+
assert_in_delta(0, @moment1.normalized_central(0, 0), 0.1)
|
54
|
+
assert_in_delta(0, @moment2.normalized_central(0, 0), 0.1)
|
55
|
+
assert_in_delta(1, @moment3.normalized_central(0, 0), 0.1)
|
56
|
+
assert_in_delta(1, @moment4.normalized_central(0, 0), 0.1)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_hu
|
60
|
+
hu_moments = @moment1.hu
|
61
|
+
assert_equal(CvHuMoments, hu_moments.class)
|
62
|
+
hu_moments.to_a.each { |hu|
|
63
|
+
assert_in_delta(0.0, hu, 0.000001)
|
64
|
+
}
|
65
|
+
|
66
|
+
hu_moments = @moment2.hu
|
67
|
+
assert_equal(CvHuMoments, hu_moments.class)
|
68
|
+
hu_moments.to_a.each { |hu|
|
69
|
+
assert_in_delta(0.0, hu, 0.000001)
|
70
|
+
}
|
71
|
+
|
72
|
+
hu_moments = @moment3.hu
|
73
|
+
assert_equal(CvHuMoments, hu_moments.class)
|
74
|
+
assert_in_delta(0.001771, hu_moments.hu1, 0.000001)
|
75
|
+
hu_moments.to_a[1..7].each { |hu|
|
76
|
+
assert_in_delta(0.0, hu, 0.000001)
|
77
|
+
}
|
78
|
+
|
79
|
+
hu_moments = @moment4.hu
|
80
|
+
assert_equal(CvHuMoments, hu_moments.class)
|
81
|
+
assert_in_delta(0.361650, hu_moments.hu1, 0.000001)
|
82
|
+
assert_in_delta(0.000625, hu_moments.hu2, 0.000001)
|
83
|
+
hu_moments.to_a[2..7].each { |hu|
|
84
|
+
assert_in_delta(0.0, hu, 0.000001)
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_gravity_center
|
89
|
+
center = @moment1.gravity_center
|
90
|
+
assert_equal(CvPoint2D32f, center.class)
|
91
|
+
assert(center.x.nan?)
|
92
|
+
assert(center.y.nan?)
|
93
|
+
|
94
|
+
center = @moment2.gravity_center
|
95
|
+
assert_equal(CvPoint2D32f, center.class)
|
96
|
+
assert(center.x.nan?)
|
97
|
+
assert(center.y.nan?)
|
98
|
+
|
99
|
+
center = @moment3.gravity_center
|
100
|
+
assert_equal(CvPoint2D32f, center.class)
|
101
|
+
assert_in_delta(63.5, center.x, 0.001)
|
102
|
+
assert_in_delta(63.5, center.y, 0.001)
|
103
|
+
|
104
|
+
center = @moment4.gravity_center
|
105
|
+
assert_equal(CvPoint2D32f, center.class)
|
106
|
+
assert_in_delta(63.5, center.x, 0.001)
|
107
|
+
assert_in_delta(63.5, center.y, 0.001)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_angle
|
111
|
+
[@moment1, @moment2].each { |m|
|
112
|
+
assert_nil(m.angle)
|
113
|
+
}
|
114
|
+
[@moment3, @moment4].each { |m|
|
115
|
+
assert_in_delta(0, m.angle, 0.001)
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_mXX
|
120
|
+
[@moment1, @moment2].each { |m|
|
121
|
+
assert_in_delta(0, m.m00, 0.001)
|
122
|
+
assert_in_delta(0, m.m10, 0.001)
|
123
|
+
assert_in_delta(0, m.m01, 0.001)
|
124
|
+
assert_in_delta(0, m.m20, 0.001)
|
125
|
+
assert_in_delta(0, m.m11, 0.001)
|
126
|
+
assert_in_delta(0, m.m02, 0.001)
|
127
|
+
assert_in_delta(0, m.m30, 0.001)
|
128
|
+
assert_in_delta(0, m.m21, 0.001)
|
129
|
+
assert_in_delta(0, m.m12, 0.001)
|
130
|
+
assert_in_delta(0, m.m03, 0.001)
|
131
|
+
assert_in_delta(0, m.mu20, 0.001)
|
132
|
+
assert_in_delta(0, m.mu11, 0.001)
|
133
|
+
assert_in_delta(0, m.mu02, 0.001)
|
134
|
+
assert_in_delta(0, m.mu30, 0.001)
|
135
|
+
assert_in_delta(0, m.mu21, 0.001)
|
136
|
+
assert_in_delta(0, m.mu12, 0.001)
|
137
|
+
assert_in_delta(0, m.mu03, 0.001)
|
138
|
+
assert_in_delta(0, m.inv_sqrt_m00, 0.001)
|
139
|
+
}
|
140
|
+
|
141
|
+
assert_in_delta(2221056, @moment3.m00, 0.001)
|
142
|
+
assert_in_delta(141037056, @moment3.m10, 0.001)
|
143
|
+
assert_in_delta(141037056, @moment3.m01, 0.001)
|
144
|
+
assert_in_delta(13157049856, @moment3.m20, 0.001)
|
145
|
+
assert_in_delta(8955853056, @moment3.m11, 0.001)
|
146
|
+
assert_in_delta(13492594176, @moment3.m02, 0.001)
|
147
|
+
assert_in_delta(1369024659456, @moment3.m30, 0.001)
|
148
|
+
assert_in_delta(835472665856, @moment3.m21, 0.001)
|
149
|
+
assert_in_delta(856779730176, @moment3.m12, 0.001)
|
150
|
+
assert_in_delta(1432945852416, @moment3.m03, 0.001)
|
151
|
+
assert_in_delta(4201196800, @moment3.mu20, 0.001)
|
152
|
+
assert_in_delta(0, @moment3.mu11, 0.001)
|
153
|
+
assert_in_delta(4536741120, @moment3.mu02, 0.001)
|
154
|
+
assert_in_delta(0, @moment3.mu30, 0.001)
|
155
|
+
assert_in_delta(0, @moment3.mu21, 0.001)
|
156
|
+
assert_in_delta(0, @moment3.mu12, 0.001)
|
157
|
+
assert_in_delta(0, @moment3.mu03, 0.001)
|
158
|
+
assert_in_delta(0.000671, @moment3.inv_sqrt_m00, 0.000001)
|
159
|
+
|
160
|
+
assert_in_delta(10240, @moment4.m00, 0.001)
|
161
|
+
assert_in_delta(650240, @moment4.m10, 0.001)
|
162
|
+
assert_in_delta(650240, @moment4.m01, 0.001)
|
163
|
+
assert_in_delta(58940416, @moment4.m20, 0.001)
|
164
|
+
assert_in_delta(41290240, @moment4.m11, 0.001)
|
165
|
+
assert_in_delta(61561856, @moment4.m02, 0.001)
|
166
|
+
assert_in_delta(5984288768, @moment4.m30, 0.001)
|
167
|
+
assert_in_delta(3742716416, @moment4.m21, 0.001)
|
168
|
+
assert_in_delta(3909177856, @moment4.m12, 0.001)
|
169
|
+
assert_in_delta(6483673088, @moment4.m03, 0.001)
|
170
|
+
assert_in_delta(17650176, @moment4.mu20, 0.001)
|
171
|
+
assert_in_delta(0, @moment4.mu11, 0.001)
|
172
|
+
assert_in_delta(20271616, @moment4.mu02, 0.001)
|
173
|
+
assert_in_delta(0, @moment4.mu30, 0.001)
|
174
|
+
assert_in_delta(0, @moment4.mu21, 0.001)
|
175
|
+
assert_in_delta(0, @moment4.mu12, 0.001)
|
176
|
+
assert_in_delta(0, @moment4.mu03, 0.001)
|
177
|
+
assert_in_delta(0.009882, @moment4.inv_sqrt_m00, 0.000001)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|