mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
update model function for cv::FaceRecognizer
This commit is contained in:
parent
f041d17b33
commit
74f89f3582
2 changed files with 52 additions and 0 deletions
|
@ -83,6 +83,43 @@ rb_train(VALUE self, VALUE src, VALUE labels)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* udpate(src, labels)
|
||||
*
|
||||
* Updates a FaceRecognizer with given data and associated labels. Only valid on LBPH models.
|
||||
*/
|
||||
VALUE
|
||||
rb_update(VALUE self, VALUE src, VALUE labels)
|
||||
{
|
||||
Check_Type(src, T_ARRAY);
|
||||
Check_Type(labels, T_ARRAY);
|
||||
|
||||
VALUE *src_ptr = RARRAY_PTR(src);
|
||||
int src_size = RARRAY_LEN(src);
|
||||
std::vector<cv::Mat> images;
|
||||
for (int i = 0; i < src_size; i++) {
|
||||
images.push_back(cv::Mat(CVMAT_WITH_CHECK(src_ptr[i])));
|
||||
}
|
||||
|
||||
VALUE *labels_ptr = RARRAY_PTR(labels);
|
||||
int labels_size = RARRAY_LEN(labels);
|
||||
std::vector<int> local_labels;
|
||||
for (int i = 0; i < labels_size; i++) {
|
||||
local_labels.push_back(NUM2INT(labels_ptr[i]));
|
||||
}
|
||||
|
||||
cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
|
||||
try {
|
||||
self_ptr->update(images, local_labels);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* predict(src)
|
||||
|
@ -171,6 +208,7 @@ init_ruby_class()
|
|||
VALUE alghorithm = cAlgorithm::rb_class();
|
||||
rb_klass = rb_define_class_under(opencv, "FaceRecognizer", alghorithm);
|
||||
rb_define_method(rb_klass, "train", RUBY_METHOD_FUNC(rb_train), 2);
|
||||
rb_define_method(rb_klass, "update", RUBY_METHOD_FUNC(rb_update), 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue