ruby-opencv 0.0.10 → 0.0.11.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/Manifest.txt +32 -8
- data/README.md +1 -1
- data/examples/alpha_blend.rb +2 -2
- data/examples/contours/bounding-box-detect-canny.rb +0 -0
- data/examples/contours/contour_retrieval_modes.rb +0 -0
- data/examples/convexhull.rb +0 -0
- data/examples/face_detect.rb +0 -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 +2 -2
- data/examples/houghcircle.rb +1 -1
- data/examples/{box.png → images/box.png} +0 -0
- data/examples/{box_in_scene.png → images/box_in_scene.png} +0 -0
- data/examples/{inpaint.png → images/inpaint.png} +0 -0
- data/examples/images/lena-256x256.jpg +0 -0
- data/examples/images/lena-eyes.jpg +0 -0
- data/examples/{lenna-rotated.jpg → images/lenna-rotated.jpg} +0 -0
- data/examples/{lenna.jpg → images/lenna.jpg} +0 -0
- data/examples/{stuff.jpg → images/stuff.jpg} +0 -0
- data/examples/{tiffany.jpg → images/tiffany.jpg} +0 -0
- data/examples/inpaint.rb +1 -1
- data/examples/match_kdtree.rb +2 -2
- data/examples/match_template.rb +26 -0
- data/examples/{matching_to_many_images.rb → matching_to_many_images/matching_to_many_images.rb} +3 -3
- 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 +0 -0
- data/examples/paint.rb +0 -0
- data/examples/snake.rb +0 -0
- data/ext/opencv/algorithm.cpp +286 -0
- data/ext/opencv/algorithm.h +38 -0
- data/ext/opencv/cvmat.cpp +205 -76
- data/ext/opencv/cvmat.h +8 -1
- data/ext/opencv/eigenfaces.cpp +67 -0
- data/ext/opencv/eigenfaces.h +30 -0
- data/ext/opencv/extconf.rb +0 -0
- data/ext/opencv/facerecognizer.cpp +174 -0
- data/ext/opencv/facerecognizer.h +46 -0
- data/ext/opencv/fisherfaces.cpp +67 -0
- data/ext/opencv/fisherfaces.h +30 -0
- data/ext/opencv/lbph.cpp +70 -0
- data/ext/opencv/lbph.h +30 -0
- data/ext/opencv/opencv.cpp +51 -1
- data/ext/opencv/opencv.h +6 -0
- data/lib/opencv.rb +0 -0
- data/lib/opencv/version.rb +1 -1
- data/ruby-opencv.gemspec +8 -7
- data/test/eigenfaces_save.xml +7524 -0
- data/test/fisherfaces_save.xml +7530 -0
- data/test/helper.rb +0 -0
- data/test/lbph_save.xml +4304 -0
- data/test/runner.rb +0 -0
- data/test/test_curve.rb +0 -0
- data/test/test_cvavgcomp.rb +0 -0
- data/test/test_cvbox2d.rb +0 -0
- data/test/test_cvcapture.rb +0 -0
- data/test/test_cvchain.rb +0 -0
- data/test/test_cvcircle32f.rb +0 -0
- data/test/test_cvconnectedcomp.rb +0 -0
- data/test/test_cvcontour.rb +0 -0
- data/test/test_cvcontourtree.rb +0 -0
- data/test/test_cverror.rb +0 -0
- data/test/test_cvfeaturetree.rb +0 -0
- data/test/test_cvfont.rb +0 -0
- data/test/test_cvhaarclassifiercascade.rb +0 -0
- data/test/test_cvhistogram.rb +0 -0
- data/test/test_cvhumoments.rb +0 -0
- data/test/test_cvline.rb +0 -0
- data/test/test_cvmat.rb +72 -16
- data/test/test_cvmat_drawing.rb +0 -0
- data/test/test_cvmat_dxt.rb +0 -0
- data/test/test_cvmat_imageprocessing.rb +72 -2
- data/test/test_cvmat_matching.rb +1 -1
- data/test/test_cvmoments.rb +0 -0
- data/test/test_cvpoint.rb +0 -0
- data/test/test_cvpoint2d32f.rb +0 -0
- data/test/test_cvpoint3d32f.rb +0 -0
- data/test/test_cvrect.rb +0 -0
- data/test/test_cvscalar.rb +0 -0
- data/test/test_cvseq.rb +0 -0
- data/test/test_cvsize.rb +0 -0
- data/test/test_cvsize2d32f.rb +0 -0
- data/test/test_cvslice.rb +0 -0
- data/test/test_cvsurfparams.rb +0 -0
- data/test/test_cvsurfpoint.rb +0 -0
- data/test/test_cvtermcriteria.rb +0 -0
- data/test/test_cvtwopoints.rb +0 -0
- data/test/test_cvvideowriter.rb +0 -0
- data/test/test_eigenfaces.rb +93 -0
- data/test/test_fisherfaces.rb +93 -0
- data/test/test_iplconvkernel.rb +0 -0
- data/test/test_iplimage.rb +0 -4
- data/test/test_lbph.rb +152 -0
- data/test/test_mouseevent.rb +0 -0
- data/test/test_opencv.rb +33 -4
- data/test/test_pointset.rb +7 -5
- data/test/test_preliminary.rb +0 -0
- data/test/test_trackbar.rb +0 -0
- data/test/test_window.rb +0 -0
- metadata +84 -56
data/test/runner.rb
CHANGED
File without changes
|
data/test/test_curve.rb
CHANGED
File without changes
|
data/test/test_cvavgcomp.rb
CHANGED
File without changes
|
data/test/test_cvbox2d.rb
CHANGED
File without changes
|
data/test/test_cvcapture.rb
CHANGED
File without changes
|
data/test/test_cvchain.rb
CHANGED
File without changes
|
data/test/test_cvcircle32f.rb
CHANGED
File without changes
|
File without changes
|
data/test/test_cvcontour.rb
CHANGED
File without changes
|
data/test/test_cvcontourtree.rb
CHANGED
File without changes
|
data/test/test_cverror.rb
CHANGED
File without changes
|
data/test/test_cvfeaturetree.rb
CHANGED
File without changes
|
data/test/test_cvfont.rb
CHANGED
File without changes
|
File without changes
|
data/test/test_cvhistogram.rb
CHANGED
File without changes
|
data/test/test_cvhumoments.rb
CHANGED
File without changes
|
data/test/test_cvline.rb
CHANGED
File without changes
|
data/test/test_cvmat.rb
CHANGED
@@ -888,7 +888,7 @@ class TestCvMat < OpenCVTestCase
|
|
888
888
|
def test_reshape
|
889
889
|
m = create_cvmat(2, 3, CV_8U, 3)
|
890
890
|
|
891
|
-
vec = m.reshape(
|
891
|
+
vec = m.reshape(0, 1)
|
892
892
|
assert_equal(6, vec.width)
|
893
893
|
assert_equal(1, vec.height)
|
894
894
|
size = m.width * m.height
|
@@ -896,7 +896,7 @@ class TestCvMat < OpenCVTestCase
|
|
896
896
|
assert_cvscalar_equal(m[i], vec[i])
|
897
897
|
}
|
898
898
|
|
899
|
-
ch1 = m.reshape(
|
899
|
+
ch1 = m.reshape(1)
|
900
900
|
assert_equal(9, ch1.width)
|
901
901
|
assert_equal(2, ch1.height)
|
902
902
|
|
@@ -909,10 +909,11 @@ class TestCvMat < OpenCVTestCase
|
|
909
909
|
}
|
910
910
|
}
|
911
911
|
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
912
|
+
assert_raise(TypeError) {
|
913
|
+
m.reshape(DUMMY_OBJ)
|
914
|
+
}
|
915
|
+
assert_raise(TypeError) {
|
916
|
+
m.reshape(0, DUMMY_OBJ)
|
916
917
|
}
|
917
918
|
end
|
918
919
|
|
@@ -2053,10 +2054,16 @@ class TestCvMat < OpenCVTestCase
|
|
2053
2054
|
assert_in_delta(x, mminmax[i][0], 0.001)
|
2054
2055
|
}
|
2055
2056
|
|
2057
|
+
minf = mat.normalize(1, 0, CV_NORM_INF, CV_32FC3)
|
2058
|
+
expected = [0.0, 0.333, 0.666, 1.0]
|
2059
|
+
expected.each_with_index { |x, i|
|
2060
|
+
assert_in_delta(x, minf[i][0], 0.001)
|
2061
|
+
}
|
2062
|
+
|
2056
2063
|
mask = mat.to_8u.zero
|
2057
2064
|
mask[0, 0] = CvScalar.new(255, 0, 0)
|
2058
2065
|
mask[1, 0] = CvScalar.new(255, 0, 0)
|
2059
|
-
minf = mat.normalize(1, 0, CV_NORM_INF, mask)
|
2066
|
+
minf = mat.normalize(1, 0, CV_NORM_INF, -1, mask)
|
2060
2067
|
expected = [0.0, 0.0, 1.0, 0.0]
|
2061
2068
|
expected.each_with_index { |x, i|
|
2062
2069
|
assert_in_delta(x, minf[i][0], 0.001)
|
@@ -2794,11 +2801,11 @@ class TestCvMat < OpenCVTestCase
|
|
2794
2801
|
CvMat.find_fundamental_mat(mat1, mat2, CV_FM_LMEDS)].each { |f_mat|
|
2795
2802
|
assert_equal(3, f_mat.rows)
|
2796
2803
|
assert_equal(3, f_mat.cols)
|
2797
|
-
expected = [
|
2798
|
-
0.
|
2799
|
-
|
2804
|
+
expected = [0.0, 0.0, 0.0,
|
2805
|
+
0.0, 0.0, 0.0,
|
2806
|
+
0.0, 0.0, 1.0]
|
2800
2807
|
expected.each_with_index { |val, i|
|
2801
|
-
assert_in_delta(val, f_mat[i][0], 1
|
2808
|
+
assert_in_delta(val, f_mat[i][0], 0.1)
|
2802
2809
|
}
|
2803
2810
|
}
|
2804
2811
|
|
@@ -2810,13 +2817,13 @@ class TestCvMat < OpenCVTestCase
|
|
2810
2817
|
assert_equal(1, status.rows)
|
2811
2818
|
assert_equal(num_points, status.cols)
|
2812
2819
|
|
2813
|
-
|
2814
|
-
|
2815
|
-
|
2820
|
+
expected_fmat = [0.0, 0.0, 0.0,
|
2821
|
+
0.0, 0.0, 0.0,
|
2822
|
+
0.0, 0.0, 1.0]
|
2816
2823
|
expected_f_mat.each_with_index { |val, i|
|
2817
|
-
assert_in_delta(val, f_mat[i][0], 1
|
2824
|
+
assert_in_delta(val, f_mat[i][0], 0.1)
|
2818
2825
|
}
|
2819
|
-
expected_status = [
|
2826
|
+
expected_status = [0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1]
|
2820
2827
|
expected_status.each_with_index { |val, i|
|
2821
2828
|
assert_equal(val, status[i][0].to_i)
|
2822
2829
|
}
|
@@ -2943,5 +2950,54 @@ class TestCvMat < OpenCVTestCase
|
|
2943
2950
|
CvMat.compute_correspond_epilines(mat1, 1, DUMMY_OBJ)
|
2944
2951
|
}
|
2945
2952
|
end
|
2953
|
+
|
2954
|
+
def test_apply_color_map
|
2955
|
+
mat = CvMat.new(64, 256, :cv8u, 1)
|
2956
|
+
mat.cols.times { |c|
|
2957
|
+
mat.rows.times { |r|
|
2958
|
+
mat[r, c] = c
|
2959
|
+
}
|
2960
|
+
}
|
2961
|
+
|
2962
|
+
results = []
|
2963
|
+
[COLORMAP_AUTUMN, COLORMAP_BONE, COLORMAP_JET, COLORMAP_WINTER,
|
2964
|
+
COLORMAP_RAINBOW, COLORMAP_OCEAN, COLORMAP_SUMMER, COLORMAP_SPRING,
|
2965
|
+
COLORMAP_COOL, COLORMAP_HSV, COLORMAP_PINK, COLORMAP_HOT].each { |colormap|
|
2966
|
+
cmap = mat.apply_color_map(colormap)
|
2967
|
+
assert_equal(CvMat, cmap.class)
|
2968
|
+
assert_equal(mat.rows, cmap.rows)
|
2969
|
+
assert_equal(mat.cols, cmap.cols)
|
2970
|
+
results << cmap
|
2971
|
+
}
|
2972
|
+
|
2973
|
+
assert_raise(TypeError) {
|
2974
|
+
mat.apply_color_map(DUMMY_OBJ)
|
2975
|
+
}
|
2976
|
+
|
2977
|
+
# Uncomment the following line to show the result
|
2978
|
+
# snap *results
|
2979
|
+
end
|
2980
|
+
|
2981
|
+
def test_subspace_project
|
2982
|
+
w = CvMat.new(10, 20, :cv32f, 1)
|
2983
|
+
mean = CvMat.new(w.rows, 1, :cv32f, 1)
|
2984
|
+
mat = CvMat.new(w.cols, w.rows, :cv32f, 1)
|
2985
|
+
result = mat.subspace_project(w, mean)
|
2986
|
+
|
2987
|
+
assert_equal(CvMat, result.class)
|
2988
|
+
assert_equal(w.cols, result.rows)
|
2989
|
+
assert_equal(w.cols, result.cols)
|
2990
|
+
end
|
2991
|
+
|
2992
|
+
def test_subspace_reconstruct
|
2993
|
+
w = CvMat.new(10, 20, :cv32f, 1)
|
2994
|
+
mean = CvMat.new(w.rows, 1, :cv32f, 1)
|
2995
|
+
mat = CvMat.new(w.cols, w.cols, :cv32f, 1)
|
2996
|
+
result = mat.subspace_reconstruct(w, mean)
|
2997
|
+
|
2998
|
+
assert_equal(CvMat, result.class)
|
2999
|
+
assert_equal(w.cols, result.rows)
|
3000
|
+
assert_equal(w.rows, result.cols)
|
3001
|
+
end
|
2946
3002
|
end
|
2947
3003
|
|
data/test/test_cvmat_drawing.rb
CHANGED
File without changes
|
data/test/test_cvmat_dxt.rb
CHANGED
File without changes
|
@@ -450,6 +450,40 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|
450
450
|
# snap mat0, mat1, mat2, mat3, mat4
|
451
451
|
end
|
452
452
|
|
453
|
+
def test_get_perspective_transform
|
454
|
+
from = [
|
455
|
+
OpenCV::CvPoint2D32f.new(540, 382),
|
456
|
+
OpenCV::CvPoint2D32f.new(802, 400),
|
457
|
+
OpenCV::CvPoint2D32f.new(850, 731),
|
458
|
+
OpenCV::CvPoint2D32f.new(540, 731),
|
459
|
+
]
|
460
|
+
to = [
|
461
|
+
OpenCV::CvPoint2D32f.new(0, 0),
|
462
|
+
OpenCV::CvPoint2D32f.new(233, 0),
|
463
|
+
OpenCV::CvPoint2D32f.new(233, 310),
|
464
|
+
OpenCV::CvPoint2D32f.new(0, 310),
|
465
|
+
]
|
466
|
+
transform = OpenCV::CvMat.get_perspective_transform(from, to)
|
467
|
+
assert_equal 3, transform.rows
|
468
|
+
assert_equal 3, transform.columns
|
469
|
+
expected = [
|
470
|
+
0.923332154750824,
|
471
|
+
0.0,
|
472
|
+
0.0,
|
473
|
+
1.4432899320127035e-15,
|
474
|
+
0.0,
|
475
|
+
0.0,
|
476
|
+
-498.599365234375,
|
477
|
+
0.0,
|
478
|
+
0.0,
|
479
|
+
]
|
480
|
+
3.times do |i|
|
481
|
+
3.times do |j|
|
482
|
+
assert_in_delta(expected.shift, transform[i][j], 0.001)
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
453
487
|
def test_rotation_matrix2D
|
454
488
|
mat1 = CvMat.rotation_matrix2D(CvPoint2D32f.new(10, 20), 60, 2.0)
|
455
489
|
expected = [1.0, 1.73205, -34.64102,
|
@@ -1009,10 +1043,18 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|
1009
1043
|
test_proc = lambda { |type, type_sym, expected_mat, expected_threshold|
|
1010
1044
|
mat1 = mat0.threshold(expected_threshold, 7, type)
|
1011
1045
|
mat2 = mat0.threshold(expected_threshold, 7, type_sym)
|
1046
|
+
[mat1, mat2].each { |m|
|
1047
|
+
expected_mat.each_with_index { |x, i|
|
1048
|
+
assert_equal(x, m[i][0])
|
1049
|
+
}
|
1050
|
+
}
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
test_proc_with_otsu = lambda { |type, type_sym, expected_mat, expected_threshold|
|
1012
1054
|
mat3, th3 = mat0.threshold(5, 7, type | CV_THRESH_OTSU)
|
1013
1055
|
mat4, th4 = mat0.threshold(3, 7, type_sym, true)
|
1014
1056
|
mat5, th5 = mat0.threshold(5, 7, type | CV_THRESH_OTSU, true)
|
1015
|
-
[
|
1057
|
+
[mat3, mat4, mat5].each { |m|
|
1016
1058
|
expected_mat.each_with_index { |x, i|
|
1017
1059
|
assert_equal(x, m[i][0])
|
1018
1060
|
}
|
@@ -1021,36 +1063,62 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|
1021
1063
|
assert_in_delta(expected_threshold, th, 0.001)
|
1022
1064
|
}
|
1023
1065
|
}
|
1066
|
+
|
1024
1067
|
# Binary
|
1025
1068
|
expected = [0, 0, 0,
|
1026
1069
|
0, 0, 7,
|
1027
1070
|
7, 7, 7]
|
1028
1071
|
test_proc.call(CV_THRESH_BINARY, :binary, expected, 4)
|
1029
1072
|
|
1073
|
+
expected = [0, 0, 0,
|
1074
|
+
0, 7, 7,
|
1075
|
+
7, 7, 7]
|
1076
|
+
test_proc_with_otsu.call(CV_THRESH_BINARY, :binary, expected, 3)
|
1077
|
+
|
1030
1078
|
# Binary inverse
|
1031
1079
|
expected = [7, 7, 7,
|
1032
1080
|
7, 7, 0,
|
1033
1081
|
0, 0, 0]
|
1034
1082
|
test_proc.call(CV_THRESH_BINARY_INV, :binary_inv, expected, 4)
|
1035
1083
|
|
1084
|
+
expected = [7, 7, 7,
|
1085
|
+
7, 0, 0,
|
1086
|
+
0, 0, 0]
|
1087
|
+
test_proc_with_otsu.call(CV_THRESH_BINARY_INV, :binary_inv, expected, 3)
|
1088
|
+
|
1036
1089
|
# Trunc
|
1037
1090
|
expected = [0, 1, 2,
|
1038
1091
|
3, 4, 4,
|
1039
1092
|
4, 4, 4]
|
1040
1093
|
test_proc.call(CV_THRESH_TRUNC, :trunc, expected, 4)
|
1041
1094
|
|
1095
|
+
expected = [0, 1, 2,
|
1096
|
+
3, 3, 3,
|
1097
|
+
3, 3, 3]
|
1098
|
+
test_proc_with_otsu.call(CV_THRESH_TRUNC, :trunc, expected, 3)
|
1099
|
+
|
1042
1100
|
# To zero
|
1043
1101
|
expected = [0, 0, 0,
|
1044
1102
|
0, 0, 5,
|
1045
1103
|
6, 7, 8]
|
1046
1104
|
test_proc.call(CV_THRESH_TOZERO, :tozero, expected, 4)
|
1047
1105
|
|
1106
|
+
expected = [0, 0, 0,
|
1107
|
+
0, 4, 5,
|
1108
|
+
6, 7, 8]
|
1109
|
+
test_proc_with_otsu.call(CV_THRESH_TOZERO, :tozero, expected, 3)
|
1110
|
+
|
1048
1111
|
# To zero inverse
|
1049
1112
|
expected = [0, 1, 2,
|
1050
1113
|
3, 4, 0,
|
1051
1114
|
0, 0, 0]
|
1052
1115
|
test_proc.call(CV_THRESH_TOZERO_INV, :tozero_inv, expected, 4)
|
1053
1116
|
|
1117
|
+
expected = [0, 1, 2,
|
1118
|
+
3, 0, 0,
|
1119
|
+
0, 0, 0]
|
1120
|
+
test_proc_with_otsu.call(CV_THRESH_TOZERO_INV, :tozero_inv, expected, 3)
|
1121
|
+
|
1054
1122
|
assert_raise(TypeError) {
|
1055
1123
|
mat0.threshold(DUMMY_OBJ, 2, :binary)
|
1056
1124
|
}
|
@@ -1603,7 +1671,9 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|
1603
1671
|
def test_equalize_hist
|
1604
1672
|
mat = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)
|
1605
1673
|
result = mat.equalize_hist
|
1606
|
-
assert_equal(
|
1674
|
+
assert_equal(CvMat, result.class)
|
1675
|
+
assert_equal(mat.rows, result.rows)
|
1676
|
+
assert_equal(mat.cols, result.cols)
|
1607
1677
|
|
1608
1678
|
assert_raise(CvStsAssert) {
|
1609
1679
|
CvMat.new(10, 10, :cv32f, 3).equalize_hist
|
data/test/test_cvmat_matching.rb
CHANGED
data/test/test_cvmoments.rb
CHANGED
File without changes
|
data/test/test_cvpoint.rb
CHANGED
File without changes
|
data/test/test_cvpoint2d32f.rb
CHANGED
File without changes
|
data/test/test_cvpoint3d32f.rb
CHANGED
File without changes
|
data/test/test_cvrect.rb
CHANGED
File without changes
|
data/test/test_cvscalar.rb
CHANGED
File without changes
|
data/test/test_cvseq.rb
CHANGED
File without changes
|
data/test/test_cvsize.rb
CHANGED
File without changes
|
data/test/test_cvsize2d32f.rb
CHANGED
File without changes
|
data/test/test_cvslice.rb
CHANGED
File without changes
|
data/test/test_cvsurfparams.rb
CHANGED
File without changes
|
data/test/test_cvsurfpoint.rb
CHANGED
File without changes
|
data/test/test_cvtermcriteria.rb
CHANGED
File without changes
|
data/test/test_cvtwopoints.rb
CHANGED
File without changes
|
data/test/test_cvvideowriter.rb
CHANGED
File without changes
|
@@ -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::EigenFaces
|
11
|
+
class TestEigenFaces < OpenCVTestCase
|
12
|
+
def setup
|
13
|
+
@eigenfaces = EigenFaces.new
|
14
|
+
|
15
|
+
@eigenfaces_trained = EigenFaces.new
|
16
|
+
@images = [CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)] * 2
|
17
|
+
@labels = [1, 2]
|
18
|
+
@eigenfaces_trained.train(@images, @labels)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_initialize
|
22
|
+
[EigenFaces.new, EigenFaces.new(1), EigenFaces.new(1, 99999)].each { |ef|
|
23
|
+
assert_equal(EigenFaces, ef.class)
|
24
|
+
}
|
25
|
+
|
26
|
+
assert_raise(TypeError) {
|
27
|
+
EigenFaces.new(DUMMY_OBJ)
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_raise(TypeError) {
|
31
|
+
EigenFaces.new(1, DUMMY_OBJ)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_train
|
36
|
+
assert_nil(@eigenfaces.train(@images, @labels))
|
37
|
+
|
38
|
+
assert_raise(TypeError) {
|
39
|
+
@eigenfaces.train(DUMMY_OBJ, @labels)
|
40
|
+
}
|
41
|
+
|
42
|
+
assert_raise(TypeError) {
|
43
|
+
@eigenfaces.train(@images, DUMMY_OBJ)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_predict
|
48
|
+
predicted_label, predicted_confidence = @eigenfaces_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
|
+
@eigenfaces_trained.predict(DUMMY_OBJ)
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_save
|
58
|
+
filename = "eigenfaces_save-#{DateTime.now.strftime('%Y%m%d%H%M%S')}.xml"
|
59
|
+
begin
|
60
|
+
@eigenfaces_trained.save(filename)
|
61
|
+
assert(File.exist? filename)
|
62
|
+
ensure
|
63
|
+
File.delete filename
|
64
|
+
end
|
65
|
+
assert_raise(TypeError) {
|
66
|
+
@eigenfaces_trained.save(DUMMY_OBJ)
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_load
|
71
|
+
assert_nothing_raised {
|
72
|
+
@eigenfaces_trained.load('eigenfaces_save.xml')
|
73
|
+
}
|
74
|
+
assert_raise(TypeError) {
|
75
|
+
@eigenfaces_trained.load(DUMMY_OBJ)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_name
|
80
|
+
assert_equal('FaceRecognizer.Eigenfaces', @eigenfaces.name)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_get_mat
|
84
|
+
mat = @eigenfaces_trained.get_mat('eigenvalues')
|
85
|
+
assert_not_nil(mat)
|
86
|
+
assert_equal(CvMat, mat.class)
|
87
|
+
|
88
|
+
assert_raise(TypeError) {
|
89
|
+
@eigenfaces_trained.get_mat(DUMMY_OBJ)
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|