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_cvcapture.rb
CHANGED
@@ -1,183 +1,183 @@
|
|
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::CvCapture
|
10
|
-
class TestCvCapture < OpenCVTestCase
|
11
|
-
def setup
|
12
|
-
@cap = CvCapture.open(AVI_SAMPLE)
|
13
|
-
@cap.query
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
@cap = nil
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_INTERFACE
|
21
|
-
assert_equal(CvCapture::INTERFACE[:any], 0)
|
22
|
-
assert_equal(CvCapture::INTERFACE[:mil], 100)
|
23
|
-
assert_equal(CvCapture::INTERFACE[:vfw], 200)
|
24
|
-
assert_equal(CvCapture::INTERFACE[:v4l], 200)
|
25
|
-
assert_equal(CvCapture::INTERFACE[:v4l2], 200)
|
26
|
-
assert_equal(CvCapture::INTERFACE[:fireware], 300)
|
27
|
-
assert_equal(CvCapture::INTERFACE[:ieee1394], 300)
|
28
|
-
assert_equal(CvCapture::INTERFACE[:dc1394], 300)
|
29
|
-
assert_equal(CvCapture::INTERFACE[:cmu1394], 300)
|
30
|
-
assert_equal(CvCapture::INTERFACE[:stereo], 400)
|
31
|
-
assert_equal(CvCapture::INTERFACE[:tyzx], 400)
|
32
|
-
assert_equal(CvCapture::INTERFACE[:tyzx_left], 400)
|
33
|
-
assert_equal(CvCapture::INTERFACE[:tyzx_right], 401)
|
34
|
-
assert_equal(CvCapture::INTERFACE[:tyzx_color], 402)
|
35
|
-
assert_equal(CvCapture::INTERFACE[:tyzx_z], 403)
|
36
|
-
assert_equal(CvCapture::INTERFACE[:qt], 500)
|
37
|
-
assert_equal(CvCapture::INTERFACE[:quicktime], 500)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_open
|
41
|
-
cap1 = CvCapture.open(AVI_SAMPLE)
|
42
|
-
assert_equal(CvCapture, cap1.class)
|
43
|
-
|
44
|
-
# Uncomment the following lines to test capturing from camera
|
45
|
-
# cap2 = CvCapture.open(0)
|
46
|
-
# assert_equal(CvCapture, cap2.class)
|
47
|
-
# CvCapture::INTERFACE.each { |k, v|
|
48
|
-
# cap3 = CvCapture.open(k)
|
49
|
-
# assert_equal(CvCapture, cap3.class)
|
50
|
-
# }
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_grab
|
54
|
-
assert(@cap.grab)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_retrieve
|
58
|
-
@cap.grab
|
59
|
-
img = @cap.retrieve
|
60
|
-
assert_equal(IplImage, img.class)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_query
|
64
|
-
img = @cap.query
|
65
|
-
assert_equal(IplImage, img.class)
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_millisecond
|
69
|
-
@cap.millisecond = 10
|
70
|
-
assert(@cap.millisecond.is_a? Numeric)
|
71
|
-
# assert_equal(10, @cap.millisecond)
|
72
|
-
@cap.millisecond = 20
|
73
|
-
assert(@cap.millisecond.is_a? Numeric)
|
74
|
-
# assert_equal(20, @cap.millisecond)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_frames
|
78
|
-
@cap.frames = 10
|
79
|
-
assert(@cap.frames.is_a? Numeric)
|
80
|
-
# assert_equal(10, @cap.frames)
|
81
|
-
@cap.frames = 20
|
82
|
-
assert(@cap.frames.is_a? Numeric)
|
83
|
-
# assert_equal(20, @cap.frames)
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_avi_ratio
|
87
|
-
@cap.avi_ratio = 0.1
|
88
|
-
assert(@cap.avi_ratio.is_a? Numeric)
|
89
|
-
# assert_equal(0.1, @cap.avi_ratio)
|
90
|
-
@cap.avi_ratio = 0.8
|
91
|
-
assert(@cap.avi_ratio.is_a? Numeric)
|
92
|
-
# assert_equal(0.8, @cap.avi_ratio)
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_size
|
96
|
-
@cap.size = CvSize.new(320, 240)
|
97
|
-
assert_equal(CvSize, @cap.size.class)
|
98
|
-
# assert_equal(320, @cap.size.width)
|
99
|
-
# assert_equal(240, @cap.size.height)
|
100
|
-
|
101
|
-
@cap.size = CvSize.new(640, 480)
|
102
|
-
assert_equal(CvSize, @cap.size.class)
|
103
|
-
# assert_equal(640, @cap.size.width)
|
104
|
-
# assert_equal(480, @cap.size.height)
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_width
|
108
|
-
@cap.width = 320
|
109
|
-
assert(@cap.width.is_a? Numeric)
|
110
|
-
# assert_equal(320, @cap.width)
|
111
|
-
@cap.width = 640
|
112
|
-
assert(@cap.width.is_a? Numeric)
|
113
|
-
# assert_equal(640, @cap.width)
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_height
|
117
|
-
@cap.height = 240
|
118
|
-
assert(@cap.height.is_a? Numeric)
|
119
|
-
# assert_equal(240, @cap.height)
|
120
|
-
@cap.height = 480
|
121
|
-
assert(@cap.height.is_a? Numeric)
|
122
|
-
# assert_equal(480, @cap.height)
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_fps
|
126
|
-
@cap.fps = 15
|
127
|
-
assert(@cap.fps.is_a? Numeric)
|
128
|
-
# assert_equal(15, @cap.fps)
|
129
|
-
@cap.fps = 30
|
130
|
-
assert(@cap.fps.is_a? Numeric)
|
131
|
-
# assert_equal(30, @cap.fps)
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_fourcc
|
135
|
-
assert_equal(String, @cap.fourcc.class)
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_frame_count
|
139
|
-
assert(@cap.frame_count.is_a? Numeric)
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_format
|
143
|
-
assert(@cap.format.is_a? Numeric)
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_mode
|
147
|
-
assert(@cap.mode.is_a? Numeric)
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_brightness
|
151
|
-
assert(@cap.brightness.is_a? Numeric)
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_contrast
|
155
|
-
assert(@cap.contrast.is_a? Numeric)
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_saturation
|
159
|
-
assert(@cap.saturation.is_a? Numeric)
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_hue
|
163
|
-
assert(@cap.hue.is_a? Numeric)
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_gain
|
167
|
-
assert(@cap.gain.is_a? Numeric)
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_exposure
|
171
|
-
assert(@cap.exposure.is_a? Numeric)
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_convert_rgb
|
175
|
-
assert((@cap.convert_rgb == true) ||
|
176
|
-
(@cap.convert_rgb == false))
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_rectification
|
180
|
-
assert(@cap.rectification.is_a? Numeric)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
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::CvCapture
|
10
|
+
class TestCvCapture < OpenCVTestCase
|
11
|
+
def setup
|
12
|
+
@cap = CvCapture.open(AVI_SAMPLE)
|
13
|
+
@cap.query
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
@cap = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_INTERFACE
|
21
|
+
assert_equal(CvCapture::INTERFACE[:any], 0)
|
22
|
+
assert_equal(CvCapture::INTERFACE[:mil], 100)
|
23
|
+
assert_equal(CvCapture::INTERFACE[:vfw], 200)
|
24
|
+
assert_equal(CvCapture::INTERFACE[:v4l], 200)
|
25
|
+
assert_equal(CvCapture::INTERFACE[:v4l2], 200)
|
26
|
+
assert_equal(CvCapture::INTERFACE[:fireware], 300)
|
27
|
+
assert_equal(CvCapture::INTERFACE[:ieee1394], 300)
|
28
|
+
assert_equal(CvCapture::INTERFACE[:dc1394], 300)
|
29
|
+
assert_equal(CvCapture::INTERFACE[:cmu1394], 300)
|
30
|
+
assert_equal(CvCapture::INTERFACE[:stereo], 400)
|
31
|
+
assert_equal(CvCapture::INTERFACE[:tyzx], 400)
|
32
|
+
assert_equal(CvCapture::INTERFACE[:tyzx_left], 400)
|
33
|
+
assert_equal(CvCapture::INTERFACE[:tyzx_right], 401)
|
34
|
+
assert_equal(CvCapture::INTERFACE[:tyzx_color], 402)
|
35
|
+
assert_equal(CvCapture::INTERFACE[:tyzx_z], 403)
|
36
|
+
assert_equal(CvCapture::INTERFACE[:qt], 500)
|
37
|
+
assert_equal(CvCapture::INTERFACE[:quicktime], 500)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_open
|
41
|
+
cap1 = CvCapture.open(AVI_SAMPLE)
|
42
|
+
assert_equal(CvCapture, cap1.class)
|
43
|
+
|
44
|
+
# Uncomment the following lines to test capturing from camera
|
45
|
+
# cap2 = CvCapture.open(0)
|
46
|
+
# assert_equal(CvCapture, cap2.class)
|
47
|
+
# CvCapture::INTERFACE.each { |k, v|
|
48
|
+
# cap3 = CvCapture.open(k)
|
49
|
+
# assert_equal(CvCapture, cap3.class)
|
50
|
+
# }
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_grab
|
54
|
+
assert(@cap.grab)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_retrieve
|
58
|
+
@cap.grab
|
59
|
+
img = @cap.retrieve
|
60
|
+
assert_equal(IplImage, img.class)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_query
|
64
|
+
img = @cap.query
|
65
|
+
assert_equal(IplImage, img.class)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_millisecond
|
69
|
+
@cap.millisecond = 10
|
70
|
+
assert(@cap.millisecond.is_a? Numeric)
|
71
|
+
# assert_equal(10, @cap.millisecond)
|
72
|
+
@cap.millisecond = 20
|
73
|
+
assert(@cap.millisecond.is_a? Numeric)
|
74
|
+
# assert_equal(20, @cap.millisecond)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_frames
|
78
|
+
@cap.frames = 10
|
79
|
+
assert(@cap.frames.is_a? Numeric)
|
80
|
+
# assert_equal(10, @cap.frames)
|
81
|
+
@cap.frames = 20
|
82
|
+
assert(@cap.frames.is_a? Numeric)
|
83
|
+
# assert_equal(20, @cap.frames)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_avi_ratio
|
87
|
+
@cap.avi_ratio = 0.1
|
88
|
+
assert(@cap.avi_ratio.is_a? Numeric)
|
89
|
+
# assert_equal(0.1, @cap.avi_ratio)
|
90
|
+
@cap.avi_ratio = 0.8
|
91
|
+
assert(@cap.avi_ratio.is_a? Numeric)
|
92
|
+
# assert_equal(0.8, @cap.avi_ratio)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_size
|
96
|
+
@cap.size = CvSize.new(320, 240)
|
97
|
+
assert_equal(CvSize, @cap.size.class)
|
98
|
+
# assert_equal(320, @cap.size.width)
|
99
|
+
# assert_equal(240, @cap.size.height)
|
100
|
+
|
101
|
+
@cap.size = CvSize.new(640, 480)
|
102
|
+
assert_equal(CvSize, @cap.size.class)
|
103
|
+
# assert_equal(640, @cap.size.width)
|
104
|
+
# assert_equal(480, @cap.size.height)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_width
|
108
|
+
@cap.width = 320
|
109
|
+
assert(@cap.width.is_a? Numeric)
|
110
|
+
# assert_equal(320, @cap.width)
|
111
|
+
@cap.width = 640
|
112
|
+
assert(@cap.width.is_a? Numeric)
|
113
|
+
# assert_equal(640, @cap.width)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_height
|
117
|
+
@cap.height = 240
|
118
|
+
assert(@cap.height.is_a? Numeric)
|
119
|
+
# assert_equal(240, @cap.height)
|
120
|
+
@cap.height = 480
|
121
|
+
assert(@cap.height.is_a? Numeric)
|
122
|
+
# assert_equal(480, @cap.height)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_fps
|
126
|
+
@cap.fps = 15
|
127
|
+
assert(@cap.fps.is_a? Numeric)
|
128
|
+
# assert_equal(15, @cap.fps)
|
129
|
+
@cap.fps = 30
|
130
|
+
assert(@cap.fps.is_a? Numeric)
|
131
|
+
# assert_equal(30, @cap.fps)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_fourcc
|
135
|
+
assert_equal(String, @cap.fourcc.class)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_frame_count
|
139
|
+
assert(@cap.frame_count.is_a? Numeric)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_format
|
143
|
+
assert(@cap.format.is_a? Numeric)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_mode
|
147
|
+
assert(@cap.mode.is_a? Numeric)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_brightness
|
151
|
+
assert(@cap.brightness.is_a? Numeric)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_contrast
|
155
|
+
assert(@cap.contrast.is_a? Numeric)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_saturation
|
159
|
+
assert(@cap.saturation.is_a? Numeric)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_hue
|
163
|
+
assert(@cap.hue.is_a? Numeric)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_gain
|
167
|
+
assert(@cap.gain.is_a? Numeric)
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_exposure
|
171
|
+
assert(@cap.exposure.is_a? Numeric)
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_convert_rgb
|
175
|
+
assert((@cap.convert_rgb == true) ||
|
176
|
+
(@cap.convert_rgb == false))
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_rectification
|
180
|
+
assert(@cap.rectification.is_a? Numeric)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
data/test/test_cvchain.rb
CHANGED
@@ -1,108 +1,108 @@
|
|
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::CvChain
|
10
|
-
class TestCvChain < OpenCVTestCase
|
11
|
-
def test_APPROX_OPTION
|
12
|
-
assert_equal(:approx_simple, CvChain::APPROX_CHAIN_OPTION[:method])
|
13
|
-
assert_equal(0, CvChain::APPROX_CHAIN_OPTION[:parameter])
|
14
|
-
assert_equal(0, CvChain::APPROX_CHAIN_OPTION[:minimal_perimeter])
|
15
|
-
assert_false(CvChain::APPROX_CHAIN_OPTION[:recursive])
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_initialize
|
19
|
-
chain = CvChain.new
|
20
|
-
assert_not_nil(chain)
|
21
|
-
assert_equal(CvChain, chain.class)
|
22
|
-
assert(chain.is_a? CvSeq)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_origin
|
26
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
27
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
28
|
-
}
|
29
|
-
chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
|
30
|
-
assert_equal(CvChain, chain.class)
|
31
|
-
assert_equal(64, chain.origin.x)
|
32
|
-
assert_equal(32, chain.origin.y)
|
33
|
-
|
34
|
-
chain.origin = CvPoint.new(32, 64)
|
35
|
-
assert_equal(32, chain.origin.x)
|
36
|
-
assert_equal(64, chain.origin.y)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_codes
|
40
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
41
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
42
|
-
}
|
43
|
-
chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
|
44
|
-
assert_equal(Array, chain.codes.class)
|
45
|
-
assert(chain.codes.all? { |a| (a.class == Fixnum) and (a >= 0 and a <= 7) })
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_points
|
49
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
50
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
51
|
-
}
|
52
|
-
chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
|
53
|
-
assert_equal(Array, chain.points.class)
|
54
|
-
assert(chain.points.all? { |a| a.class == CvPoint })
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_approx_chains
|
58
|
-
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
59
|
-
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
60
|
-
}
|
61
|
-
chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
|
62
|
-
|
63
|
-
contours = chain.approx_chains
|
64
|
-
assert_equal(CvChain, contours.class)
|
65
|
-
assert(contours.size > 0)
|
66
|
-
assert(contours.all? { |c| c.class == CvPoint })
|
67
|
-
|
68
|
-
[CV_CHAIN_APPROX_NONE, CV_CHAIN_APPROX_SIMPLE,
|
69
|
-
CV_CHAIN_APPROX_TC89_L1, CV_CHAIN_APPROX_TC89_KCOS,
|
70
|
-
:approx_none, :approx_simple, :approx_tc89_l1, :approx_tc89_kcos].each { |method|
|
71
|
-
contours = chain.approx_chains(:method => method)
|
72
|
-
assert_equal(CvChain, contours.class)
|
73
|
-
assert(contours.size > 0)
|
74
|
-
assert(contours.all? { |c| c.class == CvPoint })
|
75
|
-
}
|
76
|
-
|
77
|
-
contours = chain.approx_chains(:minimal_parameter => 10)
|
78
|
-
assert_equal(CvChain, contours.class)
|
79
|
-
assert(contours.size > 0)
|
80
|
-
assert(contours.all? { |c| c.class == CvPoint })
|
81
|
-
|
82
|
-
contours = chain.approx_chains(:minimal_perimeter => (32 * 2 * Math::PI).ceil)
|
83
|
-
assert_nil(contours)
|
84
|
-
|
85
|
-
[true, false].each { |recursive|
|
86
|
-
contours = chain.approx_chains(:recursive => recursive)
|
87
|
-
assert_equal(CvChain, contours.class)
|
88
|
-
assert(contours.size > 0)
|
89
|
-
assert(contours.all? { |c| c.class == CvPoint })
|
90
|
-
}
|
91
|
-
|
92
|
-
contours = chain.approx_chains(:method => :approx_simple,
|
93
|
-
:minimal_parameter => 100, :recursive => false)
|
94
|
-
assert_equal(CvChain, contours.class)
|
95
|
-
assert(contours.size > 0)
|
96
|
-
assert(contours.all? { |c| c.class == CvPoint })
|
97
|
-
|
98
|
-
# Uncomment the following lines to show the result
|
99
|
-
# contours = chain.approx_chains
|
100
|
-
# dst = mat0.clone.zero
|
101
|
-
# begin
|
102
|
-
# dst.draw_contours!(contours, CvColor::White, CvColor::Black, 2,
|
103
|
-
# :thickness => 1, :line_type => :aa)
|
104
|
-
# end while (contours = contours.h_next)
|
105
|
-
# snap dst
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
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::CvChain
|
10
|
+
class TestCvChain < OpenCVTestCase
|
11
|
+
def test_APPROX_OPTION
|
12
|
+
assert_equal(:approx_simple, CvChain::APPROX_CHAIN_OPTION[:method])
|
13
|
+
assert_equal(0, CvChain::APPROX_CHAIN_OPTION[:parameter])
|
14
|
+
assert_equal(0, CvChain::APPROX_CHAIN_OPTION[:minimal_perimeter])
|
15
|
+
assert_false(CvChain::APPROX_CHAIN_OPTION[:recursive])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_initialize
|
19
|
+
chain = CvChain.new
|
20
|
+
assert_not_nil(chain)
|
21
|
+
assert_equal(CvChain, chain.class)
|
22
|
+
assert(chain.is_a? CvSeq)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_origin
|
26
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
27
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
28
|
+
}
|
29
|
+
chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
|
30
|
+
assert_equal(CvChain, chain.class)
|
31
|
+
assert_equal(64, chain.origin.x)
|
32
|
+
assert_equal(32, chain.origin.y)
|
33
|
+
|
34
|
+
chain.origin = CvPoint.new(32, 64)
|
35
|
+
assert_equal(32, chain.origin.x)
|
36
|
+
assert_equal(64, chain.origin.y)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_codes
|
40
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
41
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
42
|
+
}
|
43
|
+
chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
|
44
|
+
assert_equal(Array, chain.codes.class)
|
45
|
+
assert(chain.codes.all? { |a| (a.class == Fixnum) and (a >= 0 and a <= 7) })
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_points
|
49
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
50
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
51
|
+
}
|
52
|
+
chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
|
53
|
+
assert_equal(Array, chain.points.class)
|
54
|
+
assert(chain.points.all? { |a| a.class == CvPoint })
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_approx_chains
|
58
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
59
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
60
|
+
}
|
61
|
+
chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
|
62
|
+
|
63
|
+
contours = chain.approx_chains
|
64
|
+
assert_equal(CvChain, contours.class)
|
65
|
+
assert(contours.size > 0)
|
66
|
+
assert(contours.all? { |c| c.class == CvPoint })
|
67
|
+
|
68
|
+
[CV_CHAIN_APPROX_NONE, CV_CHAIN_APPROX_SIMPLE,
|
69
|
+
CV_CHAIN_APPROX_TC89_L1, CV_CHAIN_APPROX_TC89_KCOS,
|
70
|
+
:approx_none, :approx_simple, :approx_tc89_l1, :approx_tc89_kcos].each { |method|
|
71
|
+
contours = chain.approx_chains(:method => method)
|
72
|
+
assert_equal(CvChain, contours.class)
|
73
|
+
assert(contours.size > 0)
|
74
|
+
assert(contours.all? { |c| c.class == CvPoint })
|
75
|
+
}
|
76
|
+
|
77
|
+
contours = chain.approx_chains(:minimal_parameter => 10)
|
78
|
+
assert_equal(CvChain, contours.class)
|
79
|
+
assert(contours.size > 0)
|
80
|
+
assert(contours.all? { |c| c.class == CvPoint })
|
81
|
+
|
82
|
+
contours = chain.approx_chains(:minimal_perimeter => (32 * 2 * Math::PI).ceil)
|
83
|
+
assert_nil(contours)
|
84
|
+
|
85
|
+
[true, false].each { |recursive|
|
86
|
+
contours = chain.approx_chains(:recursive => recursive)
|
87
|
+
assert_equal(CvChain, contours.class)
|
88
|
+
assert(contours.size > 0)
|
89
|
+
assert(contours.all? { |c| c.class == CvPoint })
|
90
|
+
}
|
91
|
+
|
92
|
+
contours = chain.approx_chains(:method => :approx_simple,
|
93
|
+
:minimal_parameter => 100, :recursive => false)
|
94
|
+
assert_equal(CvChain, contours.class)
|
95
|
+
assert(contours.size > 0)
|
96
|
+
assert(contours.all? { |c| c.class == CvPoint })
|
97
|
+
|
98
|
+
# Uncomment the following lines to show the result
|
99
|
+
# contours = chain.approx_chains
|
100
|
+
# dst = mat0.clone.zero
|
101
|
+
# begin
|
102
|
+
# dst.draw_contours!(contours, CvColor::White, CvColor::Black, 2,
|
103
|
+
# :thickness => 1, :line_type => :aa)
|
104
|
+
# end while (contours = contours.h_next)
|
105
|
+
# snap dst
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|