Class: OpenCV::FaceRecognizer
- Defined in:
- ext/opencv/lbph.cpp,
ext/opencv/eigenfaces.cpp,
ext/opencv/fisherfaces.cpp,
ext/opencv/facerecognizer.cpp
Direct Known Subclasses
Instance Method Summary collapse
-
#load(filename) ⇒ Object
Loads a FaceRecognizer and its model state.
-
#predict(src) ⇒ Object
Predicts a label and associated confidence (e.g. distance) for a given input image.
-
#save(filename) ⇒ Object
Saves this model to a given filename, either as XML or YAML.
-
#train(src, labels) ⇒ Object
Trains a FaceRecognizer with given data and associated labels.
Methods inherited from Algorithm
#get_bool, #get_double, #get_int, #get_mat, #get_matvector, #get_string, #name, #set_algorithm, #set_bool, #set_double, #set_int, #set_mat, #set_matvector, #set_string
Instance Method Details
#load(filename) ⇒ Object
Loads a FaceRecognizer and its model state.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'ext/opencv/facerecognizer.cpp', line 138
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;
}
|
#predict(src) ⇒ Object
Predicts a label and associated confidence (e.g. distance) for a given input image.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'ext/opencv/facerecognizer.cpp', line 92
VALUE
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 {
self_ptr->predict(mat, label, confidence);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return rb_ary_new3(2, INT2NUM(label), DBL2NUM(confidence));
}
|
#save(filename) ⇒ Object
Saves this model to a given filename, either as XML or YAML.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'ext/opencv/facerecognizer.cpp', line 116
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;
}
|
#train(src, labels) ⇒ Object
Trains a FaceRecognizer with given data and associated labels.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'ext/opencv/facerecognizer.cpp', line 55
VALUE
rb_train(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->train(images, local_labels);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return Qnil;
}
|