vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
By downloading, copying, installing or using the software you agree to this
|
||||
license. If you do not agree to this license, do not download, install,
|
||||
copy or use the software.
|
||||
|
||||
License Agreement
|
||||
For Open Source Computer Vision Library
|
||||
(3-clause BSD License)
|
||||
|
||||
Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
Third party copyrights are property of their respective owners.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the names of the copyright holders nor the names of the contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
This software is provided by the copyright holders and contributors "as is" and
|
||||
any express or implied warranties, including, but not limited to, the implied
|
||||
warranties of merchantability and fitness for a particular purpose are
|
||||
disclaimed. In no event shall copyright holders or contributors be liable for
|
||||
any direct, indirect, incidental, special, exemplary, or consequential damages
|
||||
(including, but not limited to, procurement of substitute goods or services;
|
||||
loss of use, data, or profits; or business interruption) however caused
|
||||
and on any theory of liability, whether in contract, strict liability,
|
||||
or tort (including negligence or otherwise) arising in any way out of
|
||||
the use of this software, even if advised of the possibility of such damage.
|
||||
*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
TEST(CV_Face_BIF, can_create_default) {
|
||||
cv::Ptr<cv::face::BIF> bif;
|
||||
EXPECT_NO_THROW(bif = cv::face::BIF::create());
|
||||
EXPECT_FALSE(bif.empty());
|
||||
}
|
||||
|
||||
TEST(CV_Face_BIF, fails_when_zero_bands) {
|
||||
EXPECT_ANY_THROW(cv::face::BIF::create(0));
|
||||
}
|
||||
|
||||
TEST(CV_Face_BIF, fails_when_too_many_bands) {
|
||||
EXPECT_ANY_THROW(cv::face::BIF::create(9));
|
||||
}
|
||||
|
||||
TEST(CV_Face_BIF, fails_when_zero_rotations) {
|
||||
EXPECT_ANY_THROW(cv::face::BIF::create(8, 0));
|
||||
}
|
||||
|
||||
TEST(CV_Face_BIF, can_compute) {
|
||||
cv::Mat image(60, 60, CV_32F);
|
||||
cv::theRNG().fill(image, cv::RNG::UNIFORM, -1, 1);
|
||||
|
||||
cv::Ptr<cv::face::BIF> bif = cv::face::BIF::create();
|
||||
cv::Mat fea;
|
||||
EXPECT_NO_THROW(bif->compute(image, fea));
|
||||
EXPECT_EQ(cv::Size(1, 13188), fea.size());
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
@@ -0,0 +1,93 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
using namespace cv::face;
|
||||
|
||||
static bool myDetector( InputArray image, OutputArray ROIs, CascadeClassifier* face_cascade)
|
||||
{
|
||||
Mat gray;
|
||||
std::vector<Rect> faces;
|
||||
if(image.channels()>1){
|
||||
cvtColor(image.getMat(),gray,COLOR_BGR2GRAY);
|
||||
}
|
||||
else{
|
||||
gray = image.getMat().clone();
|
||||
}
|
||||
equalizeHist( gray, gray );
|
||||
face_cascade->detectMultiScale( gray, faces, 1.1, 3, 0, Size(30, 30) );
|
||||
Mat(faces).copyTo(ROIs);
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(CV_Face_FacemarkKazemi, can_create_default) {
|
||||
string cascade_name = cvtest::findDataFile("face/lbpcascade_frontalface_improved.xml", true);
|
||||
string configfile_name = cvtest::findDataFile("face/config.xml", true);
|
||||
CascadeClassifier face_cascade;
|
||||
EXPECT_TRUE(face_cascade.load(cascade_name));
|
||||
FacemarkKazemi::Params params;
|
||||
params.configfile = configfile_name;
|
||||
Ptr<FacemarkKazemi> facemark;
|
||||
EXPECT_NO_THROW(facemark = FacemarkKazemi::create(params));
|
||||
EXPECT_TRUE(facemark->setFaceDetector((cv::face::FN_FaceDetector)myDetector, &face_cascade));
|
||||
EXPECT_FALSE(facemark.empty());
|
||||
}
|
||||
|
||||
TEST(CV_Face_FacemarkKazemi, can_loadTrainingData) {
|
||||
string filename = cvtest::findDataFile("face/lbpcascade_frontalface_improved.xml", true);
|
||||
string configfile_name = cvtest::findDataFile("face/config.xml", true);
|
||||
CascadeClassifier face_cascade;
|
||||
EXPECT_TRUE(face_cascade.load(filename));
|
||||
FacemarkKazemi::Params params;
|
||||
params.configfile = configfile_name;
|
||||
Ptr<FacemarkKazemi> facemark;
|
||||
EXPECT_NO_THROW(facemark = FacemarkKazemi::create(params));
|
||||
EXPECT_TRUE(facemark->setFaceDetector((cv::face::FN_FaceDetector)myDetector, &face_cascade));
|
||||
vector<String> filenames;
|
||||
filename = cvtest::findDataFile("face/1.txt", true);
|
||||
filenames.push_back(filename);
|
||||
filename = cvtest::findDataFile("face/2.txt", true);
|
||||
filenames.push_back(filename);
|
||||
vector<String> imagenames;
|
||||
vector< vector<Point2f> > trainlandmarks,Trainlandmarks;
|
||||
vector<Rect> rectangles;
|
||||
//Test getData function
|
||||
EXPECT_NO_THROW(loadTrainingData(filenames,trainlandmarks,imagenames));
|
||||
vector<Mat> trainimages;
|
||||
for(unsigned long i=0;i<imagenames.size();i++){
|
||||
string img = cvtest::findDataFile(imagenames[i], true);
|
||||
Mat src = imread(img);
|
||||
EXPECT_TRUE(!src.empty());
|
||||
trainimages.push_back(src);
|
||||
Trainlandmarks.push_back(trainlandmarks[i]);
|
||||
}
|
||||
string modelfilename = "face_landmark_model.dat";
|
||||
Size scale = Size(460,460);
|
||||
EXPECT_TRUE(facemark->training(trainimages,Trainlandmarks,configfile_name,scale,modelfilename));
|
||||
}
|
||||
TEST(CV_Face_FacemarkKazemi, can_detect_landmarks) {
|
||||
string cascade_name = cvtest::findDataFile("face/lbpcascade_frontalface_improved.xml", true);
|
||||
CascadeClassifier face_cascade;
|
||||
face_cascade.load(cascade_name);
|
||||
FacemarkKazemi::Params params;
|
||||
Ptr<FacemarkKazemi> facemark;
|
||||
EXPECT_NO_THROW(facemark = FacemarkKazemi::create(params));
|
||||
EXPECT_TRUE(facemark->setFaceDetector((cv::face::FN_FaceDetector)myDetector, &face_cascade));
|
||||
string imgname = cvtest::findDataFile("face/detect.jpg");
|
||||
string modelfilename = cvtest::findDataFile("face/face_landmark_model.dat",true);
|
||||
Mat img = imread(imgname);
|
||||
EXPECT_TRUE(!img.empty());
|
||||
EXPECT_FALSE(facemark.empty());
|
||||
EXPECT_NO_THROW(facemark->loadModel(modelfilename));
|
||||
vector<Rect> faces;
|
||||
//Detect faces in the current image
|
||||
EXPECT_TRUE(facemark->getFaces(img,faces));
|
||||
//vector to store the landmarks of all the faces in the image
|
||||
vector< vector<Point2f> > shapes;
|
||||
EXPECT_NO_THROW(facemark->fit(img,faces,shapes));
|
||||
shapes.clear();
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
By downloading, copying, installing or using the software you agree to this
|
||||
license. If you do not agree to this license, do not download, install,
|
||||
copy or use the software.
|
||||
License Agreement
|
||||
For Open Source Computer Vision Library
|
||||
(3-clause BSD License)
|
||||
Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
Third party copyrights are property of their respective owners.
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the names of the copyright holders nor the names of the contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
This software is provided by the copyright holders and contributors "as is" and
|
||||
any express or implied warranties, including, but not limited to, the implied
|
||||
warranties of merchantability and fitness for a particular purpose are
|
||||
disclaimed. In no event shall copyright holders or contributors be liable for
|
||||
any direct, indirect, incidental, special, exemplary, or consequential damages
|
||||
(including, but not limited to, procurement of substitute goods or services;
|
||||
loss of use, data, or profits; or business interruption) however caused
|
||||
and on any theory of liability, whether in contract, strict liability,
|
||||
or tort (including negligence or otherwise) arising in any way out of
|
||||
the use of this software, even if advised of the possibility of such damage.
|
||||
|
||||
This file was part of GSoC Project: Facemark API for OpenCV
|
||||
Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc
|
||||
Student: Laksono Kurnianggoro
|
||||
Mentor: Delia Passalacqua
|
||||
*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
TEST(CV_Face_Facemark, test_utilities) {
|
||||
string image_file = cvtest::findDataFile("face/david1.jpg", true);
|
||||
string annotation_file = cvtest::findDataFile("face/david1.pts", true);
|
||||
string cascade_filename =
|
||||
cvtest::findDataFile("cascadeandhog/cascades/lbpcascade_frontalface.xml", true);
|
||||
|
||||
std::vector<Point2f> facial_points;
|
||||
EXPECT_NO_THROW(loadFacePoints(annotation_file,facial_points));
|
||||
|
||||
Mat img = imread(image_file);
|
||||
EXPECT_NO_THROW(drawFacemarks(img, facial_points, Scalar(0,0,255)));
|
||||
|
||||
CParams params(cascade_filename);
|
||||
std::vector<Rect> faces;
|
||||
EXPECT_TRUE(getFaces(img, faces, ¶ms));
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
By downloading, copying, installing or using the software you agree to this
|
||||
license. If you do not agree to this license, do not download, install,
|
||||
copy or use the software.
|
||||
License Agreement
|
||||
For Open Source Computer Vision Library
|
||||
(3-clause BSD License)
|
||||
Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
Third party copyrights are property of their respective owners.
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the names of the copyright holders nor the names of the contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
This software is provided by the copyright holders and contributors "as is" and
|
||||
any express or implied warranties, including, but not limited to, the implied
|
||||
warranties of merchantability and fitness for a particular purpose are
|
||||
disclaimed. In no event shall copyright holders or contributors be liable for
|
||||
any direct, indirect, incidental, special, exemplary, or consequential damages
|
||||
(including, but not limited to, procurement of substitute goods or services;
|
||||
loss of use, data, or profits; or business interruption) however caused
|
||||
and on any theory of liability, whether in contract, strict liability,
|
||||
or tort (including negligence or otherwise) arising in any way out of
|
||||
the use of this software, even if advised of the possibility of such damage.
|
||||
|
||||
This file was part of GSoC Project: Facemark API for OpenCV
|
||||
Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc
|
||||
Student: Laksono Kurnianggoro
|
||||
Mentor: Delia Passalacqua
|
||||
*/
|
||||
|
||||
/*Usage:
|
||||
download the opencv_extra from https://github.com/opencv/opencv_extra
|
||||
and then execute the following commands:
|
||||
export OPENCV_TEST_DATA_PATH=/home/opencv/opencv_extra/testdata
|
||||
<build_folder>/bin/opencv_test_face
|
||||
*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
static bool customDetector( InputArray image, OutputArray ROIs, CascadeClassifier *face_detector){
|
||||
Mat gray;
|
||||
std::vector<Rect> & faces = *(std::vector<Rect>*) ROIs.getObj();
|
||||
faces.clear();
|
||||
|
||||
if(image.channels()>1){
|
||||
cvtColor(image.getMat(),gray, COLOR_BGR2GRAY);
|
||||
}else{
|
||||
gray = image.getMat().clone();
|
||||
}
|
||||
equalizeHist( gray, gray );
|
||||
|
||||
face_detector->detectMultiScale( gray, faces, 1.4, 2, CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(CV_Face_FacemarkAAM, can_create_default) {
|
||||
FacemarkAAM::Params params;
|
||||
|
||||
Ptr<FacemarkAAM> facemark;
|
||||
EXPECT_NO_THROW(facemark = FacemarkAAM::create(params));
|
||||
EXPECT_FALSE(facemark.empty());
|
||||
}
|
||||
|
||||
TEST(CV_Face_FacemarkAAM, can_set_custom_detector) {
|
||||
string cascade_filename =
|
||||
cvtest::findDataFile("cascadeandhog/cascades/lbpcascade_frontalface.xml", true);
|
||||
CascadeClassifier face_detector;
|
||||
EXPECT_TRUE(face_detector.load(cascade_filename));
|
||||
|
||||
Ptr<FacemarkAAM> facemark = FacemarkAAM::create();
|
||||
EXPECT_TRUE(facemark->setFaceDetector((cv::face::FN_FaceDetector)customDetector, &face_detector));
|
||||
}
|
||||
|
||||
TEST(CV_Face_FacemarkAAM, test_workflow) {
|
||||
|
||||
string i1 = cvtest::findDataFile("face/david1.jpg", true);
|
||||
string p1 = cvtest::findDataFile("face/david1.pts", true);
|
||||
string i2 = cvtest::findDataFile("face/david2.jpg", true);
|
||||
string p2 = cvtest::findDataFile("face/david2.pts", true);
|
||||
|
||||
std::vector<string> images_train;
|
||||
images_train.push_back(i1);
|
||||
images_train.push_back(i2);
|
||||
|
||||
std::vector<String> points_train;
|
||||
points_train.push_back(p1);
|
||||
points_train.push_back(p2);
|
||||
|
||||
string cascade_filename =
|
||||
cvtest::findDataFile("cascadeandhog/cascades/lbpcascade_frontalface.xml", true);
|
||||
CascadeClassifier face_detector;
|
||||
EXPECT_TRUE(face_detector.load(cascade_filename));
|
||||
|
||||
FacemarkAAM::Params params;
|
||||
params.n = 1;
|
||||
params.m = 1;
|
||||
params.verbose = false;
|
||||
params.save_model = false;
|
||||
Ptr<FacemarkAAM> facemark = FacemarkAAM::create(params);
|
||||
|
||||
Mat image;
|
||||
std::vector<Point2f> landmarks;
|
||||
for(size_t i = 0; i < images_train.size(); i++)
|
||||
{
|
||||
image = imread(images_train[i].c_str());
|
||||
EXPECT_TRUE(loadFacePoints(points_train[i].c_str(),landmarks));
|
||||
EXPECT_TRUE(landmarks.size()>0);
|
||||
EXPECT_TRUE(facemark->addTrainingSample(image, landmarks));
|
||||
}
|
||||
|
||||
EXPECT_NO_THROW(facemark->training());
|
||||
|
||||
/*------------ Fitting Part ---------------*/
|
||||
EXPECT_TRUE(facemark->setFaceDetector((cv::face::FN_FaceDetector)customDetector, &face_detector));
|
||||
string image_filename = cvtest::findDataFile("face/david1.jpg", true);
|
||||
image = imread(image_filename.c_str());
|
||||
EXPECT_TRUE(!image.empty());
|
||||
|
||||
std::vector<Rect> rects;
|
||||
std::vector<std::vector<Point2f> > facial_points;
|
||||
|
||||
EXPECT_TRUE(facemark->getFaces(image, rects));
|
||||
EXPECT_TRUE(rects.size()>0);
|
||||
EXPECT_TRUE(facemark->fit(image, rects, facial_points));
|
||||
EXPECT_TRUE(facial_points[0].size()>0);
|
||||
|
||||
/*------------ Test getData ---------------*/
|
||||
FacemarkAAM::Data data;
|
||||
EXPECT_TRUE(facemark->getData(&data));
|
||||
EXPECT_TRUE(data.s0.size()>0);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
By downloading, copying, installing or using the software you agree to this
|
||||
license. If you do not agree to this license, do not download, install,
|
||||
copy or use the software.
|
||||
License Agreement
|
||||
For Open Source Computer Vision Library
|
||||
(3-clause BSD License)
|
||||
Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
Third party copyrights are property of their respective owners.
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the names of the copyright holders nor the names of the contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
This software is provided by the copyright holders and contributors "as is" and
|
||||
any express or implied warranties, including, but not limited to, the implied
|
||||
warranties of merchantability and fitness for a particular purpose are
|
||||
disclaimed. In no event shall copyright holders or contributors be liable for
|
||||
any direct, indirect, incidental, special, exemplary, or consequential damages
|
||||
(including, but not limited to, procurement of substitute goods or services;
|
||||
loss of use, data, or profits; or business interruption) however caused
|
||||
and on any theory of liability, whether in contract, strict liability,
|
||||
or tort (including negligence or otherwise) arising in any way out of
|
||||
the use of this software, even if advised of the possibility of such damage.
|
||||
|
||||
This file was part of GSoC Project: Facemark API for OpenCV
|
||||
Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc
|
||||
Student: Laksono Kurnianggoro
|
||||
Mentor: Delia Passalacqua
|
||||
*/
|
||||
|
||||
/*Usage:
|
||||
download the opencv_extra from https://github.com/opencv/opencv_extra
|
||||
and then execute the following commands:
|
||||
export OPENCV_TEST_DATA_PATH=/home/opencv/opencv_extra/testdata
|
||||
<build_folder>/bin/opencv_test_face
|
||||
*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
CascadeClassifier cascade_detector;
|
||||
static bool myCustomDetector( InputArray image, OutputArray ROIs, void * config = 0 ){
|
||||
Mat gray;
|
||||
std::vector<Rect> & faces = *(std::vector<Rect>*) ROIs.getObj();
|
||||
faces.clear();
|
||||
|
||||
if(config!=0){
|
||||
//do nothing
|
||||
}
|
||||
|
||||
if(image.channels()>1){
|
||||
cvtColor(image.getMat(),gray,COLOR_BGR2GRAY);
|
||||
}else{
|
||||
gray = image.getMat().clone();
|
||||
}
|
||||
equalizeHist( gray, gray );
|
||||
|
||||
cascade_detector.detectMultiScale( gray, faces, 1.4, 2, CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(CV_Face_FacemarkLBF, can_create_default) {
|
||||
FacemarkLBF::Params params;
|
||||
params.n_landmarks = 68;
|
||||
|
||||
Ptr<FacemarkLBF> facemark;
|
||||
EXPECT_NO_THROW(facemark = FacemarkLBF::create(params));
|
||||
EXPECT_FALSE(facemark.empty());
|
||||
}
|
||||
|
||||
TEST(CV_Face_FacemarkLBF, can_set_custom_detector) {
|
||||
string cascade_filename =
|
||||
cvtest::findDataFile("cascadeandhog/cascades/lbpcascade_frontalface.xml", true);
|
||||
|
||||
EXPECT_TRUE(cascade_detector.load(cascade_filename));
|
||||
|
||||
Ptr<FacemarkLBF> facemark = FacemarkLBF::create();
|
||||
EXPECT_TRUE(facemark->setFaceDetector(myCustomDetector));
|
||||
}
|
||||
|
||||
TEST(CV_Face_FacemarkLBF, test_workflow) {
|
||||
|
||||
string i1 = cvtest::findDataFile("face/david1.jpg", true);
|
||||
string p1 = cvtest::findDataFile("face/david1.pts", true);
|
||||
string i2 = cvtest::findDataFile("face/david2.jpg", true);
|
||||
string p2 = cvtest::findDataFile("face/david2.pts", true);
|
||||
|
||||
std::vector<string> images_train;
|
||||
images_train.push_back(i1);
|
||||
images_train.push_back(i2);
|
||||
|
||||
std::vector<String> points_train;
|
||||
points_train.push_back(p1);
|
||||
points_train.push_back(p2);
|
||||
|
||||
string cascade_filename =
|
||||
cvtest::findDataFile("cascadeandhog/cascades/lbpcascade_frontalface.xml", true);
|
||||
FacemarkLBF::Params params;
|
||||
params.cascade_face = cascade_filename;
|
||||
params.verbose = false;
|
||||
params.save_model = false;
|
||||
|
||||
Ptr<FacemarkLBF> facemark = FacemarkLBF::create(params);
|
||||
|
||||
Mat image;
|
||||
std::vector<Point2f> landmarks;
|
||||
for(size_t i=0;i<images_train.size();i++){
|
||||
image = imread(images_train[i].c_str());
|
||||
EXPECT_TRUE(loadFacePoints(points_train[i].c_str(),landmarks));
|
||||
EXPECT_TRUE(landmarks.size()>0);
|
||||
EXPECT_TRUE(facemark->addTrainingSample(image, landmarks));
|
||||
}
|
||||
|
||||
EXPECT_NO_THROW(facemark->training());
|
||||
|
||||
/*------------ Fitting Part ---------------*/
|
||||
cascade_detector.load(cascade_filename);
|
||||
facemark->setFaceDetector(myCustomDetector);
|
||||
|
||||
string image_filename = cvtest::findDataFile("face/david1.jpg", true);
|
||||
image = imread(image_filename.c_str());
|
||||
EXPECT_TRUE(!image.empty());
|
||||
|
||||
std::vector<Rect> rects;
|
||||
std::vector<std::vector<Point2f> > facial_points;
|
||||
|
||||
EXPECT_TRUE(facemark->getFaces(image, rects));
|
||||
EXPECT_TRUE(rects.size()>0);
|
||||
EXPECT_TRUE(facemark->fit(image, rects, facial_points));
|
||||
EXPECT_TRUE(facial_points[0].size()>0);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
By downloading, copying, installing or using the software you agree to this
|
||||
license. If you do not agree to this license, do not download, install,
|
||||
copy or use the software.
|
||||
|
||||
License Agreement
|
||||
For Open Source Computer Vision Library
|
||||
(3-clause BSD License)
|
||||
|
||||
Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
Third party copyrights are property of their respective owners.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the names of the copyright holders nor the names of the contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
This software is provided by the copyright holders and contributors "as is" and
|
||||
any express or implied warranties, including, but not limited to, the implied
|
||||
warranties of merchantability and fitness for a particular purpose are
|
||||
disclaimed. In no event shall copyright holders or contributors be liable for
|
||||
any direct, indirect, incidental, special, exemplary, or consequential damages
|
||||
(including, but not limited to, procurement of substitute goods or services;
|
||||
loss of use, data, or profits; or business interruption) however caused
|
||||
and on any theory of liability, whether in contract, strict liability,
|
||||
or tort (including negligence or otherwise) arising in any way out of
|
||||
the use of this software, even if advised of the possibility of such damage.
|
||||
*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
// regression for #1267
|
||||
// let's make sure, that both Algorithm::save(String) and
|
||||
// FaceRecognizer::write(String) lead to the same result
|
||||
|
||||
void make_test_data(std::vector<cv::Mat> &images, std::vector<int> &labels) {
|
||||
for (int i=0; i<5; i++) {
|
||||
cv::Mat m(100,100,CV_8U);
|
||||
cv::randu(m,0,255);
|
||||
images.push_back(m);
|
||||
labels.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CV_Face_SAVELOAD, use_save) {
|
||||
std::vector<cv::Mat> images;
|
||||
std::vector<int> labels;
|
||||
make_test_data(images, labels);
|
||||
cv::Ptr<cv::face::FaceRecognizer> model1 = cv::face::LBPHFaceRecognizer::create();
|
||||
model1->train(images,labels);
|
||||
model1->save("fr.xml");
|
||||
int p1 = model1->predict(images[2]);
|
||||
cv::Ptr<cv::face::FaceRecognizer> model2 = cv::face::LBPHFaceRecognizer::create();
|
||||
model2->read("fr.xml");
|
||||
EXPECT_EQ(model2->empty(), false);
|
||||
EXPECT_EQ(p1, model2->predict(images[2]));
|
||||
}
|
||||
|
||||
TEST(CV_Face_SAVELOAD, use_write) {
|
||||
std::vector<cv::Mat> images;
|
||||
std::vector<int> labels;
|
||||
make_test_data(images, labels);
|
||||
cv::Ptr<cv::face::FaceRecognizer> model1 = cv::face::LBPHFaceRecognizer::create();
|
||||
model1->train(images,labels);
|
||||
model1->write("fr.xml");
|
||||
int p1 = model1->predict(images[2]);
|
||||
cv::Ptr<cv::face::FaceRecognizer> model2 = cv::face::LBPHFaceRecognizer::create();
|
||||
model2->read("fr.xml");
|
||||
EXPECT_EQ(model2->empty(), false);
|
||||
EXPECT_EQ(p1, model2->predict(images[2]));
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
@@ -0,0 +1,68 @@
|
||||
// This file is part of the OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include <fstream>
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
const string FACE_DIR = "face";
|
||||
const int WINDOW_SIZE = 64;
|
||||
|
||||
class MaceTest
|
||||
{
|
||||
public:
|
||||
|
||||
MaceTest(bool salt);
|
||||
void run();
|
||||
|
||||
protected:
|
||||
Ptr<MACE> mace;
|
||||
bool salt;
|
||||
};
|
||||
|
||||
MaceTest::MaceTest(bool use_salt)
|
||||
{
|
||||
mace = MACE::create(WINDOW_SIZE);
|
||||
salt = use_salt;
|
||||
}
|
||||
|
||||
void MaceTest::run()
|
||||
{
|
||||
Rect david1 (125,66,58,56);
|
||||
Rect david2 (132,69,73,74);
|
||||
Rect detect (199,124,256,274);
|
||||
string folder = cvtest::TS::ptr()->get_data_path() + FACE_DIR;
|
||||
Mat train = imread(folder + "/david2.jpg", 0);
|
||||
Mat tst_p = imread(folder + "/david1.jpg", 0);
|
||||
Mat tst_n = imread(folder + "/detect.jpg", 0);
|
||||
vector<Mat> sam_train;
|
||||
sam_train.push_back( train(Rect(132,69,73,74)) );
|
||||
sam_train.push_back( train(Rect(130,69,73,72)) );
|
||||
sam_train.push_back( train(Rect(134,67,73,74)) );
|
||||
sam_train.push_back( tst_p(Rect(125,66,58,56)) );
|
||||
sam_train.push_back( tst_p(Rect(123,67,55,58)) );
|
||||
sam_train.push_back( tst_p(Rect(125,65,58,60)) );
|
||||
|
||||
if (salt) mace->salt("it's david"); // "owner's" salt
|
||||
mace->train(sam_train);
|
||||
bool self_ok = mace->same(train(david2));
|
||||
if (salt) mace->salt("this is a test"); // "other's" salt
|
||||
bool false_A = mace->same(tst_n(detect));
|
||||
ASSERT_TRUE(self_ok);
|
||||
ASSERT_FALSE(false_A);
|
||||
}
|
||||
|
||||
|
||||
TEST(MACE_, unsalted)
|
||||
{
|
||||
MaceTest test(false); test.run();
|
||||
}
|
||||
TEST(MACE_, salted)
|
||||
{
|
||||
MaceTest test(true); test.run();
|
||||
}
|
||||
|
||||
|
||||
}} // namespace
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
By downloading, copying, installing or using the software you agree to this
|
||||
license. If you do not agree to this license, do not download, install,
|
||||
copy or use the software.
|
||||
|
||||
License Agreement
|
||||
For Open Source Computer Vision Library
|
||||
(3-clause BSD License)
|
||||
|
||||
Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
Third party copyrights are property of their respective owners.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the names of the copyright holders nor the names of the contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
This software is provided by the copyright holders and contributors "as is" and
|
||||
any express or implied warranties, including, but not limited to, the implied
|
||||
warranties of merchantability and fitness for a particular purpose are
|
||||
disclaimed. In no event shall copyright holders or contributors be liable for
|
||||
any direct, indirect, incidental, special, exemplary, or consequential damages
|
||||
(including, but not limited to, procurement of substitute goods or services;
|
||||
loss of use, data, or profits; or business interruption) however caused
|
||||
and on any theory of liability, whether in contract, strict liability,
|
||||
or tort (including negligence or otherwise) arising in any way out of
|
||||
the use of this software, even if advised of the possibility of such damage.
|
||||
*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
CV_TEST_MAIN("cv")
|
||||
@@ -0,0 +1,17 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/xobjdetect.hpp"
|
||||
#include "opencv2/face.hpp"
|
||||
#include "opencv2/face/bif.hpp"
|
||||
|
||||
namespace opencv_test {
|
||||
using namespace cv::face;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user