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_cvcircle32f.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
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::CvCircle32f
|
10
|
-
class TestCvCircle32f < OpenCVTestCase
|
11
|
-
def setup
|
12
|
-
@circle = CvCircle32f.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_initialize
|
16
|
-
assert_equal(CvCircle32f, @circle.class)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_center
|
20
|
-
assert_equal(CvPoint2D32f, @circle.center.class)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_radius
|
24
|
-
assert_equal(Float, @circle.radius.class)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_aref
|
28
|
-
assert_equal(Float, @circle[0].class)
|
29
|
-
assert_equal(Float, @circle[1].class)
|
30
|
-
assert_equal(Float, @circle[2].class)
|
31
|
-
assert_raise(IndexError) {
|
32
|
-
@circle[3]
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_to_ary
|
37
|
-
assert_equal(Array, @circle.to_ary.class)
|
38
|
-
assert_equal(2, @circle.to_ary.size)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
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::CvCircle32f
|
10
|
+
class TestCvCircle32f < OpenCVTestCase
|
11
|
+
def setup
|
12
|
+
@circle = CvCircle32f.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialize
|
16
|
+
assert_equal(CvCircle32f, @circle.class)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_center
|
20
|
+
assert_equal(CvPoint2D32f, @circle.center.class)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_radius
|
24
|
+
assert_equal(Float, @circle.radius.class)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_aref
|
28
|
+
assert_equal(Float, @circle[0].class)
|
29
|
+
assert_equal(Float, @circle[1].class)
|
30
|
+
assert_equal(Float, @circle[2].class)
|
31
|
+
assert_raise(IndexError) {
|
32
|
+
@circle[3]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_to_ary
|
37
|
+
assert_equal(Array, @circle.to_ary.class)
|
38
|
+
assert_equal(2, @circle.to_ary.size)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -1,61 +1,61 @@
|
|
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::CvConnectedComp
|
10
|
-
class TestCvConnectedComp < OpenCVTestCase
|
11
|
-
def setup
|
12
|
-
@connected_comp = CvConnectedComp.new(9216, CvScalar.new(1, 2, 3, 4),
|
13
|
-
CvRect.new(1, 2, 3, 4), CvSeq.new(CvPoint))
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_initialize
|
17
|
-
connected_comp = CvConnectedComp.new
|
18
|
-
assert_equal(CvConnectedComp, connected_comp.class)
|
19
|
-
assert_not_nil(connected_comp.area)
|
20
|
-
assert_not_nil(connected_comp.value)
|
21
|
-
assert_not_nil(connected_comp.rect)
|
22
|
-
assert_not_nil(connected_comp.contour)
|
23
|
-
|
24
|
-
connected_comp = CvConnectedComp.new(100, CvScalar.new(1, 2, 3, 4),
|
25
|
-
CvRect.new(1, 2, 3, 4), CvSeq.new(CvPoint))
|
26
|
-
assert_equal(CvConnectedComp, connected_comp.class)
|
27
|
-
assert_not_nil(connected_comp.area)
|
28
|
-
assert_not_nil(connected_comp.value)
|
29
|
-
assert_not_nil(connected_comp.rect)
|
30
|
-
assert_not_nil(connected_comp.contour)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_area
|
34
|
-
assert_in_delta(9216.0, @connected_comp.area, 0.01)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_value
|
38
|
-
assert_equal(CvScalar, @connected_comp.value.class)
|
39
|
-
assert_cvscalar_equal(CvScalar.new(1, 2, 3, 4), @connected_comp.value)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_rect
|
43
|
-
assert_equal(CvRect, @connected_comp.rect.class)
|
44
|
-
assert_equal(1, @connected_comp.rect.x)
|
45
|
-
assert_equal(2, @connected_comp.rect.y)
|
46
|
-
assert_equal(3, @connected_comp.rect.width)
|
47
|
-
assert_equal(4, @connected_comp.rect.height)
|
48
|
-
|
49
|
-
@connected_comp.rect = CvRect.new(10, 20, 30, 40);
|
50
|
-
assert_equal(10, @connected_comp.rect.x)
|
51
|
-
assert_equal(20, @connected_comp.rect.y)
|
52
|
-
assert_equal(30, @connected_comp.rect.width)
|
53
|
-
assert_equal(40, @connected_comp.rect.height)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_contour
|
57
|
-
assert_equal(CvContour, @connected_comp.contour.class)
|
58
|
-
assert_not_nil(@connected_comp.contour)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
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::CvConnectedComp
|
10
|
+
class TestCvConnectedComp < OpenCVTestCase
|
11
|
+
def setup
|
12
|
+
@connected_comp = CvConnectedComp.new(9216, CvScalar.new(1, 2, 3, 4),
|
13
|
+
CvRect.new(1, 2, 3, 4), CvSeq.new(CvPoint))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialize
|
17
|
+
connected_comp = CvConnectedComp.new
|
18
|
+
assert_equal(CvConnectedComp, connected_comp.class)
|
19
|
+
assert_not_nil(connected_comp.area)
|
20
|
+
assert_not_nil(connected_comp.value)
|
21
|
+
assert_not_nil(connected_comp.rect)
|
22
|
+
assert_not_nil(connected_comp.contour)
|
23
|
+
|
24
|
+
connected_comp = CvConnectedComp.new(100, CvScalar.new(1, 2, 3, 4),
|
25
|
+
CvRect.new(1, 2, 3, 4), CvSeq.new(CvPoint))
|
26
|
+
assert_equal(CvConnectedComp, connected_comp.class)
|
27
|
+
assert_not_nil(connected_comp.area)
|
28
|
+
assert_not_nil(connected_comp.value)
|
29
|
+
assert_not_nil(connected_comp.rect)
|
30
|
+
assert_not_nil(connected_comp.contour)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_area
|
34
|
+
assert_in_delta(9216.0, @connected_comp.area, 0.01)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_value
|
38
|
+
assert_equal(CvScalar, @connected_comp.value.class)
|
39
|
+
assert_cvscalar_equal(CvScalar.new(1, 2, 3, 4), @connected_comp.value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_rect
|
43
|
+
assert_equal(CvRect, @connected_comp.rect.class)
|
44
|
+
assert_equal(1, @connected_comp.rect.x)
|
45
|
+
assert_equal(2, @connected_comp.rect.y)
|
46
|
+
assert_equal(3, @connected_comp.rect.width)
|
47
|
+
assert_equal(4, @connected_comp.rect.height)
|
48
|
+
|
49
|
+
@connected_comp.rect = CvRect.new(10, 20, 30, 40);
|
50
|
+
assert_equal(10, @connected_comp.rect.x)
|
51
|
+
assert_equal(20, @connected_comp.rect.y)
|
52
|
+
assert_equal(30, @connected_comp.rect.width)
|
53
|
+
assert_equal(40, @connected_comp.rect.height)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_contour
|
57
|
+
assert_equal(CvContour, @connected_comp.contour.class)
|
58
|
+
assert_not_nil(@connected_comp.contour)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/test/test_cvcontour.rb
CHANGED
@@ -1,150 +1,150 @@
|
|
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::CvContour
|
10
|
-
class TestCvContour < OpenCVTestCase
|
11
|
-
def test_APPROX_OPTION
|
12
|
-
assert_equal(0, CvContour::APPROX_OPTION[:method])
|
13
|
-
assert_equal(1.0, CvContour::APPROX_OPTION[:accuracy])
|
14
|
-
assert_false(CvContour::APPROX_OPTION[:recursive])
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_initialize
|
18
|
-
contour = CvContour.new
|
19
|
-
assert_not_nil(contour)
|
20
|
-
assert_equal(CvContour, contour.class)
|
21
|
-
assert(contour.is_a? CvSeq)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_rect
|
25
|
-
contour = CvContour.new
|
26
|
-
assert_not_nil(contour.rect)
|
27
|
-
assert_equal(CvRect, contour.rect.class)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_color
|
31
|
-
contour = CvContour.new
|
32
|
-
assert_equal(0, contour.color)
|
33
|
-
contour.color = 1
|
34
|
-
assert_equal(1, contour.color)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_reserved
|
38
|
-
reserved = CvContour.new.reserved
|
39
|
-
assert_equal(Array, reserved.class)
|
40
|
-
assert_equal(3, reserved.size)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_approx_poly
|
44
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
45
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
46
|
-
}
|
47
|
-
contours = mat0.find_contours(:mode => CV_RETR_EXTERNAL)
|
48
|
-
|
49
|
-
poly = contours.approx_poly
|
50
|
-
assert_equal(CvContour, poly.class)
|
51
|
-
assert(poly.size > 0)
|
52
|
-
assert(poly.all? { |c| c.class == CvPoint })
|
53
|
-
|
54
|
-
poly = contours.approx_poly(:method => :dp)
|
55
|
-
assert_equal(CvContour, poly.class)
|
56
|
-
assert(poly.size > 0)
|
57
|
-
assert(poly.all? { |c| c.class == CvPoint })
|
58
|
-
|
59
|
-
poly = contours.approx_poly(:accuracy => 2.0)
|
60
|
-
assert_equal(CvContour, poly.class)
|
61
|
-
assert(poly.size > 0)
|
62
|
-
assert(poly.all? { |c| c.class == CvPoint })
|
63
|
-
|
64
|
-
[true, false, 1, 0].each { |recursive|
|
65
|
-
poly = contours.approx_poly(:recursive => recursive)
|
66
|
-
assert_equal(CvContour, poly.class)
|
67
|
-
assert(poly.size > 0)
|
68
|
-
assert(poly.all? { |c| c.class == CvPoint })
|
69
|
-
}
|
70
|
-
|
71
|
-
poly = contours.approx_poly(:method => :dp, :accuracy => 2.0, :recursive => false)
|
72
|
-
assert_equal(CvContour, poly.class)
|
73
|
-
assert(poly.size > 0)
|
74
|
-
assert(poly.all? { |c| c.class == CvPoint })
|
75
|
-
|
76
|
-
# Uncomment the following lines to show the result
|
77
|
-
# poly = contours.approx_poly(:accuracy => 3.0)
|
78
|
-
# dst = mat0.clone.zero
|
79
|
-
# begin
|
80
|
-
# dst.draw_contours!(poly, CvColor::White, CvColor::Black, 2,
|
81
|
-
# :thickness => 1, :line_type => :aa)
|
82
|
-
# end while (poly = poly.h_next)
|
83
|
-
# snap dst
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_bounding_rect
|
87
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
88
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
89
|
-
}
|
90
|
-
contours = mat0.find_contours
|
91
|
-
rect = contours.bounding_rect
|
92
|
-
assert_equal(CvRect, rect.class)
|
93
|
-
assert_equal(32, rect.x)
|
94
|
-
assert_equal(32, rect.y)
|
95
|
-
assert_equal(65, rect.width)
|
96
|
-
assert_equal(65, rect.height)
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_create_tree
|
100
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
101
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
102
|
-
}
|
103
|
-
contour = mat0.find_contours
|
104
|
-
tree = contour.create_tree
|
105
|
-
assert_equal(CvContourTree, tree.class)
|
106
|
-
assert_equal(34, tree.p1.x)
|
107
|
-
assert_equal(53, tree.p1.y)
|
108
|
-
assert_equal(0, tree.p2.x)
|
109
|
-
assert_equal(0, tree.p2.y)
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_in
|
113
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
114
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
115
|
-
}
|
116
|
-
contour = mat0.find_contours
|
117
|
-
assert(contour.in? CvPoint.new(64, 64))
|
118
|
-
assert_false(contour.in? CvPoint.new(0, 0))
|
119
|
-
assert_nil(contour.in? CvPoint.new(64, 32))
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_measure_distance
|
123
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
124
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
125
|
-
}
|
126
|
-
contour = mat0.find_contours
|
127
|
-
assert_in_delta(-0.7071, contour.measure_distance(CvPoint.new(63, 32)), 0.01)
|
128
|
-
assert_in_delta(31.01, contour.measure_distance(CvPoint.new(64, 64)), 0.01)
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_point_polygon_test
|
132
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
133
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
134
|
-
}
|
135
|
-
contour = mat0.find_contours
|
136
|
-
|
137
|
-
assert_equal(1, contour.point_polygon_test(CvPoint.new(64, 64), 0))
|
138
|
-
assert_equal(1, contour.point_polygon_test(CvPoint.new(64, 64), false))
|
139
|
-
assert_equal(-1, contour.point_polygon_test(CvPoint.new(0, 0), 0))
|
140
|
-
assert_equal(-1, contour.point_polygon_test(CvPoint.new(0, 0), false))
|
141
|
-
assert_equal(0, contour.point_polygon_test(CvPoint.new(64, 32), 0))
|
142
|
-
assert_equal(0, contour.point_polygon_test(CvPoint.new(64, 32), false))
|
143
|
-
|
144
|
-
assert_in_delta(-0.7071, contour.point_polygon_test(CvPoint.new(63, 32), 1), 0.01)
|
145
|
-
assert_in_delta(-0.7071, contour.point_polygon_test(CvPoint.new(63, 32), true), 0.01)
|
146
|
-
assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), 1), 0.01)
|
147
|
-
assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), true), 0.01)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
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::CvContour
|
10
|
+
class TestCvContour < OpenCVTestCase
|
11
|
+
def test_APPROX_OPTION
|
12
|
+
assert_equal(0, CvContour::APPROX_OPTION[:method])
|
13
|
+
assert_equal(1.0, CvContour::APPROX_OPTION[:accuracy])
|
14
|
+
assert_false(CvContour::APPROX_OPTION[:recursive])
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initialize
|
18
|
+
contour = CvContour.new
|
19
|
+
assert_not_nil(contour)
|
20
|
+
assert_equal(CvContour, contour.class)
|
21
|
+
assert(contour.is_a? CvSeq)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_rect
|
25
|
+
contour = CvContour.new
|
26
|
+
assert_not_nil(contour.rect)
|
27
|
+
assert_equal(CvRect, contour.rect.class)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_color
|
31
|
+
contour = CvContour.new
|
32
|
+
assert_equal(0, contour.color)
|
33
|
+
contour.color = 1
|
34
|
+
assert_equal(1, contour.color)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_reserved
|
38
|
+
reserved = CvContour.new.reserved
|
39
|
+
assert_equal(Array, reserved.class)
|
40
|
+
assert_equal(3, reserved.size)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_approx_poly
|
44
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
45
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
46
|
+
}
|
47
|
+
contours = mat0.find_contours(:mode => CV_RETR_EXTERNAL)
|
48
|
+
|
49
|
+
poly = contours.approx_poly
|
50
|
+
assert_equal(CvContour, poly.class)
|
51
|
+
assert(poly.size > 0)
|
52
|
+
assert(poly.all? { |c| c.class == CvPoint })
|
53
|
+
|
54
|
+
poly = contours.approx_poly(:method => :dp)
|
55
|
+
assert_equal(CvContour, poly.class)
|
56
|
+
assert(poly.size > 0)
|
57
|
+
assert(poly.all? { |c| c.class == CvPoint })
|
58
|
+
|
59
|
+
poly = contours.approx_poly(:accuracy => 2.0)
|
60
|
+
assert_equal(CvContour, poly.class)
|
61
|
+
assert(poly.size > 0)
|
62
|
+
assert(poly.all? { |c| c.class == CvPoint })
|
63
|
+
|
64
|
+
[true, false, 1, 0].each { |recursive|
|
65
|
+
poly = contours.approx_poly(:recursive => recursive)
|
66
|
+
assert_equal(CvContour, poly.class)
|
67
|
+
assert(poly.size > 0)
|
68
|
+
assert(poly.all? { |c| c.class == CvPoint })
|
69
|
+
}
|
70
|
+
|
71
|
+
poly = contours.approx_poly(:method => :dp, :accuracy => 2.0, :recursive => false)
|
72
|
+
assert_equal(CvContour, poly.class)
|
73
|
+
assert(poly.size > 0)
|
74
|
+
assert(poly.all? { |c| c.class == CvPoint })
|
75
|
+
|
76
|
+
# Uncomment the following lines to show the result
|
77
|
+
# poly = contours.approx_poly(:accuracy => 3.0)
|
78
|
+
# dst = mat0.clone.zero
|
79
|
+
# begin
|
80
|
+
# dst.draw_contours!(poly, CvColor::White, CvColor::Black, 2,
|
81
|
+
# :thickness => 1, :line_type => :aa)
|
82
|
+
# end while (poly = poly.h_next)
|
83
|
+
# snap dst
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_bounding_rect
|
87
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
88
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
89
|
+
}
|
90
|
+
contours = mat0.find_contours
|
91
|
+
rect = contours.bounding_rect
|
92
|
+
assert_equal(CvRect, rect.class)
|
93
|
+
assert_equal(32, rect.x)
|
94
|
+
assert_equal(32, rect.y)
|
95
|
+
assert_equal(65, rect.width)
|
96
|
+
assert_equal(65, rect.height)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_create_tree
|
100
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
101
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
102
|
+
}
|
103
|
+
contour = mat0.find_contours
|
104
|
+
tree = contour.create_tree
|
105
|
+
assert_equal(CvContourTree, tree.class)
|
106
|
+
assert_equal(34, tree.p1.x)
|
107
|
+
assert_equal(53, tree.p1.y)
|
108
|
+
assert_equal(0, tree.p2.x)
|
109
|
+
assert_equal(0, tree.p2.y)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_in
|
113
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
114
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
115
|
+
}
|
116
|
+
contour = mat0.find_contours
|
117
|
+
assert(contour.in? CvPoint.new(64, 64))
|
118
|
+
assert_false(contour.in? CvPoint.new(0, 0))
|
119
|
+
assert_nil(contour.in? CvPoint.new(64, 32))
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_measure_distance
|
123
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
124
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
125
|
+
}
|
126
|
+
contour = mat0.find_contours
|
127
|
+
assert_in_delta(-0.7071, contour.measure_distance(CvPoint.new(63, 32)), 0.01)
|
128
|
+
assert_in_delta(31.01, contour.measure_distance(CvPoint.new(64, 64)), 0.01)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_point_polygon_test
|
132
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
133
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
134
|
+
}
|
135
|
+
contour = mat0.find_contours
|
136
|
+
|
137
|
+
assert_equal(1, contour.point_polygon_test(CvPoint.new(64, 64), 0))
|
138
|
+
assert_equal(1, contour.point_polygon_test(CvPoint.new(64, 64), false))
|
139
|
+
assert_equal(-1, contour.point_polygon_test(CvPoint.new(0, 0), 0))
|
140
|
+
assert_equal(-1, contour.point_polygon_test(CvPoint.new(0, 0), false))
|
141
|
+
assert_equal(0, contour.point_polygon_test(CvPoint.new(64, 32), 0))
|
142
|
+
assert_equal(0, contour.point_polygon_test(CvPoint.new(64, 32), false))
|
143
|
+
|
144
|
+
assert_in_delta(-0.7071, contour.point_polygon_test(CvPoint.new(63, 32), 1), 0.01)
|
145
|
+
assert_in_delta(-0.7071, contour.point_polygon_test(CvPoint.new(63, 32), true), 0.01)
|
146
|
+
assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), 1), 0.01)
|
147
|
+
assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), true), 0.01)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|