Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/photo/test/test_cloning.cpp
16337 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of the copyright holders may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#include "test_precomp.hpp"
43
44
namespace opencv_test { namespace {
45
46
#define OUTPUT_SAVING 0
47
#if OUTPUT_SAVING
48
#define SAVE(x) std::vector<int> params;\
49
params.push_back(16);\
50
params.push_back(0);\
51
imwrite(folder + "output.png", x ,params);
52
#else
53
#define SAVE(x)
54
#endif
55
56
static const double numerical_precision = 0.05; // 95% of pixels should have exact values
57
58
TEST(Photo_SeamlessClone_normal, regression)
59
{
60
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Normal_Cloning/";
61
string original_path1 = folder + "source1.png";
62
string original_path2 = folder + "destination1.png";
63
string original_path3 = folder + "mask.png";
64
string reference_path = folder + "reference.png";
65
66
Mat source = imread(original_path1, IMREAD_COLOR);
67
Mat destination = imread(original_path2, IMREAD_COLOR);
68
Mat mask = imread(original_path3, IMREAD_COLOR);
69
70
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
71
ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;
72
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;
73
74
Mat result;
75
Point p;
76
p.x = destination.size().width/2;
77
p.y = destination.size().height/2;
78
seamlessClone(source, destination, mask, p, result, 1);
79
80
Mat reference = imread(reference_path);
81
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
82
83
SAVE(result);
84
85
double errorINF = cvtest::norm(reference, result, NORM_INF);
86
EXPECT_LE(errorINF, 1);
87
double errorL1 = cvtest::norm(reference, result, NORM_L1);
88
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
89
}
90
91
TEST(Photo_SeamlessClone_mixed, regression)
92
{
93
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Mixed_Cloning/";
94
string original_path1 = folder + "source1.png";
95
string original_path2 = folder + "destination1.png";
96
string original_path3 = folder + "mask.png";
97
string reference_path = folder + "reference.png";
98
99
Mat source = imread(original_path1, IMREAD_COLOR);
100
Mat destination = imread(original_path2, IMREAD_COLOR);
101
Mat mask = imread(original_path3, IMREAD_COLOR);
102
103
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
104
ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;
105
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;
106
107
Mat result;
108
Point p;
109
p.x = destination.size().width/2;
110
p.y = destination.size().height/2;
111
seamlessClone(source, destination, mask, p, result, 2);
112
113
SAVE(result);
114
115
Mat reference = imread(reference_path);
116
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
117
118
double errorINF = cvtest::norm(reference, result, NORM_INF);
119
EXPECT_LE(errorINF, 1);
120
double errorL1 = cvtest::norm(reference, result, NORM_L1);
121
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
122
}
123
124
TEST(Photo_SeamlessClone_featureExchange, regression)
125
{
126
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Monochrome_Transfer/";
127
string original_path1 = folder + "source1.png";
128
string original_path2 = folder + "destination1.png";
129
string original_path3 = folder + "mask.png";
130
string reference_path = folder + "reference.png";
131
132
Mat source = imread(original_path1, IMREAD_COLOR);
133
Mat destination = imread(original_path2, IMREAD_COLOR);
134
Mat mask = imread(original_path3, IMREAD_COLOR);
135
136
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
137
ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;
138
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;
139
140
Mat result;
141
Point p;
142
p.x = destination.size().width/2;
143
p.y = destination.size().height/2;
144
seamlessClone(source, destination, mask, p, result, 3);
145
146
SAVE(result);
147
148
Mat reference = imread(reference_path);
149
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
150
151
double errorINF = cvtest::norm(reference, result, NORM_INF);
152
EXPECT_LE(errorINF, 1);
153
double errorL1 = cvtest::norm(reference, result, NORM_L1);
154
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
155
}
156
157
TEST(Photo_SeamlessClone_colorChange, regression)
158
{
159
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/color_change/";
160
string original_path1 = folder + "source1.png";
161
string original_path2 = folder + "mask.png";
162
string reference_path = folder + "reference.png";
163
164
Mat source = imread(original_path1, IMREAD_COLOR);
165
Mat mask = imread(original_path2, IMREAD_COLOR);
166
167
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
168
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;
169
170
Mat result;
171
colorChange(source, mask, result, 1.5, .5, .5);
172
173
SAVE(result);
174
175
Mat reference = imread(reference_path);
176
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
177
178
double errorINF = cvtest::norm(reference, result, NORM_INF);
179
EXPECT_LE(errorINF, 1);
180
double errorL1 = cvtest::norm(reference, result, NORM_L1);
181
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
182
}
183
184
TEST(Photo_SeamlessClone_illuminationChange, regression)
185
{
186
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Illumination_Change/";
187
string original_path1 = folder + "source1.png";
188
string original_path2 = folder + "mask.png";
189
string reference_path = folder + "reference.png";
190
191
Mat source = imread(original_path1, IMREAD_COLOR);
192
Mat mask = imread(original_path2, IMREAD_COLOR);
193
194
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
195
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;
196
197
Mat result;
198
illuminationChange(source, mask, result, 0.2f, 0.4f);
199
200
SAVE(result);
201
202
Mat reference = imread(reference_path);
203
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
204
205
double errorINF = cvtest::norm(reference, result, NORM_INF);
206
EXPECT_LE(errorINF, 1);
207
double errorL1 = cvtest::norm(reference, result, NORM_L1);
208
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
209
}
210
211
TEST(Photo_SeamlessClone_textureFlattening, regression)
212
{
213
string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Texture_Flattening/";
214
string original_path1 = folder + "source1.png";
215
string original_path2 = folder + "mask.png";
216
string reference_path = folder + "reference.png";
217
218
Mat source = imread(original_path1, IMREAD_COLOR);
219
Mat mask = imread(original_path2, IMREAD_COLOR);
220
221
ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
222
ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;
223
224
Mat result;
225
textureFlattening(source, mask, result, 30, 45, 3);
226
227
SAVE(result);
228
229
Mat reference = imread(reference_path);
230
ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
231
232
double errorINF = cvtest::norm(reference, result, NORM_INF);
233
EXPECT_LE(errorINF, 1);
234
double errorL1 = cvtest::norm(reference, result, NORM_L1);
235
EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
236
}
237
238
}} // namespace
239
240