afeld-opencv 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/Gemfile +6 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +217 -0
- data/README.rdoc +161 -0
- data/Rakefile +52 -0
- data/examples/alpha_blend.rb +21 -0
- data/examples/box.png +0 -0
- data/examples/box_in_scene.png +0 -0
- data/examples/contours/bitmap-contours-with-labels.png +0 -0
- data/examples/contours/bitmap-contours.png +0 -0
- data/examples/contours/bounding-box-detect-canny.rb +62 -0
- data/examples/contours/contour_retrieval_modes.rb +139 -0
- data/examples/contours/rotated-boxes.jpg +0 -0
- data/examples/convexhull.rb +47 -0
- data/examples/face_detect.rb +20 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/lenna-rotated.jpg +0 -0
- data/examples/lenna.jpg +0 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/examples/stuff.jpg +0 -0
- data/examples/tiffany.jpg +0 -0
- data/ext/opencv/curve.cpp +112 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +67 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +197 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +499 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +230 -0
- data/ext/opencv/cvchain.h +46 -0
- data/ext/opencv/cvcircle32f.cpp +116 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvcondensation.cpp +282 -0
- data/ext/opencv/cvcondensation.h +49 -0
- data/ext/opencv/cvconnectedcomp.cpp +143 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +297 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +91 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +103 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +159 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +125 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +208 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +546 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +139 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +154 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +5627 -0
- data/ext/opencv/cvmat.h +280 -0
- data/ext/opencv/cvmatnd.cpp +44 -0
- data/ext/opencv/cvmatnd.h +28 -0
- data/ext/opencv/cvmemstorage.cpp +68 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +287 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +228 -0
- data/ext/opencv/cvpoint.h +64 -0
- data/ext/opencv/cvpoint2d32f.cpp +211 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +246 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +333 -0
- data/ext/opencv/cvrect.h +79 -0
- data/ext/opencv/cvscalar.cpp +236 -0
- data/ext/opencv/cvscalar.h +71 -0
- data/ext/opencv/cvseq.cpp +599 -0
- data/ext/opencv/cvseq.h +72 -0
- data/ext/opencv/cvsize.cpp +221 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +209 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +120 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsparsemat.cpp +44 -0
- data/ext/opencv/cvsparsemat.h +28 -0
- data/ext/opencv/cvsurfparams.cpp +199 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +223 -0
- data/ext/opencv/cvsurfpoint.h +52 -0
- data/ext/opencv/cvtermcriteria.cpp +192 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +116 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +194 -0
- data/ext/opencv/cvutils.h +29 -0
- data/ext/opencv/cvvideowriter.cpp +137 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/gui.cpp +68 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +192 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +576 -0
- data/ext/opencv/iplimage.h +70 -0
- data/ext/opencv/lib/opencv.rb +3 -0
- data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
- data/ext/opencv/lib/opencv/version.rb +3 -0
- data/ext/opencv/mouseevent.cpp +181 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +710 -0
- data/ext/opencv/opencv.h +400 -0
- data/ext/opencv/pointset.cpp +284 -0
- data/ext/opencv/pointset.h +69 -0
- data/ext/opencv/trackbar.cpp +121 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +357 -0
- data/ext/opencv/window.h +66 -0
- data/extconf.rb +65 -0
- data/images/CvMat_sobel.png +0 -0
- data/images/CvMat_sub_rect.png +0 -0
- data/images/CvSeq_relationmap.png +0 -0
- data/images/face_detect_from_lena.jpg +0 -0
- data/test/helper.rb +146 -0
- data/test/runner.rb +30 -0
- data/test/samples/airplane.jpg +0 -0
- data/test/samples/baboon.jpg +0 -0
- data/test/samples/baboon200.jpg +0 -0
- data/test/samples/baboon200_rotated.jpg +0 -0
- data/test/samples/blank0.jpg +0 -0
- data/test/samples/blank1.jpg +0 -0
- data/test/samples/blank2.jpg +0 -0
- data/test/samples/blank3.jpg +0 -0
- data/test/samples/blank4.jpg +0 -0
- data/test/samples/blank5.jpg +0 -0
- data/test/samples/blank6.jpg +0 -0
- data/test/samples/blank7.jpg +0 -0
- data/test/samples/blank8.jpg +0 -0
- data/test/samples/blank9.jpg +0 -0
- data/test/samples/cat.jpg +0 -0
- data/test/samples/contours.jpg +0 -0
- data/test/samples/fruits.jpg +0 -0
- data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
- data/test/samples/inpaint-mask.bmp +0 -0
- data/test/samples/lena-256x256.jpg +0 -0
- data/test/samples/lena-32x32.jpg +0 -0
- data/test/samples/lena-eyes.jpg +0 -0
- data/test/samples/lena-inpaint.jpg +0 -0
- data/test/samples/lena.jpg +0 -0
- data/test/samples/lines.jpg +0 -0
- data/test/samples/messy0.jpg +0 -0
- data/test/samples/messy1.jpg +0 -0
- data/test/samples/movie_sample.avi +0 -0
- data/test/samples/one_way_train_0000.jpg +0 -0
- data/test/samples/one_way_train_0001.jpg +0 -0
- data/test/samples/partially_blank0.jpg +0 -0
- data/test/samples/partially_blank1.jpg +0 -0
- data/test/samples/smooth0.jpg +0 -0
- data/test/samples/smooth1.jpg +0 -0
- data/test/samples/smooth2.jpg +0 -0
- data/test/samples/smooth3.jpg +0 -0
- data/test/samples/smooth4.jpg +0 -0
- data/test/samples/smooth5.jpg +0 -0
- data/test/samples/smooth6.jpg +0 -0
- data/test/samples/str-cv-rotated.jpg +0 -0
- data/test/samples/str-cv.jpg +0 -0
- data/test/samples/str-ov.jpg +0 -0
- data/test/samples/stuff.jpg +0 -0
- data/test/test_curve.rb +43 -0
- data/test/test_cvavgcomp.rb +24 -0
- data/test/test_cvbox2d.rb +76 -0
- data/test/test_cvcapture.rb +183 -0
- data/test/test_cvchain.rb +108 -0
- data/test/test_cvcircle32f.rb +41 -0
- data/test/test_cvconnectedcomp.rb +61 -0
- data/test/test_cvcontour.rb +150 -0
- data/test/test_cvcontourtree.rb +43 -0
- data/test/test_cverror.rb +50 -0
- data/test/test_cvfeaturetree.rb +65 -0
- data/test/test_cvfont.rb +58 -0
- data/test/test_cvhaarclassifiercascade.rb +63 -0
- data/test/test_cvhistogram.rb +271 -0
- data/test/test_cvhumoments.rb +83 -0
- data/test/test_cvline.rb +50 -0
- data/test/test_cvmat.rb +2752 -0
- data/test/test_cvmat_drawing.rb +318 -0
- data/test/test_cvmat_dxt.rb +147 -0
- data/test/test_cvmat_imageprocessing.rb +1943 -0
- data/test/test_cvmoments.rb +180 -0
- data/test/test_cvpoint.rb +75 -0
- data/test/test_cvpoint2d32f.rb +75 -0
- data/test/test_cvpoint3d32f.rb +93 -0
- data/test/test_cvrect.rb +144 -0
- data/test/test_cvscalar.rb +113 -0
- data/test/test_cvseq.rb +295 -0
- data/test/test_cvsize.rb +75 -0
- data/test/test_cvsize2d32f.rb +75 -0
- data/test/test_cvslice.rb +31 -0
- data/test/test_cvsurfparams.rb +57 -0
- data/test/test_cvsurfpoint.rb +66 -0
- data/test/test_cvtermcriteria.rb +56 -0
- data/test/test_cvtwopoints.rb +40 -0
- data/test/test_cvvideowriter.rb +58 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +156 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +340 -0
- data/test/test_pointset.rb +130 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- metadata +399 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8-unix -*-
|
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
|
+
|
data/test/test_cvseq.rb
ADDED
@@ -0,0 +1,295 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8-unix -*-
|
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::CvSeq
|
10
|
+
class TestCvSeq < OpenCVTestCase
|
11
|
+
def test_initialize
|
12
|
+
# assert_not_nil(CvSeq.new(CvIndex))
|
13
|
+
assert_not_nil(CvSeq.new(Fixnum))
|
14
|
+
assert_not_nil(CvSeq.new(CvPoint))
|
15
|
+
assert_not_nil(CvSeq.new(CvPoint2D32f))
|
16
|
+
assert_not_nil(CvSeq.new(CvPoint3D32f))
|
17
|
+
|
18
|
+
assert(CvSeq.new(CvPoint).is_a? Enumerable)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_total
|
22
|
+
seq1 = CvSeq.new(CvPoint)
|
23
|
+
assert_equal(0, seq1.total)
|
24
|
+
|
25
|
+
seq1.push(CvPoint.new(1, 2))
|
26
|
+
assert_equal(1, seq1.total)
|
27
|
+
|
28
|
+
seq1.push(CvPoint.new(3, 4))
|
29
|
+
assert_equal(2, seq1.total)
|
30
|
+
# Alias
|
31
|
+
assert_equal(2, seq1.length)
|
32
|
+
assert_equal(2, seq1.size)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_empty
|
36
|
+
assert(CvSeq.new(CvPoint).empty?)
|
37
|
+
assert(CvSeq.new(CvPoint2D32f).empty?)
|
38
|
+
assert(CvSeq.new(CvPoint3D32f).empty?)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_aref
|
42
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
|
43
|
+
|
44
|
+
assert_equal(CvPoint, seq1[0].class)
|
45
|
+
assert_equal(10, seq1[0].x)
|
46
|
+
assert_equal(20, seq1[0].y)
|
47
|
+
assert_equal(30, seq1[1].x)
|
48
|
+
assert_equal(40, seq1[1].y)
|
49
|
+
assert_equal(50, seq1[2].x)
|
50
|
+
assert_equal(60, seq1[2].y)
|
51
|
+
|
52
|
+
seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
|
53
|
+
|
54
|
+
assert_equal(Fixnum, seq2[0].class)
|
55
|
+
assert_equal(10, seq2[0])
|
56
|
+
assert_equal(20, seq2[1])
|
57
|
+
assert_equal(30, seq2[2])
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_push
|
61
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
|
62
|
+
|
63
|
+
assert_equal(2, seq1.total)
|
64
|
+
assert_equal(CvPoint, seq1[0].class)
|
65
|
+
assert_equal(10, seq1[0].x)
|
66
|
+
assert_equal(20, seq1[0].y)
|
67
|
+
assert_equal(CvPoint, seq1[1].class)
|
68
|
+
assert_equal(30, seq1[1].x)
|
69
|
+
assert_equal(40, seq1[1].y)
|
70
|
+
|
71
|
+
seq2 = CvSeq.new(CvPoint).push(CvPoint.new(50, 60))
|
72
|
+
seq2.push(seq1)
|
73
|
+
assert_equal(3, seq2.total)
|
74
|
+
assert_equal(CvPoint, seq2[0].class)
|
75
|
+
assert_equal(50, seq2[0].x)
|
76
|
+
assert_equal(60, seq2[0].y)
|
77
|
+
assert_equal(CvPoint, seq2[1].class)
|
78
|
+
assert_equal(10, seq2[1].x)
|
79
|
+
assert_equal(20, seq2[1].y)
|
80
|
+
assert_equal(CvPoint, seq2[2].class)
|
81
|
+
assert_equal(30, seq2[2].x)
|
82
|
+
assert_equal(40, seq2[2].y)
|
83
|
+
|
84
|
+
seq3 = CvSeq.new(Fixnum).push(10)
|
85
|
+
seq4 = CvSeq.new(Fixnum).push(20, 30)
|
86
|
+
seq3.push(seq4)
|
87
|
+
assert_equal(3, seq3.total)
|
88
|
+
assert_equal(Fixnum, seq3[0].class)
|
89
|
+
assert_equal(10, seq3[0])
|
90
|
+
assert_equal(20, seq3[1])
|
91
|
+
assert_equal(30, seq3[2])
|
92
|
+
|
93
|
+
assert_raise(TypeError) {
|
94
|
+
seq1.push(CvPoint2D32f.new(55.5, 66.6))
|
95
|
+
}
|
96
|
+
|
97
|
+
assert_raise(TypeError) {
|
98
|
+
seq3 = CvSeq.new(CvPoint2D32f).push(CvPoint2D32f.new(55.5, 66.6))
|
99
|
+
seq1.push(seq3)
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_pop
|
104
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
|
105
|
+
point1 = seq1.pop
|
106
|
+
assert_equal(CvPoint, point1.class)
|
107
|
+
assert_equal(30, point1.x)
|
108
|
+
assert_equal(40, point1.y)
|
109
|
+
|
110
|
+
assert_equal(1, seq1.total)
|
111
|
+
assert_equal(CvPoint, seq1[0].class)
|
112
|
+
assert_equal(10, seq1[0].x)
|
113
|
+
assert_equal(20, seq1[0].y)
|
114
|
+
|
115
|
+
assert_nil(CvSeq.new(CvPoint).pop)
|
116
|
+
|
117
|
+
seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
|
118
|
+
assert_equal(30, seq2.pop)
|
119
|
+
assert_equal(20, seq2.pop)
|
120
|
+
assert_equal(10, seq2.pop)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_clear
|
124
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
|
125
|
+
seq1.clear
|
126
|
+
assert_not_nil(seq1)
|
127
|
+
assert_equal(0, seq1.total)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_unshift
|
131
|
+
seq1 = CvSeq.new(CvPoint).unshift(CvPoint.new(10, 20), CvPoint.new(30, 40))
|
132
|
+
|
133
|
+
assert_equal(2, seq1.total)
|
134
|
+
assert_equal(CvPoint, seq1[0].class)
|
135
|
+
assert_equal(30, seq1[0].x)
|
136
|
+
assert_equal(40, seq1[0].y)
|
137
|
+
assert_equal(CvPoint, seq1[1].class)
|
138
|
+
assert_equal(10, seq1[1].x)
|
139
|
+
assert_equal(20, seq1[1].y)
|
140
|
+
|
141
|
+
seq2 = CvSeq.new(CvPoint).unshift(CvPoint.new(50, 60))
|
142
|
+
seq2.unshift(seq1)
|
143
|
+
assert_equal(3, seq2.total)
|
144
|
+
assert_equal(CvPoint, seq1[0].class)
|
145
|
+
assert_equal(30, seq1[0].x)
|
146
|
+
assert_equal(40, seq1[0].y)
|
147
|
+
assert_equal(CvPoint, seq1[1].class)
|
148
|
+
assert_equal(10, seq1[1].x)
|
149
|
+
assert_equal(20, seq1[1].y)
|
150
|
+
assert_equal(CvPoint, seq2[2].class)
|
151
|
+
assert_equal(50, seq2[2].x)
|
152
|
+
assert_equal(60, seq2[2].y)
|
153
|
+
|
154
|
+
seq3 = CvSeq.new(Fixnum).unshift(10, 20, 30)
|
155
|
+
assert_equal(3, seq3.total)
|
156
|
+
assert_equal(30, seq3[0])
|
157
|
+
assert_equal(20, seq3[1])
|
158
|
+
assert_equal(10, seq3[2])
|
159
|
+
|
160
|
+
assert_raise(TypeError) {
|
161
|
+
seq1.unshift(CvPoint2D32f.new(55.5, 66.6))
|
162
|
+
}
|
163
|
+
|
164
|
+
assert_raise(TypeError) {
|
165
|
+
seq3 = CvSeq.new(CvPoint2D32f).push(CvPoint2D32f.new(55.5, 66.6))
|
166
|
+
seq1.unshift(seq3)
|
167
|
+
}
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_shift
|
171
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
|
172
|
+
point1 = seq1.shift
|
173
|
+
assert_equal(CvPoint, point1.class)
|
174
|
+
assert_equal(10, point1.x)
|
175
|
+
assert_equal(20, point1.y)
|
176
|
+
|
177
|
+
assert_equal(1, seq1.total)
|
178
|
+
assert_equal(CvPoint, seq1[0].class)
|
179
|
+
assert_equal(30, seq1[0].x)
|
180
|
+
assert_equal(40, seq1[0].y)
|
181
|
+
|
182
|
+
seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
|
183
|
+
assert_equal(10, seq2.shift)
|
184
|
+
assert_equal(20, seq2.shift)
|
185
|
+
assert_equal(30, seq2.shift)
|
186
|
+
|
187
|
+
assert_nil(CvSeq.new(CvPoint).shift)
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_first
|
191
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
|
192
|
+
point1 = seq1.first
|
193
|
+
assert_equal(CvPoint, point1.class)
|
194
|
+
assert_equal(10, point1.x)
|
195
|
+
assert_equal(20, point1.y)
|
196
|
+
|
197
|
+
seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
|
198
|
+
assert_equal(10, seq2.first)
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_last
|
202
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
|
203
|
+
point1 = seq1.last
|
204
|
+
assert_equal(CvPoint, point1.class)
|
205
|
+
assert_equal(50, point1.x)
|
206
|
+
assert_equal(60, point1.y)
|
207
|
+
|
208
|
+
seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
|
209
|
+
assert_equal(30, seq2.last)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_each
|
213
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
|
214
|
+
i = 0
|
215
|
+
seq1.each { |s|
|
216
|
+
assert_equal(CvPoint, s.class)
|
217
|
+
assert_equal(seq1[i].x, s.x)
|
218
|
+
assert_equal(seq1[i].y, s.y)
|
219
|
+
i += 1
|
220
|
+
}
|
221
|
+
assert_equal(3, i)
|
222
|
+
|
223
|
+
seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
|
224
|
+
i = 0
|
225
|
+
seq2.each { |s|
|
226
|
+
assert_equal(seq2[i], s)
|
227
|
+
i += 1
|
228
|
+
}
|
229
|
+
assert_equal(3, i)
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_each_index
|
233
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
|
234
|
+
n = 0
|
235
|
+
seq1.each_index { |i|
|
236
|
+
assert_equal(n, i)
|
237
|
+
n += 1
|
238
|
+
}
|
239
|
+
assert_equal(3, n)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_insert
|
243
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
|
244
|
+
seq1.insert(1, CvPoint.new(50, 60))
|
245
|
+
assert_equal(3, seq1.total)
|
246
|
+
assert_equal(CvPoint, seq1[0].class)
|
247
|
+
assert_equal(10, seq1[0].x)
|
248
|
+
assert_equal(20, seq1[0].y)
|
249
|
+
assert_equal(CvPoint, seq1[1].class)
|
250
|
+
assert_equal(50, seq1[1].x)
|
251
|
+
assert_equal(60, seq1[1].y)
|
252
|
+
assert_equal(CvPoint, seq1[2].class)
|
253
|
+
assert_equal(30, seq1[2].x)
|
254
|
+
assert_equal(40, seq1[2].y)
|
255
|
+
|
256
|
+
seq2 = CvSeq.new(Fixnum).push(10, 20)
|
257
|
+
seq2.insert(1, 15)
|
258
|
+
assert_equal(3, seq2.total)
|
259
|
+
assert_equal(10, seq2[0])
|
260
|
+
assert_equal(15, seq2[1])
|
261
|
+
assert_equal(20, seq2[2])
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_remove
|
265
|
+
seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
|
266
|
+
|
267
|
+
seq1.remove(1)
|
268
|
+
assert_equal(2, seq1.total)
|
269
|
+
assert_equal(CvPoint, seq1[0].class)
|
270
|
+
assert_equal(10, seq1[0].x)
|
271
|
+
assert_equal(20, seq1[0].y)
|
272
|
+
assert_equal(CvPoint, seq1[1].class)
|
273
|
+
assert_equal(50, seq1[1].x)
|
274
|
+
assert_equal(60, seq1[1].y)
|
275
|
+
end
|
276
|
+
|
277
|
+
# These methods are tested in TestCvMat_imageprocessing#test_find_contours
|
278
|
+
# (test_cvmat_imageprocessing.rb)
|
279
|
+
# def test_h_prev
|
280
|
+
# flunk('FIXME: CvSeq#h_prev is not tested yet.')
|
281
|
+
# end
|
282
|
+
|
283
|
+
# def test_h_next
|
284
|
+
# flunk('FIXME: CvSeq#h_next is not tested yet.')
|
285
|
+
# end
|
286
|
+
|
287
|
+
# def test_v_prev
|
288
|
+
# flunk('FIXME: CvSeq#v_prev is not tested yet.')
|
289
|
+
# end
|
290
|
+
|
291
|
+
# def test_v_next
|
292
|
+
# flunk('FIXME: CvSeq#v_next is not tested yet.')
|
293
|
+
# end
|
294
|
+
end
|
295
|
+
|
data/test/test_cvsize.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8-unix -*-
|
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::CvSize
|
10
|
+
class TestCvSize < OpenCVTestCase
|
11
|
+
class MySize; end
|
12
|
+
|
13
|
+
def test_width
|
14
|
+
size = CvSize.new
|
15
|
+
size.width = 100
|
16
|
+
assert_equal(100, size.width)
|
17
|
+
size.width = 200
|
18
|
+
assert_equal(200, size.width)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_height
|
22
|
+
size = CvSize.new
|
23
|
+
size.height = 100
|
24
|
+
assert_equal(100, size.height)
|
25
|
+
size.height = 200
|
26
|
+
assert_equal(200, size.height)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_compatible
|
30
|
+
assert(!(CvSize.compatible? MySize.new))
|
31
|
+
MySize.class_eval { def width; end }
|
32
|
+
assert(!(CvSize.compatible? MySize.new))
|
33
|
+
MySize.class_eval { def height; end }
|
34
|
+
assert(CvSize.compatible? MySize.new)
|
35
|
+
assert(CvSize.compatible? CvSize.new)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_initialize
|
39
|
+
size = CvSize.new
|
40
|
+
assert_equal(0, size.width)
|
41
|
+
assert_equal(0, size.height)
|
42
|
+
|
43
|
+
size = CvSize.new(10, 20)
|
44
|
+
assert_equal(10, size.width)
|
45
|
+
assert_equal(20, size.height)
|
46
|
+
|
47
|
+
size = CvSize.new(CvSize.new(10, 20))
|
48
|
+
assert_equal(10, size.width)
|
49
|
+
assert_equal(20, size.height)
|
50
|
+
|
51
|
+
assert_raise(TypeError) {
|
52
|
+
CvSize.new(DUMMY_OBJ)
|
53
|
+
}
|
54
|
+
assert_raise(ArgumentError) {
|
55
|
+
CvSize.new(1, 2, 3)
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_to_s
|
60
|
+
size = CvSize.new(10, 20)
|
61
|
+
assert_equal('<OpenCV::CvSize:10x20>', size.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_to_ary
|
65
|
+
a = CvSize.new(10, 20).to_ary
|
66
|
+
assert_equal(10, a[0])
|
67
|
+
assert_equal(20, a[1])
|
68
|
+
|
69
|
+
# Alias
|
70
|
+
a = CvSize.new(10, 20).to_a
|
71
|
+
assert_equal(10, a[0])
|
72
|
+
assert_equal(20, a[1])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|