2013-08-05 14:42:28 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// 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:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's 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.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not 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 the Intel Corporation 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.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
2017-11-05 21:48:40 +08:00
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
|
|
|
namespace opencv_test { namespace {
|
|
|
|
|
2014-10-08 10:15:41 +08:00
|
|
|
#define OUTPUT_SAVING 0
|
|
|
|
#if OUTPUT_SAVING
|
|
|
|
#define SAVE(x) std::vector<int> params;\
|
|
|
|
params.push_back(16);\
|
|
|
|
params.push_back(0);\
|
|
|
|
imwrite(folder + "output.png", x ,params);
|
|
|
|
#else
|
|
|
|
#define SAVE(x)
|
|
|
|
#endif
|
2013-08-05 14:42:28 +08:00
|
|
|
|
2018-05-16 22:58:16 +08:00
|
|
|
static const double numerical_precision = 0.05; // 95% of pixels should have exact values
|
2013-08-05 14:42:28 +08:00
|
|
|
|
|
|
|
TEST(Photo_SeamlessClone_normal, regression)
|
|
|
|
{
|
|
|
|
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Normal_Cloning/";
|
|
|
|
string original_path1 = folder + "source1.png";
|
|
|
|
string original_path2 = folder + "destination1.png";
|
|
|
|
string original_path3 = folder + "mask.png";
|
2015-01-12 15:59:30 +08:00
|
|
|
string reference_path = folder + "reference.png";
|
2013-08-05 14:42:28 +08:00
|
|
|
|
|
|
|
Mat source = imread(original_path1, IMREAD_COLOR);
|
|
|
|
Mat destination = imread(original_path2, IMREAD_COLOR);
|
|
|
|
Mat mask = imread(original_path3, IMREAD_COLOR);
|
|
|
|
|
|
|
|
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
|
|
|
|
ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;
|
|
|
|
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;
|
|
|
|
|
|
|
|
Mat result;
|
|
|
|
Point p;
|
|
|
|
p.x = destination.size().width/2;
|
|
|
|
p.y = destination.size().height/2;
|
|
|
|
seamlessClone(source, destination, mask, p, result, 1);
|
|
|
|
|
2015-01-12 15:59:30 +08:00
|
|
|
Mat reference = imread(reference_path);
|
|
|
|
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
|
2014-10-08 10:15:41 +08:00
|
|
|
|
|
|
|
SAVE(result);
|
|
|
|
|
2018-05-16 22:58:16 +08:00
|
|
|
double errorINF = cvtest::norm(reference, result, NORM_INF);
|
|
|
|
EXPECT_LE(errorINF, 1);
|
|
|
|
double errorL1 = cvtest::norm(reference, result, NORM_L1);
|
|
|
|
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
|
2019-08-16 02:49:02 +08:00
|
|
|
|
|
|
|
mask = Scalar(0, 0, 0);
|
|
|
|
seamlessClone(source, destination, mask, p, result, 1);
|
|
|
|
|
|
|
|
reference = destination;
|
|
|
|
errorINF = cvtest::norm(reference, result, NORM_INF);
|
|
|
|
EXPECT_LE(errorINF, 1);
|
|
|
|
errorL1 = cvtest::norm(reference, result, NORM_L1);
|
|
|
|
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
|
2013-08-05 14:42:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Photo_SeamlessClone_mixed, regression)
|
|
|
|
{
|
|
|
|
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Mixed_Cloning/";
|
|
|
|
string original_path1 = folder + "source1.png";
|
|
|
|
string original_path2 = folder + "destination1.png";
|
|
|
|
string original_path3 = folder + "mask.png";
|
2015-01-12 15:59:30 +08:00
|
|
|
string reference_path = folder + "reference.png";
|
2013-08-05 14:42:28 +08:00
|
|
|
|
|
|
|
Mat source = imread(original_path1, IMREAD_COLOR);
|
|
|
|
Mat destination = imread(original_path2, IMREAD_COLOR);
|
|
|
|
Mat mask = imread(original_path3, IMREAD_COLOR);
|
|
|
|
|
|
|
|
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
|
|
|
|
ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;
|
|
|
|
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;
|
|
|
|
|
|
|
|
Mat result;
|
|
|
|
Point p;
|
|
|
|
p.x = destination.size().width/2;
|
|
|
|
p.y = destination.size().height/2;
|
|
|
|
seamlessClone(source, destination, mask, p, result, 2);
|
|
|
|
|
2014-10-08 10:15:41 +08:00
|
|
|
SAVE(result);
|
|
|
|
|
2015-01-12 15:59:30 +08:00
|
|
|
Mat reference = imread(reference_path);
|
|
|
|
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
|
|
|
|
|
2018-05-16 22:58:16 +08:00
|
|
|
double errorINF = cvtest::norm(reference, result, NORM_INF);
|
|
|
|
EXPECT_LE(errorINF, 1);
|
|
|
|
double errorL1 = cvtest::norm(reference, result, NORM_L1);
|
|
|
|
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
|
2013-08-05 14:42:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Photo_SeamlessClone_featureExchange, regression)
|
|
|
|
{
|
2013-09-03 23:42:05 +08:00
|
|
|
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Monochrome_Transfer/";
|
2013-08-05 14:42:28 +08:00
|
|
|
string original_path1 = folder + "source1.png";
|
|
|
|
string original_path2 = folder + "destination1.png";
|
|
|
|
string original_path3 = folder + "mask.png";
|
2015-01-12 15:59:30 +08:00
|
|
|
string reference_path = folder + "reference.png";
|
2013-08-05 14:42:28 +08:00
|
|
|
|
|
|
|
Mat source = imread(original_path1, IMREAD_COLOR);
|
|
|
|
Mat destination = imread(original_path2, IMREAD_COLOR);
|
|
|
|
Mat mask = imread(original_path3, IMREAD_COLOR);
|
|
|
|
|
|
|
|
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
|
|
|
|
ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;
|
|
|
|
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;
|
|
|
|
|
|
|
|
Mat result;
|
|
|
|
Point p;
|
|
|
|
p.x = destination.size().width/2;
|
|
|
|
p.y = destination.size().height/2;
|
|
|
|
seamlessClone(source, destination, mask, p, result, 3);
|
|
|
|
|
2014-10-08 10:15:41 +08:00
|
|
|
SAVE(result);
|
|
|
|
|
2015-01-12 15:59:30 +08:00
|
|
|
Mat reference = imread(reference_path);
|
|
|
|
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
|
|
|
|
|
2018-05-16 22:58:16 +08:00
|
|
|
double errorINF = cvtest::norm(reference, result, NORM_INF);
|
|
|
|
EXPECT_LE(errorINF, 1);
|
|
|
|
double errorL1 = cvtest::norm(reference, result, NORM_L1);
|
|
|
|
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
|
2013-08-05 14:42:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Photo_SeamlessClone_colorChange, regression)
|
|
|
|
{
|
2013-09-14 21:42:25 +08:00
|
|
|
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/color_change/";
|
2013-08-05 14:42:28 +08:00
|
|
|
string original_path1 = folder + "source1.png";
|
|
|
|
string original_path2 = folder + "mask.png";
|
2015-01-12 15:59:30 +08:00
|
|
|
string reference_path = folder + "reference.png";
|
2013-08-05 14:42:28 +08:00
|
|
|
|
|
|
|
Mat source = imread(original_path1, IMREAD_COLOR);
|
|
|
|
Mat mask = imread(original_path2, IMREAD_COLOR);
|
|
|
|
|
|
|
|
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
|
|
|
|
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;
|
|
|
|
|
|
|
|
Mat result;
|
|
|
|
colorChange(source, mask, result, 1.5, .5, .5);
|
|
|
|
|
2014-10-08 10:15:41 +08:00
|
|
|
SAVE(result);
|
|
|
|
|
2015-01-12 15:59:30 +08:00
|
|
|
Mat reference = imread(reference_path);
|
|
|
|
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
|
|
|
|
|
2018-05-16 22:58:16 +08:00
|
|
|
double errorINF = cvtest::norm(reference, result, NORM_INF);
|
|
|
|
EXPECT_LE(errorINF, 1);
|
|
|
|
double errorL1 = cvtest::norm(reference, result, NORM_L1);
|
|
|
|
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
|
2013-08-05 14:42:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Photo_SeamlessClone_illuminationChange, regression)
|
|
|
|
{
|
|
|
|
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Illumination_Change/";
|
|
|
|
string original_path1 = folder + "source1.png";
|
|
|
|
string original_path2 = folder + "mask.png";
|
2015-01-12 15:59:30 +08:00
|
|
|
string reference_path = folder + "reference.png";
|
2013-08-05 14:42:28 +08:00
|
|
|
|
|
|
|
Mat source = imread(original_path1, IMREAD_COLOR);
|
|
|
|
Mat mask = imread(original_path2, IMREAD_COLOR);
|
|
|
|
|
|
|
|
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
|
|
|
|
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;
|
|
|
|
|
|
|
|
Mat result;
|
2013-12-06 17:29:53 +08:00
|
|
|
illuminationChange(source, mask, result, 0.2f, 0.4f);
|
2013-08-05 14:42:28 +08:00
|
|
|
|
2014-10-08 10:15:41 +08:00
|
|
|
SAVE(result);
|
|
|
|
|
2015-01-12 15:59:30 +08:00
|
|
|
Mat reference = imread(reference_path);
|
2018-05-16 22:58:16 +08:00
|
|
|
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
|
2013-08-05 14:42:28 +08:00
|
|
|
|
2018-05-16 22:58:16 +08:00
|
|
|
double errorINF = cvtest::norm(reference, result, NORM_INF);
|
|
|
|
EXPECT_LE(errorINF, 1);
|
|
|
|
double errorL1 = cvtest::norm(reference, result, NORM_L1);
|
|
|
|
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
|
2013-08-05 14:42:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Photo_SeamlessClone_textureFlattening, regression)
|
|
|
|
{
|
|
|
|
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Texture_Flattening/";
|
2013-08-19 15:46:04 +08:00
|
|
|
string original_path1 = folder + "source1.png";
|
|
|
|
string original_path2 = folder + "mask.png";
|
2015-01-12 15:59:30 +08:00
|
|
|
string reference_path = folder + "reference.png";
|
2013-08-05 14:42:28 +08:00
|
|
|
|
2013-08-19 15:46:04 +08:00
|
|
|
Mat source = imread(original_path1, IMREAD_COLOR);
|
|
|
|
Mat mask = imread(original_path2, IMREAD_COLOR);
|
2013-08-05 14:42:28 +08:00
|
|
|
|
2013-08-19 15:46:04 +08:00
|
|
|
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
|
|
|
|
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;
|
2013-08-05 14:42:28 +08:00
|
|
|
|
|
|
|
Mat result;
|
2013-09-03 23:42:05 +08:00
|
|
|
textureFlattening(source, mask, result, 30, 45, 3);
|
2013-08-05 14:42:28 +08:00
|
|
|
|
2014-10-08 10:15:41 +08:00
|
|
|
SAVE(result);
|
|
|
|
|
2015-01-12 15:59:30 +08:00
|
|
|
Mat reference = imread(reference_path);
|
|
|
|
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
|
|
|
|
|
2018-05-16 22:58:16 +08:00
|
|
|
double errorINF = cvtest::norm(reference, result, NORM_INF);
|
|
|
|
EXPECT_LE(errorINF, 1);
|
|
|
|
double errorL1 = cvtest::norm(reference, result, NORM_L1);
|
|
|
|
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
|
2013-08-05 14:42:28 +08:00
|
|
|
}
|
2017-11-05 21:48:40 +08:00
|
|
|
|
|
|
|
}} // namespace
|