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,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8-unix -*-
|
3
|
+
require 'test/unit'
|
4
|
+
require 'opencv'
|
5
|
+
require 'date'
|
6
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
7
|
+
|
8
|
+
include OpenCV
|
9
|
+
|
10
|
+
# Tests for OpenCV::FisherFaces
|
11
|
+
class TestFisherFaces < OpenCVTestCase
|
12
|
+
def setup
|
13
|
+
@fisherfaces = FisherFaces.new
|
14
|
+
|
15
|
+
@fisherfaces_trained = FisherFaces.new
|
16
|
+
@images = [CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)] * 2
|
17
|
+
@labels = [1, 2]
|
18
|
+
@fisherfaces_trained.train(@images, @labels)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_initialize
|
22
|
+
[FisherFaces.new, FisherFaces.new(1), FisherFaces.new(1, 99999)].each { |ff|
|
23
|
+
assert_equal(FisherFaces, ff.class)
|
24
|
+
}
|
25
|
+
|
26
|
+
assert_raise(TypeError) {
|
27
|
+
FisherFaces.new(DUMMY_OBJ)
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_raise(TypeError) {
|
31
|
+
FisherFaces.new(1, DUMMY_OBJ)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_train
|
36
|
+
assert_nil(@fisherfaces.train(@images, @labels))
|
37
|
+
|
38
|
+
assert_raise(TypeError) {
|
39
|
+
@fisherfaces.train(DUMMY_OBJ, @labels)
|
40
|
+
}
|
41
|
+
|
42
|
+
assert_raise(TypeError) {
|
43
|
+
@fisherfaces.train(@images, DUMMY_OBJ)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_predict
|
48
|
+
predicted_label, predicted_confidence = @fisherfaces_trained.predict(@images[0])
|
49
|
+
assert_equal(@labels[0], predicted_label)
|
50
|
+
assert_in_delta(0.0, predicted_confidence, 0.01)
|
51
|
+
|
52
|
+
assert_raise(TypeError) {
|
53
|
+
@fisherfaces_trained.predict(DUMMY_OBJ)
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_save
|
58
|
+
filename = "fisherfaces_save-#{DateTime.now.strftime('%Y%m%d%H%M%S')}.xml"
|
59
|
+
begin
|
60
|
+
@fisherfaces_trained.save(filename)
|
61
|
+
assert(File.exist? filename)
|
62
|
+
ensure
|
63
|
+
File.delete filename
|
64
|
+
end
|
65
|
+
assert_raise(TypeError) {
|
66
|
+
@fisherfaces_trained.save(DUMMY_OBJ)
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_load
|
71
|
+
assert_nothing_raised {
|
72
|
+
@fisherfaces.load('fisherfaces_save.xml')
|
73
|
+
}
|
74
|
+
assert_raise(TypeError) {
|
75
|
+
@fisherfaces.load(DUMMY_OBJ)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_name
|
80
|
+
assert_equal('FaceRecognizer.Fisherfaces', @fisherfaces.name)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_get_mat
|
84
|
+
mat = @fisherfaces_trained.get_mat('eigenvalues')
|
85
|
+
assert_not_nil(mat)
|
86
|
+
assert_equal(CvMat, mat.class)
|
87
|
+
|
88
|
+
assert_raise(TypeError) {
|
89
|
+
@fisherfaces_trained.get_mat(DUMMY_OBJ)
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
@@ -0,0 +1,54 @@
|
|
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::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,232 @@
|
|
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::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
|
+
|
84
|
+
[img1, img2, img3, img4, img5, img6].each { |img|
|
85
|
+
assert_equal(IplImage, img.class)
|
86
|
+
assert_equal(expected.rows, img.rows)
|
87
|
+
assert_equal(expected.cols, img.cols)
|
88
|
+
assert_equal(expected.channel, img.channel)
|
89
|
+
}
|
90
|
+
|
91
|
+
expected_c1 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_GRAYSCALE)
|
92
|
+
img1c1 = IplImage.decode(data, CV_LOAD_IMAGE_GRAYSCALE)
|
93
|
+
img2c1 = IplImage.decode(data_ary, CV_LOAD_IMAGE_GRAYSCALE)
|
94
|
+
img3c1 = IplImage.decode(data_mat, CV_LOAD_IMAGE_GRAYSCALE)
|
95
|
+
|
96
|
+
[img1c1, img2c1, img3c1].each { |img|
|
97
|
+
assert_equal(IplImage, img.class)
|
98
|
+
assert_equal(expected_c1.rows, img.rows)
|
99
|
+
assert_equal(expected_c1.cols, img.cols)
|
100
|
+
assert_equal(expected_c1.channel, img.channel)
|
101
|
+
}
|
102
|
+
|
103
|
+
assert_raise(TypeError) {
|
104
|
+
IplImage.decode(DUMMY_OBJ)
|
105
|
+
}
|
106
|
+
assert_raise(TypeError) {
|
107
|
+
IplImage.decode(data, DUMMY_OBJ)
|
108
|
+
}
|
109
|
+
|
110
|
+
# Uncomment the following line to show the result images
|
111
|
+
# snap img1, img2, img3
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_roi
|
115
|
+
img = IplImage.new(20, 30)
|
116
|
+
rect = img.roi
|
117
|
+
assert_equal(0, rect.x)
|
118
|
+
assert_equal(0, rect.y)
|
119
|
+
assert_equal(img.width, rect.width)
|
120
|
+
assert_equal(img.height, rect.height)
|
121
|
+
|
122
|
+
img.set_roi(CvRect.new(2, 3, 10, 20))
|
123
|
+
rect = img.roi
|
124
|
+
assert_equal(2, rect.x)
|
125
|
+
assert_equal(3, rect.y)
|
126
|
+
assert_equal(10, rect.width)
|
127
|
+
assert_equal(20, rect.height)
|
128
|
+
|
129
|
+
img.reset_roi
|
130
|
+
rect = img.roi
|
131
|
+
assert_equal(0, rect.x)
|
132
|
+
assert_equal(0, rect.y)
|
133
|
+
assert_equal(img.width, rect.width)
|
134
|
+
assert_equal(img.height, rect.height)
|
135
|
+
|
136
|
+
img.set_roi(CvRect.new(1, 2, 5, 6)) {|image|
|
137
|
+
rect = image.roi
|
138
|
+
assert_equal(1, rect.x)
|
139
|
+
assert_equal(2, rect.y)
|
140
|
+
assert_equal(5, rect.width)
|
141
|
+
assert_equal(6, rect.height)
|
142
|
+
}
|
143
|
+
rect = img.roi
|
144
|
+
assert_equal(0, rect.x)
|
145
|
+
assert_equal(0, rect.y)
|
146
|
+
assert_equal(img.width, rect.width)
|
147
|
+
assert_equal(img.height, rect.height)
|
148
|
+
|
149
|
+
# Alias
|
150
|
+
img.roi = CvRect.new(4, 5, 11, 12)
|
151
|
+
rect = img.roi
|
152
|
+
assert_equal(4, rect.x)
|
153
|
+
assert_equal(5, rect.y)
|
154
|
+
assert_equal(11, rect.width)
|
155
|
+
assert_equal(12, rect.height)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_coi
|
159
|
+
img = IplImage.new(20, 30)
|
160
|
+
assert_equal(0, img.coi)
|
161
|
+
|
162
|
+
img.set_coi(1)
|
163
|
+
assert_equal(1, img.coi)
|
164
|
+
|
165
|
+
img.reset_coi
|
166
|
+
assert_equal(0, img.coi)
|
167
|
+
|
168
|
+
img.set_coi(2) {|image|
|
169
|
+
assert_equal(2, image.coi)
|
170
|
+
}
|
171
|
+
assert_equal(0, img.coi)
|
172
|
+
|
173
|
+
# Alias
|
174
|
+
img.coi = 1
|
175
|
+
assert_equal(1, img.coi)
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_smoothness
|
179
|
+
asset_path = File.join(File.dirname(__FILE__), 'samples')
|
180
|
+
|
181
|
+
for image in Array.new(7) { |e| e = File.join(asset_path, "smooth%d.jpg") % e } do
|
182
|
+
should_classify_images_as image, :smooth
|
183
|
+
end
|
184
|
+
|
185
|
+
for image in Array.new(2) { |e| e = File.join(asset_path, "messy%d.jpg") % e } do
|
186
|
+
should_classify_images_as image, :messy
|
187
|
+
end
|
188
|
+
|
189
|
+
for image in Array.new(10) { |e| e = File.join(asset_path, "blank%d.jpg") % e } do
|
190
|
+
should_classify_images_as image, :blank
|
191
|
+
end
|
192
|
+
|
193
|
+
for image in Array.new(2) { |e| e = File.join(asset_path, "partially_blank%d.jpg") % e } do
|
194
|
+
should_classify_images_as image, :blank
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_pyr_segmentation
|
199
|
+
img0 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
200
|
+
img0.set_roi(CvRect.new(0, 0, 256, 512))
|
201
|
+
img1, seq1 = img0.pyr_segmentation(2, 255, 50)
|
202
|
+
assert_equal('963b26f51b14f175fbbf128e9b9e979f', hash_img(img1))
|
203
|
+
assert_equal(11, seq1.total)
|
204
|
+
|
205
|
+
assert_raise(CvStsAssert) {
|
206
|
+
img0.pyr_segmentation(-1, 255, 50)
|
207
|
+
}
|
208
|
+
assert_raise(CvStsAssert) {
|
209
|
+
img0.pyr_segmentation(1000, 255, 50)
|
210
|
+
}
|
211
|
+
assert_raise(CvStsAssert) {
|
212
|
+
img0.pyr_segmentation(4, -1, 50)
|
213
|
+
}
|
214
|
+
assert_raise(CvStsAssert) {
|
215
|
+
img0.pyr_segmentation(4, 255, -1)
|
216
|
+
}
|
217
|
+
assert_raise(TypeError) {
|
218
|
+
img0.pyr_segmentation(DUMMY_OBJ, 255, 50)
|
219
|
+
}
|
220
|
+
assert_raise(TypeError) {
|
221
|
+
img0.pyr_segmentation(4, DUMMY_OBJ, 50)
|
222
|
+
}
|
223
|
+
assert_raise(TypeError) {
|
224
|
+
img0.pyr_segmentation(4, 255, DUMMY_OBJ)
|
225
|
+
}
|
226
|
+
assert_raise(CvBadDepth) {
|
227
|
+
IplImage.new(10, 10, :cv32f, 2).pyr_segmentation(4, 255, 50)
|
228
|
+
}
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
|
data/test/test_lbph.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8-unix -*-
|
3
|
+
require 'test/unit'
|
4
|
+
require 'opencv'
|
5
|
+
require 'date'
|
6
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
7
|
+
|
8
|
+
include OpenCV
|
9
|
+
|
10
|
+
# Tests for OpenCV::LBPH
|
11
|
+
class TestLBPH < OpenCVTestCase
|
12
|
+
def setup
|
13
|
+
@lbph = LBPH.new
|
14
|
+
|
15
|
+
@lbph_trained = LBPH.new
|
16
|
+
@images = [CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)] * 2
|
17
|
+
@labels = [1, 2]
|
18
|
+
@lbph_trained.train(@images, @labels)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_initialize
|
22
|
+
[LBPH.new, LBPH.new(1), LBPH.new(1, 2, 3, 4, 5.0)].each { |lbph|
|
23
|
+
assert_equal(LBPH, lbph.class)
|
24
|
+
}
|
25
|
+
|
26
|
+
assert_raise(TypeError) {
|
27
|
+
LBPH.new(DUMMY_OBJ)
|
28
|
+
}
|
29
|
+
assert_raise(TypeError) {
|
30
|
+
LBPH.new(1, DUMMY_OBJ)
|
31
|
+
}
|
32
|
+
assert_raise(TypeError) {
|
33
|
+
LBPH.new(1, 2, DUMMY_OBJ)
|
34
|
+
}
|
35
|
+
assert_raise(TypeError) {
|
36
|
+
LBPH.new(1, 2, 3, DUMMY_OBJ)
|
37
|
+
}
|
38
|
+
assert_raise(TypeError) {
|
39
|
+
LBPH.new(1, 2, 3, 4, DUMMY_OBJ)
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_train
|
44
|
+
assert_nil(@lbph.train(@images, @labels))
|
45
|
+
|
46
|
+
assert_raise(TypeError) {
|
47
|
+
@lbph.train(DUMMY_OBJ, @labels)
|
48
|
+
}
|
49
|
+
|
50
|
+
assert_raise(TypeError) {
|
51
|
+
@lbph.train(@images, DUMMY_OBJ)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_predict
|
56
|
+
predicted_label, predicted_confidence = @lbph_trained.predict(@images[0])
|
57
|
+
assert_equal(@labels[0], predicted_label)
|
58
|
+
assert_in_delta(0.0, predicted_confidence, 0.01)
|
59
|
+
|
60
|
+
assert_raise(TypeError) {
|
61
|
+
@lbph_trained.predict(DUMMY_OBJ)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_save
|
66
|
+
filename = "lbph_save-#{DateTime.now.strftime('%Y%m%d%H%M%S')}.xml"
|
67
|
+
begin
|
68
|
+
@lbph_trained.save(filename)
|
69
|
+
assert(File.exist? filename)
|
70
|
+
ensure
|
71
|
+
File.delete filename
|
72
|
+
end
|
73
|
+
assert_raise(TypeError) {
|
74
|
+
@lbph_trained.save(DUMMY_OBJ)
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_load
|
79
|
+
assert_nothing_raised {
|
80
|
+
@lbph.load('lbph_save.xml')
|
81
|
+
}
|
82
|
+
assert_raise(TypeError) {
|
83
|
+
@lbph.load(DUMMY_OBJ)
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_name
|
88
|
+
assert_equal('FaceRecognizer.LBPH', @lbph.name)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_get_int
|
92
|
+
assert_equal(1, @lbph.get_int('radius'))
|
93
|
+
assert_equal(8, @lbph.get_int('neighbors'))
|
94
|
+
assert_equal(8, @lbph.get_int('grid_x'))
|
95
|
+
assert_equal(8, @lbph.get_int('grid_y'))
|
96
|
+
|
97
|
+
assert_raise(TypeError) {
|
98
|
+
@lbph.get_int(DUMMY_OBJ)
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_get_double
|
103
|
+
assert_equal(Float::MAX, @lbph.get_double('threshold'))
|
104
|
+
|
105
|
+
assert_raise(TypeError) {
|
106
|
+
@lbph.get_double(DUMMY_OBJ)
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_get_matvector
|
111
|
+
histgrams = @lbph_trained.get_matvector('histograms')
|
112
|
+
assert_equal(Array, histgrams.class)
|
113
|
+
assert_equal(2, histgrams.size)
|
114
|
+
assert_equal(CvMat, histgrams[0].class)
|
115
|
+
|
116
|
+
assert_raise(TypeError) {
|
117
|
+
@lbph.get_matvector(DUMMY_OBJ)
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_set_int
|
122
|
+
@lbph.set_int('radius', 2)
|
123
|
+
@lbph.set_int('neighbors', 3)
|
124
|
+
@lbph.set_int('grid_x', 4)
|
125
|
+
@lbph.set_int('grid_y', 5)
|
126
|
+
|
127
|
+
assert_equal(2, @lbph.get_int('radius'))
|
128
|
+
assert_equal(3, @lbph.get_int('neighbors'))
|
129
|
+
assert_equal(4, @lbph.get_int('grid_x'))
|
130
|
+
assert_equal(5, @lbph.get_int('grid_y'))
|
131
|
+
|
132
|
+
assert_raise(TypeError) {
|
133
|
+
@lbph.set_int(DUMMY_OBJ, 1)
|
134
|
+
}
|
135
|
+
assert_raise(TypeError) {
|
136
|
+
@lbph.set_int('radius', DUMMY_OBJ)
|
137
|
+
}
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_set_double
|
141
|
+
@lbph.set_double('threshold', 1.0)
|
142
|
+
assert_in_delta(1.0, @lbph.get_double('threshold'), 0.001)
|
143
|
+
|
144
|
+
assert_raise(TypeError) {
|
145
|
+
@lbph.set_double(DUMMY_OBJ, 1.0)
|
146
|
+
}
|
147
|
+
assert_raise(TypeError) {
|
148
|
+
@lbph.set_double('threshold', DUMMY_OBJ)
|
149
|
+
}
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|