|
| 1 | +/* |
| 2 | +By downloading, copying, installing or using the software you agree to this |
| 3 | +license. If you do not agree to this license, do not download, install, |
| 4 | +copy or use the software. |
| 5 | +
|
| 6 | + License Agreement |
| 7 | + For Open Source Computer Vision Library |
| 8 | + (3-clause BSD License) |
| 9 | +
|
| 10 | +Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
| 11 | +Third party copyrights are property of their respective owners. |
| 12 | +
|
| 13 | +Redistribution and use in source and binary forms, with or without modification, |
| 14 | +are permitted provided that the following conditions are met: |
| 15 | +
|
| 16 | + * Redistributions of source code must retain the above copyright notice, |
| 17 | + this list of conditions and the following disclaimer. |
| 18 | +
|
| 19 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 20 | + this list of conditions and the following disclaimer in the documentation |
| 21 | + and/or other materials provided with the distribution. |
| 22 | +
|
| 23 | + * Neither the names of the copyright holders nor the names of the contributors |
| 24 | + may be used to endorse or promote products derived from this software |
| 25 | + without specific prior written permission. |
| 26 | +
|
| 27 | +This software is provided by the copyright holders and contributors "as is" and |
| 28 | +any express or implied warranties, including, but not limited to, the implied |
| 29 | +warranties of merchantability and fitness for a particular purpose are |
| 30 | +disclaimed. In no event shall copyright holders or contributors be liable for |
| 31 | +any direct, indirect, incidental, special, exemplary, or consequential damages |
| 32 | +(including, but not limited to, procurement of substitute goods or services; |
| 33 | +loss of use, data, or profits; or business interruption) however caused |
| 34 | +and on any theory of liability, whether in contract, strict liability, |
| 35 | +or tort (including negligence or otherwise) arising in any way out of |
| 36 | +the use of this software, even if advised of the possibility of such damage. |
| 37 | +*/ |
| 38 | + |
| 39 | +#include "test_precomp.hpp" |
| 40 | + |
| 41 | +// regression for #1267 |
| 42 | +// let's make sure, that both Algorithm::save(String) and |
| 43 | +// FaceRecognizer::write(String) lead to the same result |
| 44 | + |
| 45 | +void make_test_data(std::vector<cv::Mat> &images, std::vector<int> &labels) { |
| 46 | + for (int i=0; i<5; i++) { |
| 47 | + cv::Mat m(100,100,CV_8U); |
| 48 | + cv::randu(m,0,255); |
| 49 | + images.push_back(m); |
| 50 | + labels.push_back(i); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +TEST(CV_Face_SAVELOAD, use_save) { |
| 55 | + std::vector<cv::Mat> images; |
| 56 | + std::vector<int> labels; |
| 57 | + make_test_data(images, labels); |
| 58 | + cv::Ptr<cv::face::FaceRecognizer> model1 = cv::face::LBPHFaceRecognizer::create(); |
| 59 | + model1->train(images,labels); |
| 60 | + model1->save("fr.xml"); |
| 61 | + int p1 = model1->predict(images[2]); |
| 62 | + cv::Ptr<cv::face::FaceRecognizer> model2 = cv::face::LBPHFaceRecognizer::create(); |
| 63 | + model2->read("fr.xml"); |
| 64 | + EXPECT_EQ(model2->empty(), false); |
| 65 | + EXPECT_EQ(p1, model2->predict(images[2])); |
| 66 | +} |
| 67 | + |
| 68 | +TEST(CV_Face_SAVELOAD, use_write) { |
| 69 | + std::vector<cv::Mat> images; |
| 70 | + std::vector<int> labels; |
| 71 | + make_test_data(images, labels); |
| 72 | + cv::Ptr<cv::face::FaceRecognizer> model1 = cv::face::LBPHFaceRecognizer::create(); |
| 73 | + model1->train(images,labels); |
| 74 | + model1->write("fr.xml"); |
| 75 | + int p1 = model1->predict(images[2]); |
| 76 | + cv::Ptr<cv::face::FaceRecognizer> model2 = cv::face::LBPHFaceRecognizer::create(); |
| 77 | + model2->read("fr.xml"); |
| 78 | + EXPECT_EQ(model2->empty(), false); |
| 79 | + EXPECT_EQ(p1, model2->predict(images[2])); |
| 80 | +} |
0 commit comments