Last active
May 10, 2017 01:45
-
-
Save wermarter/a85308a41bde5a858aa786fe161d87ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "opencv2/core/core.hpp" | |
| #include "opencv2/contrib/contrib.hpp" | |
| #include "opencv2/highgui/highgui.hpp" | |
| #include <iostream> | |
| #include <fstream> | |
| #include <sstream> | |
| using namespace cv; | |
| using namespace std; | |
| int main(int argc, const char *argv[]){ | |
| // Data to be loaded | |
| vector<Mat> images; | |
| vector<int> labels; | |
| // | |
| Mat testSample = images[images.size() - 1]; | |
| int testLabel = labels[labels.size() - 1]; | |
| images.pop_back(); | |
| labels.pop_back(); | |
| // Train model | |
| Ptr<FaceRecognizer> model = createLBPHFaceRecognizer(); | |
| model->train(images, labels); | |
| // Predict faces | |
| int predictedLabel = model->predict(testSample); | |
| string result_message = format("Predicted class = %d / Actual class = %d.", predictedLabel, testLabel); | |
| // Save model | |
| string filename = "saved_model.sav"; | |
| model->save(filename); | |
| // Load model | |
| Ptr<FaceRecognizer> saved_model = createLBPHFaceRecognizer(); | |
| saved_model->load(filename); | |
| // Update model with new faces | |
| vector<Mat> images_update; | |
| vector<int> labels_update; | |
| saved_model->update(images_update, labels_update); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment