Path: blob/master/modules/photo/test/test_cloning.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2013, OpenCV Foundation, all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of the copyright holders may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "test_precomp.hpp"4243namespace opencv_test { namespace {4445#define OUTPUT_SAVING 046#if OUTPUT_SAVING47#define SAVE(x) std::vector<int> params;\48params.push_back(16);\49params.push_back(0);\50imwrite(folder + "output.png", x ,params);51#else52#define SAVE(x)53#endif5455static const double numerical_precision = 0.05; // 95% of pixels should have exact values5657TEST(Photo_SeamlessClone_normal, regression)58{59string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Normal_Cloning/";60string original_path1 = folder + "source1.png";61string original_path2 = folder + "destination1.png";62string original_path3 = folder + "mask.png";63string reference_path = folder + "reference.png";6465Mat source = imread(original_path1, IMREAD_COLOR);66Mat destination = imread(original_path2, IMREAD_COLOR);67Mat mask = imread(original_path3, IMREAD_COLOR);6869ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;70ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;71ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;7273Mat result;74Point p;75p.x = destination.size().width/2;76p.y = destination.size().height/2;77seamlessClone(source, destination, mask, p, result, 1);7879Mat reference = imread(reference_path);80ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;8182SAVE(result);8384double errorINF = cvtest::norm(reference, result, NORM_INF);85EXPECT_LE(errorINF, 1);86double errorL1 = cvtest::norm(reference, result, NORM_L1);87EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();88}8990TEST(Photo_SeamlessClone_mixed, regression)91{92string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Mixed_Cloning/";93string original_path1 = folder + "source1.png";94string original_path2 = folder + "destination1.png";95string original_path3 = folder + "mask.png";96string reference_path = folder + "reference.png";9798Mat source = imread(original_path1, IMREAD_COLOR);99Mat destination = imread(original_path2, IMREAD_COLOR);100Mat mask = imread(original_path3, IMREAD_COLOR);101102ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;103ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;104ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;105106Mat result;107Point p;108p.x = destination.size().width/2;109p.y = destination.size().height/2;110seamlessClone(source, destination, mask, p, result, 2);111112SAVE(result);113114Mat reference = imread(reference_path);115ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;116117double errorINF = cvtest::norm(reference, result, NORM_INF);118EXPECT_LE(errorINF, 1);119double errorL1 = cvtest::norm(reference, result, NORM_L1);120EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();121}122123TEST(Photo_SeamlessClone_featureExchange, regression)124{125string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Monochrome_Transfer/";126string original_path1 = folder + "source1.png";127string original_path2 = folder + "destination1.png";128string original_path3 = folder + "mask.png";129string reference_path = folder + "reference.png";130131Mat source = imread(original_path1, IMREAD_COLOR);132Mat destination = imread(original_path2, IMREAD_COLOR);133Mat mask = imread(original_path3, IMREAD_COLOR);134135ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;136ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;137ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;138139Mat result;140Point p;141p.x = destination.size().width/2;142p.y = destination.size().height/2;143seamlessClone(source, destination, mask, p, result, 3);144145SAVE(result);146147Mat reference = imread(reference_path);148ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;149150double errorINF = cvtest::norm(reference, result, NORM_INF);151EXPECT_LE(errorINF, 1);152double errorL1 = cvtest::norm(reference, result, NORM_L1);153EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();154}155156TEST(Photo_SeamlessClone_colorChange, regression)157{158string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/color_change/";159string original_path1 = folder + "source1.png";160string original_path2 = folder + "mask.png";161string reference_path = folder + "reference.png";162163Mat source = imread(original_path1, IMREAD_COLOR);164Mat mask = imread(original_path2, IMREAD_COLOR);165166ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;167ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;168169Mat result;170colorChange(source, mask, result, 1.5, .5, .5);171172SAVE(result);173174Mat reference = imread(reference_path);175ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;176177double errorINF = cvtest::norm(reference, result, NORM_INF);178EXPECT_LE(errorINF, 1);179double errorL1 = cvtest::norm(reference, result, NORM_L1);180EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();181}182183TEST(Photo_SeamlessClone_illuminationChange, regression)184{185string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Illumination_Change/";186string original_path1 = folder + "source1.png";187string original_path2 = folder + "mask.png";188string reference_path = folder + "reference.png";189190Mat source = imread(original_path1, IMREAD_COLOR);191Mat mask = imread(original_path2, IMREAD_COLOR);192193ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;194ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;195196Mat result;197illuminationChange(source, mask, result, 0.2f, 0.4f);198199SAVE(result);200201Mat reference = imread(reference_path);202ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;203204double errorINF = cvtest::norm(reference, result, NORM_INF);205EXPECT_LE(errorINF, 1);206double errorL1 = cvtest::norm(reference, result, NORM_L1);207EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();208}209210TEST(Photo_SeamlessClone_textureFlattening, regression)211{212string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Texture_Flattening/";213string original_path1 = folder + "source1.png";214string original_path2 = folder + "mask.png";215string reference_path = folder + "reference.png";216217Mat source = imread(original_path1, IMREAD_COLOR);218Mat mask = imread(original_path2, IMREAD_COLOR);219220ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;221ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;222223Mat result;224textureFlattening(source, mask, result, 30, 45, 3);225226SAVE(result);227228Mat reference = imread(reference_path);229ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;230231double errorINF = cvtest::norm(reference, result, NORM_INF);232EXPECT_LE(errorINF, 1);233double errorL1 = cvtest::norm(reference, result, NORM_L1);234EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();235}236237}} // namespace238239240