ruby-opencv 0.0.8.pre-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/Gemfile +8 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +225 -0
- data/README.rdoc +149 -0
- data/Rakefile +32 -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 +499 -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 +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 +644 -0
- data/ext/opencv/iplimage.h +73 -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 +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/extconf.rb +75 -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 +3 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +3 -0
- data/ruby-opencv.gemspec +43 -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 +414 -0
@@ -0,0 +1,54 @@
|
|
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::IplConvKernel
|
10
|
+
class TestIplConvKernel < OpenCVTestCase
|
11
|
+
def test_initialize
|
12
|
+
[:rect, :cross, :ellipse, CV_SHAPE_RECT, CV_SHAPE_CROSS, CV_SHAPE_ELLIPSE].each { |shape|
|
13
|
+
kernel = IplConvKernel.new(5, 5, 2, 2, shape)
|
14
|
+
assert_not_nil(kernel)
|
15
|
+
}
|
16
|
+
|
17
|
+
values = [1] * 25
|
18
|
+
[:custom, CV_SHAPE_CUSTOM].each { |shape|
|
19
|
+
kernel = IplConvKernel.new(5, 5, 2, 2, shape, values)
|
20
|
+
assert_not_nil(kernel)
|
21
|
+
}
|
22
|
+
|
23
|
+
[:custom, CV_SHAPE_CUSTOM].each { |shape|
|
24
|
+
assert_raise(ArgumentError) {
|
25
|
+
IplConvKernel.new(5, 5, 2, 2, shape)
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
assert_raise(TypeError) {
|
30
|
+
IplConvKernel.new(5, 5, 2, 2, :foobar)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_size
|
35
|
+
kernel = IplConvKernel.new(5, 4, 2, 2, :rect)
|
36
|
+
size = kernel.size
|
37
|
+
assert_equal(5, size.width)
|
38
|
+
assert_equal(4, size.height)
|
39
|
+
|
40
|
+
assert_equal(5, kernel.cols)
|
41
|
+
assert_equal(4, kernel.rows)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_anchor
|
45
|
+
kernel = IplConvKernel.new(5, 4, 3, 2, :rect)
|
46
|
+
a = kernel.anchor
|
47
|
+
assert_equal(3, a.x)
|
48
|
+
assert_equal(2, a.y)
|
49
|
+
|
50
|
+
assert_equal(3, kernel.anchor_x)
|
51
|
+
assert_equal(2, kernel.anchor_y)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,236 @@
|
|
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::IplImage
|
10
|
+
class TestIplImage < OpenCVTestCase
|
11
|
+
def should_classify_images_as(filename, classification)
|
12
|
+
assert_equal(OpenCV::IplImage::load(filename, OpenCV::CV_LOAD_IMAGE_GRAYSCALE).smoothness[0], classification)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialize
|
16
|
+
img = IplImage.new(10, 20)
|
17
|
+
assert_equal(10, img.width)
|
18
|
+
assert_equal(20, img.height)
|
19
|
+
assert_equal(:cv8u, img.depth)
|
20
|
+
assert_equal(3, img.channel)
|
21
|
+
|
22
|
+
img = IplImage.new(30, 40, :cv32f, 1)
|
23
|
+
assert_equal(30, img.width)
|
24
|
+
assert_equal(40, img.height)
|
25
|
+
assert_equal(:cv32f, img.depth)
|
26
|
+
assert_equal(1, img.channel)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_load
|
30
|
+
img1 = IplImage.load(FILENAME_CAT)
|
31
|
+
assert_equal(IplImage, img1.class)
|
32
|
+
assert_equal(375, img1.width)
|
33
|
+
assert_equal(500, img1.height)
|
34
|
+
assert_equal(:cv8u, img1.depth)
|
35
|
+
assert_equal(3, img1.channel)
|
36
|
+
|
37
|
+
img2 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_GRAYSCALE)
|
38
|
+
assert_equal(IplImage, img2.class)
|
39
|
+
assert_equal(375, img2.width)
|
40
|
+
assert_equal(500, img2.height)
|
41
|
+
assert_equal(:cv8u, img2.depth)
|
42
|
+
assert_equal(1, img2.channel)
|
43
|
+
|
44
|
+
img3 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR)
|
45
|
+
assert_equal(IplImage, img3.class)
|
46
|
+
assert_equal(375, img3.width)
|
47
|
+
assert_equal(500, img3.height)
|
48
|
+
assert_equal(:cv8u, img3.depth)
|
49
|
+
assert_equal(3, img3.channel)
|
50
|
+
|
51
|
+
assert_raise(ArgumentError) {
|
52
|
+
IplImage.load
|
53
|
+
}
|
54
|
+
assert_raise(TypeError) {
|
55
|
+
IplImage.load(123)
|
56
|
+
}
|
57
|
+
assert_raise(TypeError) {
|
58
|
+
IplImage.load(FILENAME_CAT, 'foobar')
|
59
|
+
}
|
60
|
+
assert_raise(StandardError) {
|
61
|
+
IplImage.load('file/does/not/exist')
|
62
|
+
}
|
63
|
+
|
64
|
+
# Uncomment the following lines to show the results
|
65
|
+
# snap img1, img2, img3
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_decode
|
69
|
+
data = nil
|
70
|
+
open(FILENAME_CAT, 'rb') { |f|
|
71
|
+
data = f.read
|
72
|
+
}
|
73
|
+
data_ary = data.unpack("c*")
|
74
|
+
data_mat = CvMat.new(1, data_ary.size).set_data(data_ary)
|
75
|
+
expected = IplImage.load(FILENAME_CAT)
|
76
|
+
|
77
|
+
img1 = IplImage.decode(data)
|
78
|
+
img2 = IplImage.decode(data_ary)
|
79
|
+
img3 = IplImage.decode(data_mat)
|
80
|
+
img4 = IplImage.decode(data, CV_LOAD_IMAGE_COLOR)
|
81
|
+
img5 = IplImage.decode(data_ary, CV_LOAD_IMAGE_COLOR)
|
82
|
+
img6 = IplImage.decode(data_mat, CV_LOAD_IMAGE_COLOR)
|
83
|
+
expected_hash = hash_img(expected)
|
84
|
+
|
85
|
+
[img1, img2, img3, img4, img5, img6].each { |img|
|
86
|
+
assert_equal(IplImage, img.class)
|
87
|
+
assert_equal(expected.rows, img.rows)
|
88
|
+
assert_equal(expected.cols, img.cols)
|
89
|
+
assert_equal(expected.channel, img.channel)
|
90
|
+
assert_equal(expected_hash, hash_img(img))
|
91
|
+
}
|
92
|
+
|
93
|
+
expected_c1 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_GRAYSCALE)
|
94
|
+
img1c1 = IplImage.decode(data, CV_LOAD_IMAGE_GRAYSCALE)
|
95
|
+
img2c1 = IplImage.decode(data_ary, CV_LOAD_IMAGE_GRAYSCALE)
|
96
|
+
img3c1 = IplImage.decode(data_mat, CV_LOAD_IMAGE_GRAYSCALE)
|
97
|
+
expected_hash_c1 = hash_img(expected_c1)
|
98
|
+
|
99
|
+
[img1c1, img2c1, img3c1].each { |img|
|
100
|
+
assert_equal(IplImage, img.class)
|
101
|
+
assert_equal(expected_c1.rows, img.rows)
|
102
|
+
assert_equal(expected_c1.cols, img.cols)
|
103
|
+
assert_equal(expected_c1.channel, img.channel)
|
104
|
+
assert_equal(expected_hash_c1, hash_img(img))
|
105
|
+
}
|
106
|
+
|
107
|
+
assert_raise(TypeError) {
|
108
|
+
IplImage.decode(DUMMY_OBJ)
|
109
|
+
}
|
110
|
+
assert_raise(TypeError) {
|
111
|
+
IplImage.decode(data, DUMMY_OBJ)
|
112
|
+
}
|
113
|
+
|
114
|
+
# Uncomment the following line to show the result images
|
115
|
+
# snap img1, img2, img3
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_roi
|
119
|
+
img = IplImage.new(20, 30)
|
120
|
+
rect = img.roi
|
121
|
+
assert_equal(0, rect.x)
|
122
|
+
assert_equal(0, rect.y)
|
123
|
+
assert_equal(img.width, rect.width)
|
124
|
+
assert_equal(img.height, rect.height)
|
125
|
+
|
126
|
+
img.set_roi(CvRect.new(2, 3, 10, 20))
|
127
|
+
rect = img.roi
|
128
|
+
assert_equal(2, rect.x)
|
129
|
+
assert_equal(3, rect.y)
|
130
|
+
assert_equal(10, rect.width)
|
131
|
+
assert_equal(20, rect.height)
|
132
|
+
|
133
|
+
img.reset_roi
|
134
|
+
rect = img.roi
|
135
|
+
assert_equal(0, rect.x)
|
136
|
+
assert_equal(0, rect.y)
|
137
|
+
assert_equal(img.width, rect.width)
|
138
|
+
assert_equal(img.height, rect.height)
|
139
|
+
|
140
|
+
img.set_roi(CvRect.new(1, 2, 5, 6)) {|image|
|
141
|
+
rect = image.roi
|
142
|
+
assert_equal(1, rect.x)
|
143
|
+
assert_equal(2, rect.y)
|
144
|
+
assert_equal(5, rect.width)
|
145
|
+
assert_equal(6, rect.height)
|
146
|
+
}
|
147
|
+
rect = img.roi
|
148
|
+
assert_equal(0, rect.x)
|
149
|
+
assert_equal(0, rect.y)
|
150
|
+
assert_equal(img.width, rect.width)
|
151
|
+
assert_equal(img.height, rect.height)
|
152
|
+
|
153
|
+
# Alias
|
154
|
+
img.roi = CvRect.new(4, 5, 11, 12)
|
155
|
+
rect = img.roi
|
156
|
+
assert_equal(4, rect.x)
|
157
|
+
assert_equal(5, rect.y)
|
158
|
+
assert_equal(11, rect.width)
|
159
|
+
assert_equal(12, rect.height)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_coi
|
163
|
+
img = IplImage.new(20, 30)
|
164
|
+
assert_equal(0, img.coi)
|
165
|
+
|
166
|
+
img.set_coi(1)
|
167
|
+
assert_equal(1, img.coi)
|
168
|
+
|
169
|
+
img.reset_coi
|
170
|
+
assert_equal(0, img.coi)
|
171
|
+
|
172
|
+
img.set_coi(2) {|image|
|
173
|
+
assert_equal(2, image.coi)
|
174
|
+
}
|
175
|
+
assert_equal(0, img.coi)
|
176
|
+
|
177
|
+
# Alias
|
178
|
+
img.coi = 1
|
179
|
+
assert_equal(1, img.coi)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_smoothness
|
183
|
+
asset_path = File.join(File.dirname(__FILE__), 'samples')
|
184
|
+
|
185
|
+
for image in Array.new(7) { |e| e = File.join(asset_path, "smooth%d.jpg") % e } do
|
186
|
+
should_classify_images_as image, :smooth
|
187
|
+
end
|
188
|
+
|
189
|
+
for image in Array.new(2) { |e| e = File.join(asset_path, "messy%d.jpg") % e } do
|
190
|
+
should_classify_images_as image, :messy
|
191
|
+
end
|
192
|
+
|
193
|
+
for image in Array.new(10) { |e| e = File.join(asset_path, "blank%d.jpg") % e } do
|
194
|
+
should_classify_images_as image, :blank
|
195
|
+
end
|
196
|
+
|
197
|
+
for image in Array.new(2) { |e| e = File.join(asset_path, "partially_blank%d.jpg") % e } do
|
198
|
+
should_classify_images_as image, :blank
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_pyr_segmentation
|
203
|
+
img0 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
204
|
+
img0.set_roi(CvRect.new(0, 0, 256, 512))
|
205
|
+
img1, seq1 = img0.pyr_segmentation(2, 255, 50)
|
206
|
+
assert_equal('963b26f51b14f175fbbf128e9b9e979f', hash_img(img1))
|
207
|
+
assert_equal(11, seq1.total)
|
208
|
+
|
209
|
+
assert_raise(CvStsAssert) {
|
210
|
+
img0.pyr_segmentation(-1, 255, 50)
|
211
|
+
}
|
212
|
+
assert_raise(CvStsAssert) {
|
213
|
+
img0.pyr_segmentation(1000, 255, 50)
|
214
|
+
}
|
215
|
+
assert_raise(CvStsAssert) {
|
216
|
+
img0.pyr_segmentation(4, -1, 50)
|
217
|
+
}
|
218
|
+
assert_raise(CvStsAssert) {
|
219
|
+
img0.pyr_segmentation(4, 255, -1)
|
220
|
+
}
|
221
|
+
assert_raise(TypeError) {
|
222
|
+
img0.pyr_segmentation(DUMMY_OBJ, 255, 50)
|
223
|
+
}
|
224
|
+
assert_raise(TypeError) {
|
225
|
+
img0.pyr_segmentation(4, DUMMY_OBJ, 50)
|
226
|
+
}
|
227
|
+
assert_raise(TypeError) {
|
228
|
+
img0.pyr_segmentation(4, 255, DUMMY_OBJ)
|
229
|
+
}
|
230
|
+
assert_raise(CvBadDepth) {
|
231
|
+
IplImage.new(10, 10, :cv32f, 2).pyr_segmentation(4, 255, 50)
|
232
|
+
}
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
|
@@ -0,0 +1,17 @@
|
|
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
|
+
include GUI
|
9
|
+
|
10
|
+
# Tests for OpenCV::MouseEvent
|
11
|
+
class TestMouseEvent < OpenCVTestCase
|
12
|
+
def test_initialize
|
13
|
+
assert_not_nil(MouseEvent.new)
|
14
|
+
assert_equal(MouseEvent, MouseEvent.new.class)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
data/test/test_opencv.rb
ADDED
@@ -0,0 +1,324 @@
|
|
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
|
+
class TestOpenCV < OpenCVTestCase
|
10
|
+
def test_constants
|
11
|
+
# OpenCV version
|
12
|
+
assert_equal('2.4.3', CV_VERSION)
|
13
|
+
assert_equal(2, CV_MAJOR_VERSION)
|
14
|
+
assert_equal(4, CV_MINOR_VERSION)
|
15
|
+
assert_equal(3, CV_SUBMINOR_VERSION)
|
16
|
+
|
17
|
+
# Depths
|
18
|
+
assert_equal(0, CV_8U)
|
19
|
+
assert_equal(1, CV_8S)
|
20
|
+
assert_equal(2, CV_16U)
|
21
|
+
assert_equal(3, CV_16S)
|
22
|
+
assert_equal(4, CV_32S)
|
23
|
+
assert_equal(5, CV_32F)
|
24
|
+
assert_equal(6, CV_64F)
|
25
|
+
|
26
|
+
# Load image flags
|
27
|
+
assert_equal(-1, CV_LOAD_IMAGE_UNCHANGED)
|
28
|
+
assert_equal(0, CV_LOAD_IMAGE_GRAYSCALE)
|
29
|
+
assert_equal(1, CV_LOAD_IMAGE_COLOR)
|
30
|
+
assert_equal(2, CV_LOAD_IMAGE_ANYDEPTH)
|
31
|
+
assert_equal(4, CV_LOAD_IMAGE_ANYCOLOR)
|
32
|
+
|
33
|
+
# Structuring element shapes
|
34
|
+
assert_equal(0, CV_SHAPE_RECT)
|
35
|
+
assert_equal(1, CV_SHAPE_CROSS)
|
36
|
+
assert_equal(2, CV_SHAPE_ELLIPSE)
|
37
|
+
assert_equal(100, CV_SHAPE_CUSTOM)
|
38
|
+
|
39
|
+
# Types of morphological operations
|
40
|
+
assert_equal(2, CV_MOP_OPEN)
|
41
|
+
assert_equal(3, CV_MOP_CLOSE)
|
42
|
+
assert_equal(4, CV_MOP_GRADIENT)
|
43
|
+
assert_equal(5, CV_MOP_TOPHAT)
|
44
|
+
assert_equal(6, CV_MOP_BLACKHAT)
|
45
|
+
|
46
|
+
# Types of the smoothing
|
47
|
+
assert_equal(0, CV_BLUR_NO_SCALE)
|
48
|
+
assert_equal(1, CV_BLUR)
|
49
|
+
assert_equal(2, CV_GAUSSIAN)
|
50
|
+
assert_equal(3, CV_MEDIAN)
|
51
|
+
assert_equal(4, CV_BILATERAL)
|
52
|
+
|
53
|
+
# Border types
|
54
|
+
assert_equal(0, IPL_BORDER_CONSTANT)
|
55
|
+
assert_equal(1, IPL_BORDER_REPLICATE)
|
56
|
+
|
57
|
+
# Thresholding types
|
58
|
+
assert_equal(0, CV_THRESH_BINARY)
|
59
|
+
assert_equal(1, CV_THRESH_BINARY_INV)
|
60
|
+
assert_equal(2, CV_THRESH_TRUNC)
|
61
|
+
assert_equal(3, CV_THRESH_TOZERO)
|
62
|
+
assert_equal(4, CV_THRESH_TOZERO_INV)
|
63
|
+
assert_equal(8, CV_THRESH_OTSU)
|
64
|
+
|
65
|
+
# Adaptive methods
|
66
|
+
assert_equal(0, CV_ADAPTIVE_THRESH_MEAN_C)
|
67
|
+
assert_equal(1, CV_ADAPTIVE_THRESH_GAUSSIAN_C)
|
68
|
+
|
69
|
+
# Retrieval mode
|
70
|
+
assert_equal(0, CV_RETR_EXTERNAL)
|
71
|
+
assert_equal(1, CV_RETR_LIST)
|
72
|
+
assert_equal(2, CV_RETR_CCOMP)
|
73
|
+
assert_equal(3, CV_RETR_TREE)
|
74
|
+
|
75
|
+
# Approximation method
|
76
|
+
assert_equal(0, CV_CHAIN_CODE)
|
77
|
+
assert_equal(1, CV_CHAIN_APPROX_NONE)
|
78
|
+
assert_equal(2, CV_CHAIN_APPROX_SIMPLE)
|
79
|
+
assert_equal(3, CV_CHAIN_APPROX_TC89_L1)
|
80
|
+
assert_equal(4, CV_CHAIN_APPROX_TC89_KCOS)
|
81
|
+
assert_equal(5, CV_LINK_RUNS)
|
82
|
+
|
83
|
+
# Termination criteria for iterative algorithms
|
84
|
+
assert_equal(1, CV_TERMCRIT_ITER)
|
85
|
+
assert_equal(1, CV_TERMCRIT_NUMBER)
|
86
|
+
assert_equal(2, CV_TERMCRIT_EPS)
|
87
|
+
|
88
|
+
# Hough transform methods
|
89
|
+
assert_equal(0, CV_HOUGH_STANDARD)
|
90
|
+
assert_equal(1, CV_HOUGH_PROBABILISTIC)
|
91
|
+
assert_equal(2, CV_HOUGH_MULTI_SCALE)
|
92
|
+
assert_equal(3, CV_HOUGH_GRADIENT)
|
93
|
+
|
94
|
+
# Inpaint method
|
95
|
+
assert_equal(0, CV_INPAINT_NS)
|
96
|
+
assert_equal(1, CV_INPAINT_TELEA)
|
97
|
+
|
98
|
+
# Match tempalte method
|
99
|
+
assert_equal(0, CV_TM_SQDIFF)
|
100
|
+
assert_equal(1, CV_TM_SQDIFF_NORMED)
|
101
|
+
assert_equal(2, CV_TM_CCORR)
|
102
|
+
assert_equal(3, CV_TM_CCORR_NORMED)
|
103
|
+
assert_equal(4, CV_TM_CCOEFF)
|
104
|
+
assert_equal(5, CV_TM_CCOEFF_NORMED)
|
105
|
+
|
106
|
+
# Comparison method
|
107
|
+
assert_equal(1, CV_CONTOURS_MATCH_I1)
|
108
|
+
assert_equal(2, CV_CONTOURS_MATCH_I2)
|
109
|
+
assert_equal(3, CV_CONTOURS_MATCH_I3)
|
110
|
+
|
111
|
+
# Fundamental matrix computing methods
|
112
|
+
assert_equal(1, CV_FM_7POINT)
|
113
|
+
assert_equal(2, CV_FM_8POINT)
|
114
|
+
assert_equal(8, CV_FM_RANSAC)
|
115
|
+
assert_equal(4, CV_FM_LMEDS)
|
116
|
+
|
117
|
+
# Flags of window
|
118
|
+
assert_equal(1, CV_WINDOW_AUTOSIZE)
|
119
|
+
|
120
|
+
# Object detection mode
|
121
|
+
assert_equal(1, CV_HAAR_DO_CANNY_PRUNING)
|
122
|
+
|
123
|
+
# Interpolation methods
|
124
|
+
assert_equal(0, CV_INTER_NN)
|
125
|
+
assert_equal(1, CV_INTER_LINEAR)
|
126
|
+
assert_equal(2, CV_INTER_CUBIC)
|
127
|
+
assert_equal(3, CV_INTER_AREA)
|
128
|
+
|
129
|
+
# Warp affine optional flags
|
130
|
+
assert_equal(8, CV_WARP_FILL_OUTLIERS)
|
131
|
+
assert_equal(16, CV_WARP_INVERSE_MAP)
|
132
|
+
|
133
|
+
# SVD operation flags
|
134
|
+
assert_equal(1, CV_SVD_MODIFY_A)
|
135
|
+
assert_equal(2, CV_SVD_U_T)
|
136
|
+
assert_equal(4, CV_SVD_V_T)
|
137
|
+
|
138
|
+
# Histogram representation format
|
139
|
+
assert_equal(0, CV_HIST_ARRAY)
|
140
|
+
assert_equal(1, CV_HIST_SPARSE)
|
141
|
+
assert_equal(1, CV_HIST_TREE)
|
142
|
+
assert_equal(1, CV_HIST_UNIFORM)
|
143
|
+
|
144
|
+
# Histogram comparison method
|
145
|
+
assert_equal(0, CV_COMP_CORREL)
|
146
|
+
assert_equal(1, CV_COMP_CHISQR)
|
147
|
+
assert_equal(2, CV_COMP_INTERSECT)
|
148
|
+
assert_equal(3, CV_COMP_BHATTACHARYYA)
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_symbols
|
152
|
+
# Depths
|
153
|
+
assert_equal(0, DEPTH[:cv8u])
|
154
|
+
assert_equal(1, DEPTH[:cv8s])
|
155
|
+
assert_equal(2, DEPTH[:cv16u])
|
156
|
+
assert_equal(3, DEPTH[:cv16s])
|
157
|
+
assert_equal(4, DEPTH[:cv32s])
|
158
|
+
assert_equal(5, DEPTH[:cv32f])
|
159
|
+
assert_equal(6, DEPTH[:cv64f])
|
160
|
+
|
161
|
+
# Inversion methods
|
162
|
+
assert_equal(0, INVERSION_METHOD[:lu])
|
163
|
+
assert_equal(1, INVERSION_METHOD[:svd])
|
164
|
+
assert_equal(2, INVERSION_METHOD[:svd_sym])
|
165
|
+
assert_equal(2, INVERSION_METHOD[:svd_symmetric])
|
166
|
+
|
167
|
+
# Homography calculation methods
|
168
|
+
assert_equal(0, HOMOGRAPHY_CALC_METHOD[:all])
|
169
|
+
assert_equal(4, HOMOGRAPHY_CALC_METHOD[:lmeds])
|
170
|
+
assert_equal(8, HOMOGRAPHY_CALC_METHOD[:ransac])
|
171
|
+
|
172
|
+
# Anti aliasing flags
|
173
|
+
assert_equal(16, CONNECTIVITY[:aa])
|
174
|
+
assert_equal(16, CONNECTIVITY[:anti_alias])
|
175
|
+
|
176
|
+
# Retrieval modes
|
177
|
+
assert_equal(0, RETRIEVAL_MODE[:external])
|
178
|
+
assert_equal(1, RETRIEVAL_MODE[:list])
|
179
|
+
assert_equal(2, RETRIEVAL_MODE[:ccomp])
|
180
|
+
assert_equal(3, RETRIEVAL_MODE[:tree])
|
181
|
+
|
182
|
+
# Approximation methods
|
183
|
+
assert_equal(0, APPROX_CHAIN_METHOD[:code])
|
184
|
+
assert_equal(1, APPROX_CHAIN_METHOD[:approx_none])
|
185
|
+
assert_equal(2, APPROX_CHAIN_METHOD[:approx_simple])
|
186
|
+
assert_equal(3, APPROX_CHAIN_METHOD[:approx_tc89_l1])
|
187
|
+
assert_equal(4, APPROX_CHAIN_METHOD[:approx_tc89_kcos])
|
188
|
+
|
189
|
+
# Approximation methods (polygon)
|
190
|
+
assert_equal(0, APPROX_POLY_METHOD[:dp])
|
191
|
+
|
192
|
+
# Match template methods
|
193
|
+
assert_equal(0, MATCH_TEMPLATE_METHOD[:sqdiff])
|
194
|
+
assert_equal(1, MATCH_TEMPLATE_METHOD[:sqdiff_normed])
|
195
|
+
assert_equal(2, MATCH_TEMPLATE_METHOD[:ccorr])
|
196
|
+
assert_equal(3, MATCH_TEMPLATE_METHOD[:ccorr_normed])
|
197
|
+
assert_equal(4, MATCH_TEMPLATE_METHOD[:ccoeff])
|
198
|
+
assert_equal(5, MATCH_TEMPLATE_METHOD[:ccoeff_normed])
|
199
|
+
|
200
|
+
# Structuring element shapes
|
201
|
+
assert_equal(0, STRUCTURING_ELEMENT_SHAPE[:rect])
|
202
|
+
assert_equal(1, STRUCTURING_ELEMENT_SHAPE[:cross])
|
203
|
+
assert_equal(2, STRUCTURING_ELEMENT_SHAPE[:ellipse])
|
204
|
+
assert_equal(100, STRUCTURING_ELEMENT_SHAPE[:custom])
|
205
|
+
|
206
|
+
# Types of morphological operations
|
207
|
+
assert_equal(2, MORPHOLOGICAL_OPERATION[:open])
|
208
|
+
assert_equal(3, MORPHOLOGICAL_OPERATION[:close])
|
209
|
+
assert_equal(4, MORPHOLOGICAL_OPERATION[:gradient])
|
210
|
+
assert_equal(5, MORPHOLOGICAL_OPERATION[:tophat])
|
211
|
+
assert_equal(6, MORPHOLOGICAL_OPERATION[:blackhat])
|
212
|
+
|
213
|
+
# Types of the smoothing
|
214
|
+
assert_equal(0, SMOOTHING_TYPE[:blur_no_scale])
|
215
|
+
assert_equal(1, SMOOTHING_TYPE[:blur])
|
216
|
+
assert_equal(2, SMOOTHING_TYPE[:gaussian])
|
217
|
+
assert_equal(3, SMOOTHING_TYPE[:median])
|
218
|
+
assert_equal(4, SMOOTHING_TYPE[:bilateral])
|
219
|
+
|
220
|
+
# Thresholding types
|
221
|
+
assert_equal(0, THRESHOLD_TYPE[:binary])
|
222
|
+
assert_equal(1, THRESHOLD_TYPE[:binary_inv])
|
223
|
+
assert_equal(2, THRESHOLD_TYPE[:trunc])
|
224
|
+
assert_equal(3, THRESHOLD_TYPE[:tozero])
|
225
|
+
assert_equal(4, THRESHOLD_TYPE[:tozero_inv])
|
226
|
+
assert_equal(8, THRESHOLD_TYPE[:otsu])
|
227
|
+
|
228
|
+
# Hough transform methods
|
229
|
+
assert_equal(0, HOUGH_TRANSFORM_METHOD[:standard])
|
230
|
+
assert_equal(1, HOUGH_TRANSFORM_METHOD[:probabilistic])
|
231
|
+
assert_equal(2, HOUGH_TRANSFORM_METHOD[:multi_scale])
|
232
|
+
assert_equal(3, HOUGH_TRANSFORM_METHOD[:gradient])
|
233
|
+
|
234
|
+
# Inpaint method
|
235
|
+
assert_equal(0, INPAINT_METHOD[:ns])
|
236
|
+
assert_equal(1, INPAINT_METHOD[:telea])
|
237
|
+
|
238
|
+
# Comparison method
|
239
|
+
assert_equal(1, COMPARISON_METHOD[:i1])
|
240
|
+
assert_equal(2, COMPARISON_METHOD[:i2])
|
241
|
+
assert_equal(3, COMPARISON_METHOD[:i3])
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_cvt_color_funcs
|
245
|
+
mat_1ch = CvMat.new(1, 1, :cv8u, 1)
|
246
|
+
mat_1ch[0] = CvScalar.new(10)
|
247
|
+
|
248
|
+
mat_3ch = CvMat.new(1, 1, :cv8u, 3)
|
249
|
+
mat_3ch[0] = CvScalar.new(10, 20, 30)
|
250
|
+
|
251
|
+
mat_4ch = CvMat.new(1, 1, :cv8u, 4)
|
252
|
+
mat_4ch[0] = CvScalar.new(10, 20, 30, 40)
|
253
|
+
|
254
|
+
gray_rgb = (0.299 * mat_3ch[0][0] + 0.587 * mat_3ch[0][1] + 0.114 * mat_3ch[0][2]).round
|
255
|
+
gray_bgr = (0.299 * mat_3ch[0][2] + 0.587 * mat_3ch[0][1] + 0.114 * mat_3ch[0][0]).round
|
256
|
+
|
257
|
+
# RGB(A) <=> RGB(A)
|
258
|
+
[mat_3ch.BGR2BGRA, mat_3ch.RGB2RGBA].each { |m|
|
259
|
+
assert_equal(CvMat, m.class)
|
260
|
+
assert_equal(4, m.channel)
|
261
|
+
assert_cvscalar_equal(CvScalar.new(10, 20, 30, 255), m[0])
|
262
|
+
}
|
263
|
+
[mat_3ch.BGR2RGBA, mat_3ch.RGB2BGRA].each { |m|
|
264
|
+
assert_equal(CvMat, m.class)
|
265
|
+
assert_equal(4, m.channel)
|
266
|
+
assert_cvscalar_equal(CvScalar.new(30, 20, 10, 255), m[0])
|
267
|
+
}
|
268
|
+
[mat_4ch.BGRA2BGR, mat_4ch.RGBA2RGB].each { |m|
|
269
|
+
assert_equal(CvMat, m.class)
|
270
|
+
assert_equal(3, m.channel)
|
271
|
+
assert_cvscalar_equal(CvScalar.new(10, 20, 30, 0), m[0])
|
272
|
+
}
|
273
|
+
[mat_4ch.RGBA2BGR, mat_4ch.BGRA2RGB].each { |m|
|
274
|
+
assert_equal(CvMat, m.class)
|
275
|
+
assert_equal(3, m.channel)
|
276
|
+
assert_cvscalar_equal(CvScalar.new(30, 20, 10, 0), m[0])
|
277
|
+
}
|
278
|
+
[mat_3ch.BGR2RGB, mat_3ch.RGB2BGR].each { |m|
|
279
|
+
assert_equal(CvMat, m.class)
|
280
|
+
assert_equal(3, m.channel)
|
281
|
+
assert_cvscalar_equal(CvScalar.new(30, 20, 10, 0), m[0])
|
282
|
+
}
|
283
|
+
[mat_4ch.BGRA2RGBA, mat_4ch.RGBA2BGRA].each { |m|
|
284
|
+
assert_equal(CvMat, m.class)
|
285
|
+
assert_equal(4, m.channel)
|
286
|
+
assert_cvscalar_equal(CvScalar.new(30, 20, 10, 40), m[0])
|
287
|
+
}
|
288
|
+
|
289
|
+
# RGB <=> GRAY
|
290
|
+
[mat_3ch.BGR2GRAY, mat_4ch.BGRA2GRAY].each { |m|
|
291
|
+
assert_equal(CvMat, m.class)
|
292
|
+
assert_equal(1, m.channel)
|
293
|
+
assert_cvscalar_equal(CvScalar.new(gray_bgr, 0, 0, 0), m[0])
|
294
|
+
}
|
295
|
+
[mat_3ch.RGB2GRAY, mat_4ch.RGBA2GRAY].each { |m|
|
296
|
+
assert_equal(CvMat, m.class)
|
297
|
+
assert_equal(1, m.channel)
|
298
|
+
assert_cvscalar_equal(CvScalar.new(gray_rgb, 0, 0, 0), m[0])
|
299
|
+
}
|
300
|
+
[mat_1ch.GRAY2BGR, mat_1ch.GRAY2RGB].each { |m|
|
301
|
+
assert_equal(CvMat, m.class)
|
302
|
+
assert_equal(3, m.channel)
|
303
|
+
assert_cvscalar_equal(CvScalar.new(10, 10, 10, 0), m[0])
|
304
|
+
}
|
305
|
+
[mat_1ch.GRAY2BGRA, mat_1ch.GRAY2RGBA].each { |m|
|
306
|
+
assert_equal(CvMat, m.class)
|
307
|
+
assert_equal(4, m.channel)
|
308
|
+
assert_cvscalar_equal(CvScalar.new(10, 10, 10, 255), m[0])
|
309
|
+
}
|
310
|
+
|
311
|
+
img_3ch = IplImage.new(1, 1, :cv8u, 3)
|
312
|
+
assert_equal(IplImage, img_3ch.BGR2GRAY.class)
|
313
|
+
|
314
|
+
flunk('FIXME: Most cvtColor functions are not tested yet.')
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_build_information
|
318
|
+
s = build_information
|
319
|
+
assert_equal(String, s.class)
|
320
|
+
assert(s =~ /^\s+General configuration for OpenCV #{CV_VERSION}/)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
|