1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

add EigenFaces#load

This commit is contained in:
ser1zw 2013-05-21 01:04:26 +09:00
parent e6f396ae0c
commit 12f9ea1751
4 changed files with 7557 additions and 0 deletions

View file

@ -142,6 +142,28 @@ rb_save(VALUE self, VALUE filename)
return Qnil;
}
/*
* call-seq:
* load(filename)
*
* Loads a FaceRecognizer and its model state.
*/
VALUE
rb_load(VALUE self, VALUE filename)
{
Check_Type(filename, T_STRING);
cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
try {
char* s = StringValueCStr(filename);
self_ptr->load(std::string(s));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return Qnil;
}
void
define_ruby_class()
{
@ -159,6 +181,7 @@ define_ruby_class()
rb_define_method(rb_klass, "train", RUBY_METHOD_FUNC(rb_train), 2);
rb_define_method(rb_klass, "predict", RUBY_METHOD_FUNC(rb_predict), 1);
rb_define_method(rb_klass, "save", RUBY_METHOD_FUNC(rb_save), 1);
rb_define_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load), 1);
}
__NAMESPACE_END_EIGENFACES

View file

@ -25,6 +25,7 @@ VALUE rb_allocate(VALUE klass);
VALUE rb_initialize(int argc, VALUE argv[], VALUE self);
VALUE rb_train(VALUE self, VALUE src, VALUE labels);
VALUE rb_save(VALUE self, VALUE filename);
VALUE rb_load(VALUE self, VALUE filename);
__NAMESPACE_END_EIGENFACES

7524
test/eigenfaces_save.xml Normal file

File diff suppressed because it is too large Load diff

View file

@ -63,5 +63,14 @@ class TestEigenFaces < OpenCVTestCase
File.delete filename
end
end
def test_load
assert_nothing_raised {
@eigenfaces.load('eigenfaces_save.xml')
}
assert_raise(TypeError) {
@eigenfaces.load(DUMMY_OBJ)
}
end
end