ruby-opencv 0.0.9.pre2-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +8 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +227 -0
- data/README.md +98 -0
- data/Rakefile +90 -0
- data/config.yml +7 -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/matching_to_many_images.rb +16 -0
- data/examples/matching_to_many_images/query.png +0 -0
- data/examples/matching_to_many_images/train/1.png +0 -0
- data/examples/matching_to_many_images/train/2.png +0 -0
- data/examples/matching_to_many_images/train/3.png +0 -0
- data/examples/matching_to_many_images/train/trainImages.txt +3 -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 +506 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +233 -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 +296 -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 +5848 -0
- data/ext/opencv/cvmat.h +284 -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 +245 -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 +74 -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 +192 -0
- data/ext/opencv/cvutils.h +30 -0
- data/ext/opencv/cvvideowriter.cpp +137 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/extconf.rb +83 -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 +644 -0
- data/ext/opencv/iplimage.h +73 -0
- data/ext/opencv/mouseevent.cpp +181 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +722 -0
- data/ext/opencv/opencv.h +400 -0
- data/ext/opencv/pointset.cpp +274 -0
- data/ext/opencv/pointset.h +68 -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/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/lib/opencv.rb +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +3 -0
- data/ruby-opencv.gemspec +44 -0
- data/test/helper.rb +166 -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/chessboard.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 +2947 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2025 -0
- data/test/test_cvmat_matching.rb +57 -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 +236 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +324 -0
- data/test/test_pointset.rb +126 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- metadata +386 -0
@@ -0,0 +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
|
+
|
@@ -0,0 +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
|
+
|
@@ -0,0 +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
|
+
|
@@ -0,0 +1,43 @@
|
|
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::CvContourTree
|
10
|
+
class TestCvContourTree < OpenCVTestCase
|
11
|
+
def setup
|
12
|
+
@tree = CvContourTree.new(CvPoint)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialize
|
16
|
+
tree = CvContourTree.new(CvPoint)
|
17
|
+
assert_equal(CvContourTree, tree.class)
|
18
|
+
assert(tree.is_a? CvSeq)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_p1
|
22
|
+
assert_equal(CvPoint, @tree.p1.class)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_p2
|
26
|
+
assert_equal(CvPoint, @tree.p2.class)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_contour
|
30
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
31
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
32
|
+
}
|
33
|
+
contour = mat0.find_contours
|
34
|
+
tree = contour.create_tree
|
35
|
+
contour = tree.contour(CvTermCriteria.new(100, 0.01))
|
36
|
+
assert_equal(CvContour, contour.class)
|
37
|
+
|
38
|
+
assert_raise(CvStsBadArg) {
|
39
|
+
tree.contour(CvTermCriteria.new(0, 0))
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +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::CvError
|
10
|
+
class TestCvError < OpenCVTestCase
|
11
|
+
def test_cverror
|
12
|
+
assert_equal(StandardError, CvError.superclass)
|
13
|
+
begin
|
14
|
+
raise CvError
|
15
|
+
rescue
|
16
|
+
assert_equal(CvError, $!.class)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_subclass
|
21
|
+
errors = [CvStsBackTrace, CvStsError, CvStsInternal, CvStsNoMem, CvStsBadArg, CvStsBadFunc, CvStsNoConv, CvStsAutoTrace, CvHeaderIsNull, CvBadImageSize, CvBadOffset, CvBadDataPtr, CvBadStep, CvBadModelOrChSeq, CvBadNumChannels, CvBadNumChannel1U, CvBadDepth, CvBadAlphaChannel, CvBadOrder, CvBadOrigin, CvBadAlign, CvBadCallBack, CvBadTileSize, CvBadCOI, CvBadROISize, CvMaskIsTiled, CvStsNullPtr, CvStsVecLengthErr, CvStsFilterStructContentErr, CvStsKernelStructContentErr, CvStsFilterOffsetErr, CvStsBadSize, CvStsDivByZero, CvStsInplaceNotSupported, CvStsObjectNotFound, CvStsUnmatchedFormats, CvStsBadFlag, CvStsBadPoint, CvStsBadMask, CvStsUnmatchedSizes, CvStsUnsupportedFormat, CvStsOutOfRange, CvStsParseError, CvStsNotImplemented, CvStsBadMemBlock, CvStsAssert, CvGpuNotSupported, CvGpuApiCallError]
|
22
|
+
|
23
|
+
errors.each { |err|
|
24
|
+
assert_equal(CvError, err.superclass)
|
25
|
+
|
26
|
+
begin
|
27
|
+
raise err
|
28
|
+
rescue err
|
29
|
+
assert_equal(err, $!.class)
|
30
|
+
rescue
|
31
|
+
flunk("Failed to catch #{err}")
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
raise err
|
36
|
+
rescue CvError
|
37
|
+
assert_equal(err, $!.class)
|
38
|
+
rescue
|
39
|
+
flunk("Failed to catch #{err}")
|
40
|
+
end
|
41
|
+
|
42
|
+
begin
|
43
|
+
raise err
|
44
|
+
rescue
|
45
|
+
assert_equal(err, $!.class)
|
46
|
+
end
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,65 @@
|
|
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::CvFeatureTree
|
10
|
+
class TestCvFeatureTree < OpenCVTestCase
|
11
|
+
def test_initialize
|
12
|
+
desc = CvMat.new(1, 1, :cv32f, 1)
|
13
|
+
ft = CvFeatureTree.new(desc)
|
14
|
+
assert_equal(CvFeatureTree, ft.class)
|
15
|
+
|
16
|
+
assert_raise(TypeError) {
|
17
|
+
CvFeatureTree.new(DUMMY_OBJ)
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_find_feature
|
22
|
+
dim = 2
|
23
|
+
points = []
|
24
|
+
points << [99, 51]
|
25
|
+
points << [52, 57]
|
26
|
+
points << [57, 42]
|
27
|
+
points << [13, 39]
|
28
|
+
points << [15, 68]
|
29
|
+
points << [75, 11]
|
30
|
+
points << [69, 62]
|
31
|
+
points << [52, 46]
|
32
|
+
points << [0, 64]
|
33
|
+
points << [67, 16]
|
34
|
+
|
35
|
+
desc1 = CvMat.new(points.size, dim, :cv32f, 1)
|
36
|
+
desc1.set_data(points)
|
37
|
+
|
38
|
+
pt = [[50, 50], [11, 40]]
|
39
|
+
desc2 = CvMat.new(pt.size, dim, :cv32f, 1)
|
40
|
+
desc2.set_data(pt)
|
41
|
+
|
42
|
+
ft = CvFeatureTree.new(desc1)
|
43
|
+
results, dist = ft.find_features(desc2, 1, 10)
|
44
|
+
|
45
|
+
assert_equal(CvMat, results.class)
|
46
|
+
assert_equal(CvMat, dist.class)
|
47
|
+
|
48
|
+
assert_equal(7, results[0][0].to_i)
|
49
|
+
assert_in_delta(4.472, dist[0][0], 0.001)
|
50
|
+
|
51
|
+
assert_equal(3, results[1][0].to_i)
|
52
|
+
assert_in_delta(2.236, dist[1][0], 0.001)
|
53
|
+
|
54
|
+
assert_raise(TypeError) {
|
55
|
+
ft.find_features(DUMMY_OBJ, 1, 10)
|
56
|
+
}
|
57
|
+
assert_raise(TypeError) {
|
58
|
+
ft.find_features(desc2, DUMMY_OBJ, 10)
|
59
|
+
}
|
60
|
+
assert_raise(TypeError) {
|
61
|
+
ft.find_features(desc2, 1, DUMMY_OBJ)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/test/test_cvfont.rb
ADDED
@@ -0,0 +1,58 @@
|
|
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::CvFont
|
10
|
+
class TestCvFont < OpenCVTestCase
|
11
|
+
def test_FACE
|
12
|
+
assert_equal(0, CvFont::FACE[:simplex])
|
13
|
+
assert_equal(1, CvFont::FACE[:plain])
|
14
|
+
assert_equal(2, CvFont::FACE[:duplex])
|
15
|
+
assert_equal(4, CvFont::FACE[:triplex])
|
16
|
+
assert_equal(5, CvFont::FACE[:complex_small])
|
17
|
+
assert_equal(6, CvFont::FACE[:script_simplex])
|
18
|
+
assert_equal(7, CvFont::FACE[:script_complex])
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_FONT_OPTION
|
22
|
+
assert_equal(1.0, CvFont::FONT_OPTION[:hscale])
|
23
|
+
assert_equal(1.0, CvFont::FONT_OPTION[:vscale])
|
24
|
+
assert_equal(0, CvFont::FONT_OPTION[:shear])
|
25
|
+
assert_equal(1, CvFont::FONT_OPTION[:thickness])
|
26
|
+
assert_equal(8, CvFont::FONT_OPTION[:line_type])
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_initialize
|
30
|
+
font = CvFont.new(:simplex)
|
31
|
+
assert_equal(0, font.face)
|
32
|
+
assert_equal(1.0, font.hscale)
|
33
|
+
assert_equal(1.0, font.vscale)
|
34
|
+
assert_equal(0, font.shear)
|
35
|
+
assert_equal(1, font.thickness)
|
36
|
+
assert_equal(8, font.line_type)
|
37
|
+
assert_false(font.italic)
|
38
|
+
|
39
|
+
font = CvFont.new(:plain, :hscale => 2.5, :vscale => 3.5,
|
40
|
+
:shear => 0.5, :thickness => 3, :line_type => 2, :italic => false)
|
41
|
+
assert_equal(1, font.face)
|
42
|
+
assert_equal(2.5, font.hscale)
|
43
|
+
assert_equal(3.5, font.vscale)
|
44
|
+
assert_equal(0.5, font.shear)
|
45
|
+
assert_equal(3, font.thickness)
|
46
|
+
assert_equal(2, font.line_type)
|
47
|
+
assert_false(font.italic)
|
48
|
+
|
49
|
+
font = CvFont.new(:simplex, :italic => true)
|
50
|
+
assert_equal(16, font.face)
|
51
|
+
assert(font.italic)
|
52
|
+
|
53
|
+
assert_raise(ArgumentError) {
|
54
|
+
CvFont.new(:foo)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|