Merge branch 'develop' into fix/issues-33_opencv_gpulib_not_found
19
Manifest.txt
|
@ -8,8 +8,6 @@ README.md
|
|||
Rakefile
|
||||
config.yml
|
||||
examples/alpha_blend.rb
|
||||
examples/box.png
|
||||
examples/box_in_scene.png
|
||||
examples/contours/bitmap-contours-with-labels.png
|
||||
examples/contours/bitmap-contours.png
|
||||
examples/contours/bounding-box-detect-canny.rb
|
||||
|
@ -24,12 +22,19 @@ examples/facerec/facerec_lbph.rb
|
|||
examples/facerec/readme.md
|
||||
examples/find_obj.rb
|
||||
examples/houghcircle.rb
|
||||
examples/inpaint.png
|
||||
examples/images/box.png
|
||||
examples/images/box_in_scene.png
|
||||
examples/images/inpaint.png
|
||||
examples/images/lena-256x256.jpg
|
||||
examples/images/lena-eyes.jpg
|
||||
examples/images/lenna-rotated.jpg
|
||||
examples/images/lenna.jpg
|
||||
examples/images/stuff.jpg
|
||||
examples/images/tiffany.jpg
|
||||
examples/inpaint.rb
|
||||
examples/lenna-rotated.jpg
|
||||
examples/lenna.jpg
|
||||
examples/match_kdtree.rb
|
||||
examples/matching_to_many_images.rb
|
||||
examples/match_template.rb
|
||||
examples/matching_to_many_images/matching_to_many_images.rb
|
||||
examples/matching_to_many_images/query.png
|
||||
examples/matching_to_many_images/train/1.png
|
||||
examples/matching_to_many_images/train/2.png
|
||||
|
@ -37,8 +42,6 @@ examples/matching_to_many_images/train/3.png
|
|||
examples/matching_to_many_images/train/trainImages.txt
|
||||
examples/paint.rb
|
||||
examples/snake.rb
|
||||
examples/stuff.jpg
|
||||
examples/tiffany.jpg
|
||||
ext/opencv/algorithm.cpp
|
||||
ext/opencv/algorithm.h
|
||||
ext/opencv/curve.cpp
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
An OpenCV wrapper for Ruby.
|
||||
|
||||
* Web site: <https://github.com/ruby-opencv/ruby-opencv>
|
||||
* Ruby 1.9.3, 2.0.0 and OpenCV 2.4.6.1 are supported.
|
||||
* Ruby 1.9.3, 2.0.0 and OpenCV 2.4.7 are supported.
|
||||
|
||||
## Requirement
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
img1 = IplImage.load('lenna.jpg', CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||
img2 = IplImage.load('tiffany.jpg', CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||
img1 = IplImage.load('images/lenna.jpg', CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||
img2 = IplImage.load('images/tiffany.jpg', CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||
|
||||
window = GUI::Window.new('Alpha blend')
|
||||
max = 100.0
|
||||
|
|
|
@ -74,7 +74,7 @@ model = EigenFaces.new
|
|||
model.train(images, labels)
|
||||
|
||||
# The following line predicts the label of a given test image:
|
||||
predicted_label = model.predict(test_sample)
|
||||
predicted_label, predicted_confidence = model.predict(test_sample)
|
||||
|
||||
puts "Predicted class: #{predicted_label} / Actual class: #{test_label}"
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ model = FisherFaces.new
|
|||
model.train(images, labels)
|
||||
|
||||
# The following line predicts the label of a given test image:
|
||||
predicted_label = model.predict(test_sample)
|
||||
predicted_label, predicted_confidence = model.predict(test_sample)
|
||||
|
||||
puts "Predicted class: #{predicted_label} / Actual class: #{test_label}"
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ model = LBPH.new
|
|||
model.train(images, labels)
|
||||
|
||||
# The following line predicts the label of a given test image:
|
||||
predicted_label = model.predict(test_sample)
|
||||
predicted_label, predicted_confidence = model.predict(test_sample)
|
||||
|
||||
# To get the confidence of a prediction call the model with:
|
||||
#
|
||||
|
|
|
@ -100,8 +100,8 @@ puts 'Usage:'
|
|||
puts "ruby #{__FILE__} <object_filename> <scene_filename>, default is box.png and box_in_scene.png"
|
||||
puts
|
||||
|
||||
object_filename = (ARGV.size == 2) ? ARGV[0] : 'box.png'
|
||||
scene_filename = (ARGV.size == 2) ? ARGV[1] : 'box_in_scene.png'
|
||||
object_filename = (ARGV.size == 2) ? ARGV[0] : 'images/box.png'
|
||||
scene_filename = (ARGV.size == 2) ? ARGV[1] : 'images/box_in_scene.png'
|
||||
|
||||
object, image = nil, nil
|
||||
begin
|
||||
|
|
|
@ -7,7 +7,7 @@ include OpenCV
|
|||
original_window = GUI::Window.new "original"
|
||||
hough_window = GUI::Window.new "hough circles"
|
||||
|
||||
image = IplImage::load "stuff.jpg"
|
||||
image = IplImage::load "images/stuff.jpg"
|
||||
gray = image.BGR2GRAY
|
||||
|
||||
result = image.clone
|
||||
|
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
BIN
examples/images/lena-256x256.jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
examples/images/lena-eyes.jpg
Normal file
After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 90 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
|
@ -20,7 +20,7 @@ owindow = GUI::Window.new('original')
|
|||
mwindow = GUI::Window.new('mask')
|
||||
iwindow = GUI::Window.new('inpaint')
|
||||
|
||||
image = IplImage::load('inpaint.png')
|
||||
image = IplImage::load('images/inpaint.png')
|
||||
noimage = image.zero
|
||||
b, g, r = image.split
|
||||
original_mask = r.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV) & b.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV)
|
||||
|
|
|
@ -11,8 +11,8 @@ USE_EXTENDED_DESCRIPTOR = true
|
|||
THRESHOLD = 1500
|
||||
DESCRIPTOR_SIZE = USE_EXTENDED_DESCRIPTOR ? 128 : 64
|
||||
|
||||
img1 = CvMat.load('lenna.jpg', CV_LOAD_IMAGE_GRAYSCALE)
|
||||
img2 = CvMat.load('lenna-rotated.jpg', CV_LOAD_IMAGE_GRAYSCALE)
|
||||
img1 = CvMat.load('images/lenna.jpg', CV_LOAD_IMAGE_GRAYSCALE)
|
||||
img2 = CvMat.load('images/lenna-rotated.jpg', CV_LOAD_IMAGE_GRAYSCALE)
|
||||
|
||||
puts 'Extracting features from img1 using SURF...'
|
||||
param = CvSURFParams.new(THRESHOLD, USE_EXTENDED_DESCRIPTOR)
|
||||
|
|
26
examples/match_template.rb
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# A demo of Ruby/OpenCV's match_template function
|
||||
|
||||
require 'opencv'
|
||||
include OpenCV
|
||||
|
||||
puts 'This program demonstrates the match_template function'
|
||||
puts 'Usage:'
|
||||
puts "ruby #{__FILE__} <template_filename> <match_filename>"
|
||||
puts
|
||||
|
||||
template_filename = (ARGV.size == 2) ? ARGV[0] : File.expand_path(File.dirname(__FILE__) + '/images/lena-eyes.jpg')
|
||||
match_image_filename = (ARGV.size == 2) ? ARGV[1] : File.expand_path(File.dirname(__FILE__) + '/images/lena-256x256.jpg')
|
||||
|
||||
template = CvMat.load(template_filename)
|
||||
match_image = CvMat.load(match_image_filename)
|
||||
result = match_image.match_template(template, :sqdiff_normed)
|
||||
|
||||
pt1 = result.min_max_loc[2] # minimum location
|
||||
pt2 = CvPoint.new(pt1.x + template.width, pt1.y + template.height)
|
||||
match_image.rectangle!(pt1, pt2, :color => CvColor::Black, :thickness => 3)
|
||||
|
||||
window = GUI::Window.new('Display window') # Create a window for display.
|
||||
window.show(match_image) # Show our image inside it.
|
||||
GUI::wait_key # Wait for a keystroke in the window.
|
|
@ -2,11 +2,11 @@ require 'opencv'
|
|||
require 'benchmark'
|
||||
include OpenCV
|
||||
|
||||
data = File.join(File.dirname(__FILE__), 'matching_to_many_images')
|
||||
data = File.dirname(__FILE__)
|
||||
|
||||
query = IplImage.load File.join(data, 'query.png'), CV_LOAD_IMAGE_GRAYSCALE
|
||||
query = CvMat.load File.join(data, 'query.png'), CV_LOAD_IMAGE_GRAYSCALE
|
||||
image_files = ['1.png', '2.png', '3.png'].map{|f| File.join(data, 'train', f)}
|
||||
images = image_files.map{|f| IplImage.load f, CV_LOAD_IMAGE_GRAYSCALE}
|
||||
images = image_files.map{|f| CvMat.load f, CV_LOAD_IMAGE_GRAYSCALE}
|
||||
|
||||
|
||||
matchs = query.match_descriptors(images)
|
|
@ -352,6 +352,7 @@ void define_ruby_class()
|
|||
rb_define_method(rb_klass, "resize", RUBY_METHOD_FUNC(rb_resize), -1);
|
||||
rb_define_method(rb_klass, "warp_affine", RUBY_METHOD_FUNC(rb_warp_affine), -1);
|
||||
rb_define_singleton_method(rb_klass, "rotation_matrix2D", RUBY_METHOD_FUNC(rb_rotation_matrix2D), 3);
|
||||
rb_define_singleton_method(rb_klass, "get_perspective_transform", RUBY_METHOD_FUNC(rb_get_perspective_transform), 2);
|
||||
rb_define_method(rb_klass, "warp_perspective", RUBY_METHOD_FUNC(rb_warp_perspective), -1);
|
||||
rb_define_singleton_method(rb_klass, "find_homography", RUBY_METHOD_FUNC(rb_find_homograpy), -1);
|
||||
rb_define_method(rb_klass, "remap", RUBY_METHOD_FUNC(rb_remap), -1);
|
||||
|
@ -4053,6 +4054,40 @@ rb_rotation_matrix2D(VALUE self, VALUE center, VALUE angle, VALUE scale)
|
|||
return map_matrix;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* CvMat.get_perspective_transform(<i>from_points,to_points</i>) -> cvmat
|
||||
*
|
||||
* Calculates a perspective transform from four pairs of the corresponding points.
|
||||
* Returns a matrix suitable for use with warp_perspective
|
||||
*/
|
||||
VALUE
|
||||
rb_get_perspective_transform(VALUE self, VALUE source, VALUE dest)
|
||||
{
|
||||
Check_Type(source, T_ARRAY);
|
||||
Check_Type(dest, T_ARRAY);
|
||||
|
||||
int count = RARRAY_LEN(source);
|
||||
|
||||
CvPoint2D32f* source_buff = ALLOCA_N(CvPoint2D32f, count);
|
||||
CvPoint2D32f* dest_buff = ALLOCA_N(CvPoint2D32f, count);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
source_buff[i] = *(CVPOINT2D32F(RARRAY_PTR(source)[i]));
|
||||
dest_buff[i] = *(CVPOINT2D32F(RARRAY_PTR(dest)[i]));
|
||||
}
|
||||
|
||||
VALUE map_matrix = new_object(cvSize(3, 3), CV_MAKETYPE(CV_32F, 1));
|
||||
|
||||
try {
|
||||
cvGetPerspectiveTransform(source_buff, dest_buff, CVMAT(map_matrix));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
return map_matrix;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* warp_perspective(<i>map_matrix[,flags = CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS][,fillval=0])</i>) -> cvmat
|
||||
|
@ -5351,7 +5386,6 @@ rb_match_descriptors(int argc, VALUE *argv, VALUE self)
|
|||
{
|
||||
VALUE images, detector_type, descriptor_type, matcher_type;
|
||||
rb_scan_args(argc, argv, "13", &images, &detector_type, &descriptor_type, &matcher_type);
|
||||
|
||||
if (RARRAY_LEN(images) == 0) {
|
||||
return rb_hash_new();
|
||||
}
|
||||
|
@ -5365,45 +5399,44 @@ rb_match_descriptors(int argc, VALUE *argv, VALUE self)
|
|||
matcher_type = rb_str_new2("FlannBased");
|
||||
}
|
||||
|
||||
cv::Mat queryImage = CVMAT(self);
|
||||
VALUE _matches = rb_hash_new();
|
||||
try {
|
||||
cv::Mat queryImage(CVMAT(self));
|
||||
std::vector<cv::Mat> trainImages;
|
||||
for(int i=0; i < RARRAY_LEN(images); i++) {
|
||||
for(int i = 0, n = RARRAY_LEN(images); i < n; i++) {
|
||||
trainImages.push_back(CVMAT_WITH_CHECK(RARRAY_PTR(images)[i]));
|
||||
}
|
||||
|
||||
cv::Ptr<cv::FeatureDetector> featureDetector = cv::FeatureDetector::create(RSTRING_PTR(detector_type));
|
||||
cv::Ptr<cv::FeatureDetector> featureDetector = cv::FeatureDetector::create(StringValueCStr(detector_type));
|
||||
if (featureDetector.empty()) {
|
||||
rb_raise(rb_eArgError, "Could not create feature detector by given detector type: %s", RSTRING_PTR(detector_type));
|
||||
rb_raise(rb_eArgError, "Could not create feature detector by given detector type: %s", StringValueCStr(detector_type));
|
||||
}
|
||||
cv::Ptr<cv::DescriptorExtractor> descriptorExtractor = cv::DescriptorExtractor::create(RSTRING_PTR(descriptor_type));
|
||||
cv::Ptr<cv::DescriptorExtractor> descriptorExtractor = cv::DescriptorExtractor::create(StringValueCStr(descriptor_type));
|
||||
if (descriptorExtractor.empty()) {
|
||||
rb_raise(rb_eArgError, "Could not create descriptor extractor by given descriptor type: %s", RSTRING_PTR(descriptor_type));
|
||||
rb_raise(rb_eArgError, "Could not create descriptor extractor by given descriptor type: %s", StringValueCStr(descriptor_type));
|
||||
}
|
||||
cv::Ptr<cv::DescriptorMatcher> descriptorMatcher;
|
||||
try {
|
||||
descriptorMatcher = cv::DescriptorMatcher::create(RSTRING_PTR(matcher_type));
|
||||
descriptorMatcher = cv::DescriptorMatcher::create(StringValueCStr(matcher_type));
|
||||
}
|
||||
catch(cv::Exception& e) {
|
||||
rb_raise(rb_eArgError, "Could not create descriptor matcher by given matcher type: %s", RSTRING_PTR(matcher_type));
|
||||
rb_raise(rb_eArgError, "Could not create descriptor matcher by given matcher type: %s", StringValueCStr(matcher_type));
|
||||
}
|
||||
|
||||
std::vector<cv::KeyPoint> queryKeypoints;
|
||||
std::vector<std::vector<cv::KeyPoint> > trainKeypoints;
|
||||
featureDetector->detect(queryImage, queryKeypoints);
|
||||
featureDetector->detect(trainImages, trainKeypoints);
|
||||
|
||||
cv::Mat queryDescriptors;
|
||||
std::vector<cv::Mat> trainDescriptors;
|
||||
descriptorExtractor->compute(queryImage, queryKeypoints, queryDescriptors);
|
||||
descriptorExtractor->compute(trainImages, trainKeypoints, trainDescriptors);
|
||||
|
||||
std::vector<cv::DMatch> matches;
|
||||
descriptorMatcher->add(trainDescriptors);
|
||||
descriptorMatcher->train();
|
||||
descriptorMatcher->match(queryDescriptors, matches);
|
||||
|
||||
VALUE _matches = rb_hash_new();
|
||||
for (size_t i=0; i<matches.size(); i++) {
|
||||
for (size_t i = 0, n = matches.size(); i < n; i++) {
|
||||
VALUE match = INT2FIX(matches[i].imgIdx);
|
||||
VALUE count = rb_hash_lookup(_matches, match);
|
||||
if (NIL_P(count)) {
|
||||
|
@ -5413,6 +5446,11 @@ rb_match_descriptors(int argc, VALUE *argv, VALUE self)
|
|||
}
|
||||
rb_hash_aset(_matches, match, count);
|
||||
}
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return _matches;
|
||||
}
|
||||
|
||||
|
|
|
@ -175,6 +175,7 @@ VALUE rb_quadrangle_sub_pix(int argc, VALUE *argv, VALUE self);
|
|||
VALUE rb_resize(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_warp_affine(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_rotation_matrix2D(VALUE self, VALUE center, VALUE angle, VALUE scale);
|
||||
VALUE rb_get_perspective_transform(VALUE self, VALUE source, VALUE dest);
|
||||
VALUE rb_warp_perspective(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_find_homograpy(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_remap(int argc, VALUE *argv, VALUE self);
|
||||
|
|
|
@ -96,16 +96,18 @@ rb_predict(VALUE self, VALUE src)
|
|||
cv::Mat mat = cv::Mat(CVMAT_WITH_CHECK(src));
|
||||
cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
|
||||
int label;
|
||||
double confidence;
|
||||
try {
|
||||
label = self_ptr->predict(mat);
|
||||
self_ptr->predict(mat, label, confidence);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return INT2NUM(label);
|
||||
return rb_ary_new3(2, INT2NUM(label), DBL2NUM(confidence));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* save(filename)
|
||||
|
|
|
@ -22,6 +22,7 @@ VALUE rb_class();
|
|||
|
||||
void define_ruby_class();
|
||||
VALUE rb_train(VALUE self, VALUE src, VALUE labels);
|
||||
VALUE rb_predict(VALUE self, VALUE src);
|
||||
VALUE rb_save(VALUE self, VALUE filename);
|
||||
VALUE rb_load(VALUE self, VALUE filename);
|
||||
|
||||
|
|
|
@ -450,6 +450,40 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
# snap mat0, mat1, mat2, mat3, mat4
|
||||
end
|
||||
|
||||
def test_get_perspective_transform
|
||||
from = [
|
||||
OpenCV::CvPoint2D32f.new(540, 382),
|
||||
OpenCV::CvPoint2D32f.new(802, 400),
|
||||
OpenCV::CvPoint2D32f.new(850, 731),
|
||||
OpenCV::CvPoint2D32f.new(540, 731),
|
||||
]
|
||||
to = [
|
||||
OpenCV::CvPoint2D32f.new(0, 0),
|
||||
OpenCV::CvPoint2D32f.new(233, 0),
|
||||
OpenCV::CvPoint2D32f.new(233, 310),
|
||||
OpenCV::CvPoint2D32f.new(0, 310),
|
||||
]
|
||||
transform = OpenCV::CvMat.get_perspective_transform(from, to)
|
||||
assert_equal 3, transform.rows
|
||||
assert_equal 3, transform.columns
|
||||
expected = [
|
||||
0.923332154750824,
|
||||
0.0,
|
||||
0.0,
|
||||
1.4432899320127035e-15,
|
||||
0.0,
|
||||
0.0,
|
||||
-498.599365234375,
|
||||
0.0,
|
||||
0.0,
|
||||
]
|
||||
3.times do |i|
|
||||
3.times do |j|
|
||||
assert_in_delta(expected.shift, transform[i][j], 0.001)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_rotation_matrix2D
|
||||
mat1 = CvMat.rotation_matrix2D(CvPoint2D32f.new(10, 20), 60, 2.0)
|
||||
expected = [1.0, 1.73205, -34.64102,
|
||||
|
|
|
@ -18,7 +18,7 @@ class TestCvMat_matching < OpenCVTestCase
|
|||
end
|
||||
|
||||
def read_test_image(*path)
|
||||
IplImage.load File.join(data_dir, *path), CV_LOAD_IMAGE_GRAYSCALE
|
||||
CvMat.load File.join(data_dir, *path), CV_LOAD_IMAGE_GRAYSCALE
|
||||
end
|
||||
|
||||
def test_match_descriptors
|
||||
|
|
|
@ -13,8 +13,9 @@ class TestEigenFaces < OpenCVTestCase
|
|||
@eigenfaces = EigenFaces.new
|
||||
|
||||
@eigenfaces_trained = EigenFaces.new
|
||||
img = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
@eigenfaces_trained.train([img], [1])
|
||||
@images = [CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)] * 2
|
||||
@labels = [1, 2]
|
||||
@eigenfaces_trained.train(@images, @labels)
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
|
@ -32,51 +33,46 @@ class TestEigenFaces < OpenCVTestCase
|
|||
end
|
||||
|
||||
def test_train
|
||||
img = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
assert_nil(@eigenfaces.train([img], [1]))
|
||||
assert_nil(@eigenfaces.train(@images, @labels))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
@eigenfaces.train(DUMMY_OBJ, [1])
|
||||
@eigenfaces.train(DUMMY_OBJ, @labels)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
@eigenfaces.train([img], DUMMY_OBJ)
|
||||
@eigenfaces.train(@images, DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_predict
|
||||
img = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
label = 1
|
||||
@eigenfaces.train([img], [label])
|
||||
assert_equal(label, @eigenfaces.predict(img))
|
||||
predicted_label, predicted_confidence = @eigenfaces_trained.predict(@images[0])
|
||||
assert_equal(@labels[0], predicted_label)
|
||||
assert_in_delta(0.0, predicted_confidence, 0.01)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
@eigenfaces.predict(DUMMY_OBJ)
|
||||
@eigenfaces_trained.predict(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_save
|
||||
img = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)
|
||||
label = 1
|
||||
@eigenfaces.train([img], [label])
|
||||
filename = "eigenfaces_save-#{DateTime.now.strftime('%Y%m%d%H%M%S')}.xml"
|
||||
begin
|
||||
@eigenfaces.save(filename)
|
||||
@eigenfaces_trained.save(filename)
|
||||
assert(File.exist? filename)
|
||||
ensure
|
||||
File.delete filename
|
||||
end
|
||||
assert_raise(TypeError) {
|
||||
@eigenfaces.save(DUMMY_OBJ)
|
||||
@eigenfaces_trained.save(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_load
|
||||
assert_nothing_raised {
|
||||
@eigenfaces.load('eigenfaces_save.xml')
|
||||
@eigenfaces_trained.load('eigenfaces_save.xml')
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
@eigenfaces.load(DUMMY_OBJ)
|
||||
@eigenfaces_trained.load(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@ class TestFisherFaces < OpenCVTestCase
|
|||
|
||||
@fisherfaces_trained = FisherFaces.new
|
||||
@images = [CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)] * 2
|
||||
@fisherfaces_trained.train(@images, [1, 2])
|
||||
@labels = [1, 2]
|
||||
@fisherfaces_trained.train(@images, @labels)
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
|
@ -32,10 +33,10 @@ class TestFisherFaces < OpenCVTestCase
|
|||
end
|
||||
|
||||
def test_train
|
||||
assert_nil(@fisherfaces.train(@images, [1, 2]))
|
||||
assert_nil(@fisherfaces.train(@images, @labels))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
@fisherfaces.train(DUMMY_OBJ, [1])
|
||||
@fisherfaces.train(DUMMY_OBJ, @labels)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
|
@ -44,8 +45,9 @@ class TestFisherFaces < OpenCVTestCase
|
|||
end
|
||||
|
||||
def test_predict
|
||||
label = 1
|
||||
assert_equal(1, @fisherfaces_trained.predict(@images[0]))
|
||||
predicted_label, predicted_confidence = @fisherfaces_trained.predict(@images[0])
|
||||
assert_equal(@labels[0], predicted_label)
|
||||
assert_in_delta(0.0, predicted_confidence, 0.01)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
@fisherfaces_trained.predict(DUMMY_OBJ)
|
||||
|
|
|
@ -14,7 +14,8 @@ class TestLBPH < OpenCVTestCase
|
|||
|
||||
@lbph_trained = LBPH.new
|
||||
@images = [CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_GRAYSCALE)] * 2
|
||||
@lbph_trained.train(@images, [1, 1])
|
||||
@labels = [1, 2]
|
||||
@lbph_trained.train(@images, @labels)
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
|
@ -40,10 +41,10 @@ class TestLBPH < OpenCVTestCase
|
|||
end
|
||||
|
||||
def test_train
|
||||
assert_nil(@lbph.train(@images, [1, 1]))
|
||||
assert_nil(@lbph.train(@images, @labels))
|
||||
|
||||
assert_raise(TypeError) {
|
||||
@lbph.train(DUMMY_OBJ, [1, 1])
|
||||
@lbph.train(DUMMY_OBJ, @labels)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
|
@ -52,7 +53,9 @@ class TestLBPH < OpenCVTestCase
|
|||
end
|
||||
|
||||
def test_predict
|
||||
assert_equal(1, @lbph_trained.predict(@images[0]))
|
||||
predicted_label, predicted_confidence = @lbph_trained.predict(@images[0])
|
||||
assert_equal(@labels[0], predicted_label)
|
||||
assert_in_delta(0.0, predicted_confidence, 0.01)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
@lbph_trained.predict(DUMMY_OBJ)
|
||||
|
|
|
@ -9,15 +9,15 @@ include OpenCV
|
|||
class TestOpenCV < OpenCVTestCase
|
||||
def test_constants
|
||||
# OpenCV version
|
||||
assert_equal('2.4.6.1', CV_VERSION)
|
||||
assert_equal('2.4.7', CV_VERSION)
|
||||
assert_equal(2, CV_MAJOR_VERSION)
|
||||
assert_equal(4, CV_MINOR_VERSION)
|
||||
assert_equal(6, CV_SUBMINOR_VERSION)
|
||||
assert_equal(7, CV_SUBMINOR_VERSION)
|
||||
|
||||
assert_equal(2, CV_VERSION_EPOCH)
|
||||
assert_equal(4, CV_VERSION_MAJOR)
|
||||
assert_equal(6, CV_VERSION_MINOR)
|
||||
assert_equal(1, CV_VERSION_REVISION)
|
||||
assert_equal(7, CV_VERSION_MINOR)
|
||||
assert_equal(0, CV_VERSION_REVISION)
|
||||
|
||||
# Depths
|
||||
assert_equal(0, CV_8U)
|
||||
|
|