bonanza-ruby-opencv 0.0.13.20140330211753
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.yardopts +3 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +9 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +239 -0
- data/README.md +98 -0
- data/Rakefile +99 -0
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -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/facerec/create_csv.rb +43 -0
- data/examples/facerec/facerec_eigenfaces.rb +132 -0
- data/examples/facerec/facerec_fisherfaces.rb +131 -0
- data/examples/facerec/facerec_lbph.rb +116 -0
- data/examples/facerec/readme.md +111 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/images/box.png +0 -0
- data/examples/images/box_in_scene.png +0 -0
- data/examples/images/inpaint.png +0 -0
- data/examples/images/lena-256x256.jpg +0 -0
- data/examples/images/lena-eyes.jpg +0 -0
- data/examples/images/lenna-rotated.jpg +0 -0
- data/examples/images/lenna.jpg +0 -0
- data/examples/images/stuff.jpg +0 -0
- data/examples/images/tiffany.jpg +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/match_template.rb +26 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/ext/opencv/algorithm.cpp +291 -0
- data/ext/opencv/algorithm.h +38 -0
- data/ext/opencv/curve.cpp +127 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +64 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +195 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +607 -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 +126 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvconnectedcomp.cpp +156 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +332 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +96 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +92 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +115 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +123 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +228 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +148 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +715 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +178 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +159 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +6829 -0
- data/ext/opencv/cvmat.h +323 -0
- data/ext/opencv/cvmemstorage.cpp +73 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +293 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +265 -0
- data/ext/opencv/cvpoint.h +67 -0
- data/ext/opencv/cvpoint2d32f.cpp +216 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +252 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +441 -0
- data/ext/opencv/cvrect.h +88 -0
- data/ext/opencv/cvscalar.cpp +301 -0
- data/ext/opencv/cvscalar.h +76 -0
- data/ext/opencv/cvseq.cpp +605 -0
- data/ext/opencv/cvseq.h +74 -0
- data/ext/opencv/cvsize.cpp +227 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +215 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +126 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsurfparams.cpp +208 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +279 -0
- data/ext/opencv/cvsurfpoint.h +54 -0
- data/ext/opencv/cvtermcriteria.cpp +198 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +122 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +221 -0
- data/ext/opencv/cvutils.h +31 -0
- data/ext/opencv/cvvideowriter.cpp +142 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/eigenfaces.cpp +75 -0
- data/ext/opencv/eigenfaces.h +30 -0
- data/ext/opencv/extconf.rb +82 -0
- data/ext/opencv/facerecognizer.cpp +181 -0
- data/ext/opencv/facerecognizer.h +46 -0
- data/ext/opencv/fisherfaces.cpp +75 -0
- data/ext/opencv/fisherfaces.h +30 -0
- data/ext/opencv/gui.cpp +71 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +198 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +666 -0
- data/ext/opencv/iplimage.h +75 -0
- data/ext/opencv/lbph.cpp +78 -0
- data/ext/opencv/lbph.h +30 -0
- data/ext/opencv/mouseevent.cpp +186 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +833 -0
- data/ext/opencv/opencv.h +405 -0
- data/ext/opencv/pointset.cpp +280 -0
- data/ext/opencv/pointset.h +68 -0
- data/ext/opencv/trackbar.cpp +127 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +377 -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/lib/opencv.rb +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +4 -0
- data/test/eigenfaces_save.xml +7524 -0
- data/test/fisherfaces_save.xml +7530 -0
- data/test/helper.rb +166 -0
- data/test/lbph_save.xml +4304 -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 +3003 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2085 -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_eigenfaces.rb +93 -0
- data/test/test_fisherfaces.rb +93 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +232 -0
- data/test/test_lbph.rb +152 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +360 -0
- data/test/test_pointset.rb +128 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- data/yard_extension.rb +5 -0
- metadata +399 -0
@@ -0,0 +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
|
+
|
@@ -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
|
+
|