mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add EigenFaces#save
This commit is contained in:
parent
8fc406e5fd
commit
e6f396ae0c
3 changed files with 38 additions and 0 deletions
|
@ -120,6 +120,28 @@ rb_predict(VALUE self, VALUE src)
|
|||
return INT2NUM(label);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* save(filename)
|
||||
*
|
||||
* Saves this model to a given filename, either as XML or YAML.
|
||||
*/
|
||||
VALUE
|
||||
rb_save(VALUE self, VALUE filename)
|
||||
{
|
||||
Check_Type(filename, T_STRING);
|
||||
cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
|
||||
try {
|
||||
char* s = StringValueCStr(filename);
|
||||
self_ptr->save(std::string(s));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
void
|
||||
define_ruby_class()
|
||||
{
|
||||
|
@ -136,6 +158,7 @@ define_ruby_class()
|
|||
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
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);
|
||||
}
|
||||
|
||||
__NAMESPACE_END_EIGENFACES
|
||||
|
|
|
@ -24,6 +24,7 @@ void define_ruby_class();
|
|||
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);
|
||||
|
||||
__NAMESPACE_END_EIGENFACES
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# -*- mode: ruby; coding: utf-8-unix -*-
|
||||
require 'test/unit'
|
||||
require 'opencv'
|
||||
require 'date'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
||||
|
||||
include OpenCV
|
||||
|
@ -49,5 +50,18 @@ class TestEigenFaces < OpenCVTestCase
|
|||
@eigenfaces.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)
|
||||
assert(File.exist? filename)
|
||||
ensure
|
||||
File.delete filename
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue