mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add variation of predict that also returns the confidence
This commit is contained in:
parent
cfcf6fa0ba
commit
0a3295cf32
3 changed files with 49 additions and 0 deletions
|
@ -106,6 +106,30 @@ rb_predict(VALUE self, VALUE src)
|
|||
return INT2NUM(label);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* predict_with_confidence(src)
|
||||
*
|
||||
* Predicts a label and associated confidence (e.g. distance) for a given input image.
|
||||
*/
|
||||
VALUE
|
||||
rb_predict_with_confidence(VALUE self, VALUE src)
|
||||
{
|
||||
cv::Mat mat = cv::Mat(CVMAT_WITH_CHECK(src));
|
||||
cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
|
||||
int label;
|
||||
double confidence;
|
||||
try {
|
||||
self_ptr->predict(mat, label, confidence);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
raise_cverror(e);
|
||||
}
|
||||
|
||||
return rb_ary_new3(2, INT2NUM(label), DBL2NUM(confidence));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* save(filename)
|
||||
|
@ -164,6 +188,7 @@ define_ruby_class()
|
|||
rb_klass = rb_define_class_under(opencv, "FaceRecognizer", cAlgorithm::rb_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, "predict_with_confidence", RUBY_METHOD_FUNC(rb_predict_with_confidence), 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