Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/photo/test/test_inpaint.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) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
19
//
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
22
//
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
26
//
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
29
//
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
40
//
41
//M*/
42
43
#include "test_precomp.hpp"
44
45
namespace opencv_test { namespace {
46
47
class CV_InpaintTest : public cvtest::BaseTest
48
{
49
public:
50
CV_InpaintTest();
51
~CV_InpaintTest();
52
protected:
53
void run(int);
54
};
55
56
CV_InpaintTest::CV_InpaintTest()
57
{
58
}
59
CV_InpaintTest::~CV_InpaintTest() {}
60
61
void CV_InpaintTest::run( int )
62
{
63
string folder = string(ts->get_data_path()) + "inpaint/";
64
Mat orig = imread(folder + "orig.png");
65
Mat exp1 = imread(folder + "exp1.png");
66
Mat exp2 = imread(folder + "exp2.png");
67
Mat mask = imread(folder + "mask.png");
68
69
if (orig.empty() || exp1.empty() || exp2.empty() || mask.empty())
70
{
71
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
72
return;
73
}
74
75
Mat inv_mask;
76
mask.convertTo(inv_mask, CV_8UC3, -1.0, 255.0);
77
78
Mat mask1ch;
79
cv::cvtColor(mask, mask1ch, COLOR_BGR2GRAY);
80
81
Mat test = orig.clone();
82
test.setTo(Scalar::all(255), mask1ch);
83
84
Mat res1, res2;
85
inpaint( test, mask1ch, res1, 5, INPAINT_NS );
86
inpaint( test, mask1ch, res2, 5, INPAINT_TELEA );
87
88
Mat diff1, diff2;
89
absdiff( orig, res1, diff1 );
90
absdiff( orig, res2, diff2 );
91
92
double n1 = cvtest::norm(diff1.reshape(1), NORM_INF, inv_mask.reshape(1));
93
double n2 = cvtest::norm(diff2.reshape(1), NORM_INF, inv_mask.reshape(1));
94
95
if (n1 != 0 || n2 != 0)
96
{
97
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH );
98
return;
99
}
100
101
absdiff( exp1, res1, diff1 );
102
absdiff( exp2, res2, diff2 );
103
104
n1 = cvtest::norm(diff1.reshape(1), NORM_INF, mask.reshape(1));
105
n2 = cvtest::norm(diff2.reshape(1), NORM_INF, mask.reshape(1));
106
107
const int jpeg_thres = 3;
108
if (n1 > jpeg_thres || n2 > jpeg_thres)
109
{
110
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
111
return;
112
}
113
114
ts->set_failed_test_info(cvtest::TS::OK);
115
}
116
117
TEST(Photo_Inpaint, regression) { CV_InpaintTest test; test.safe_run(); }
118
119
typedef testing::TestWithParam<tuple<int> > formats;
120
121
TEST_P(formats, 1c)
122
{
123
const int type = get<0>(GetParam());
124
Mat src(100, 100, type);
125
src.setTo(Scalar::all(128));
126
Mat ref = src.clone();
127
Mat dst, mask = Mat::zeros(src.size(), CV_8U);
128
129
circle(src, Point(50, 50), 5, Scalar(200), 6);
130
circle(mask, Point(50, 50), 5, Scalar(200), 6);
131
inpaint(src, mask, dst, 10, INPAINT_NS);
132
133
Mat dst2;
134
inpaint(src, mask, dst2, 10, INPAINT_TELEA);
135
136
ASSERT_LE(cv::norm(dst, ref, NORM_INF), 3.);
137
ASSERT_LE(cv::norm(dst2, ref, NORM_INF), 3.);
138
}
139
140
INSTANTIATE_TEST_CASE_P(Photo_Inpaint, formats, testing::Values(CV_32F, CV_16U, CV_8U));
141
142
}} // namespace
143
144