Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/stitching/test/ocl/test_warpers.cpp
16348 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) 2010-2013, Advanced Micro Devices, Inc., 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 OpenCV Foundation 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
#include "opencv2/ts/ocl_test.hpp"
44
#include "opencv2/stitching/warpers.hpp"
45
46
#ifdef HAVE_OPENCL
47
48
namespace opencv_test {
49
namespace ocl {
50
51
struct WarperTestBase :
52
public Test, public TestUtils
53
{
54
Mat src, dst, xmap, ymap;
55
UMat usrc, udst, uxmap, uymap;
56
Mat K, R;
57
58
void generateTestData()
59
{
60
Size size = randomSize(1, MAX_VALUE);
61
62
src = randomMat(size, CV_32FC1, -500, 500);
63
src.copyTo(usrc);
64
65
K = Mat::eye(3, 3, CV_32FC1);
66
float angle = (float)(30.0 * CV_PI / 180.0);
67
float rotationMatrix[9] = {
68
(float)cos(angle), (float)sin(angle), 0,
69
(float)-sin(angle), (float)cos(angle), 0,
70
0, 0, 1
71
};
72
Mat(3, 3, CV_32FC1, rotationMatrix).copyTo(R);
73
}
74
75
void Near(double threshold = 0.)
76
{
77
EXPECT_MAT_NEAR(xmap, uxmap, threshold);
78
EXPECT_MAT_NEAR(ymap, uymap, threshold);
79
EXPECT_MAT_NEAR(dst, udst, threshold);
80
}
81
};
82
83
typedef WarperTestBase SphericalWarperTest;
84
85
OCL_TEST_F(SphericalWarperTest, Mat)
86
{
87
for (int j = 0; j < test_loop_times; j++)
88
{
89
generateTestData();
90
91
Ptr<WarperCreator> creator = makePtr<SphericalWarper>();
92
Ptr<detail::RotationWarper> warper = creator->create(2.0);
93
94
OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));
95
OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));
96
97
OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));
98
OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));
99
100
Near(1e-4);
101
}
102
}
103
104
typedef WarperTestBase CylindricalWarperTest;
105
106
OCL_TEST_F(CylindricalWarperTest, Mat)
107
{
108
for (int j = 0; j < test_loop_times; j++)
109
{
110
generateTestData();
111
112
Ptr<WarperCreator> creator = makePtr<CylindricalWarper>();
113
Ptr<detail::RotationWarper> warper = creator->create(2.0);
114
115
OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));
116
OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));
117
118
OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));
119
OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));
120
121
Near(1e-4);
122
}
123
}
124
125
typedef WarperTestBase PlaneWarperTest;
126
127
OCL_TEST_F(PlaneWarperTest, Mat)
128
{
129
for (int j = 0; j < test_loop_times; j++)
130
{
131
generateTestData();
132
133
Ptr<WarperCreator> creator = makePtr<PlaneWarper>();
134
Ptr<detail::RotationWarper> warper = creator->create(2.0);
135
136
OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));
137
OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));
138
139
OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));
140
OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));
141
142
Near(1.5e-4);
143
}
144
}
145
146
typedef WarperTestBase AffineWarperTest;
147
148
OCL_TEST_F(AffineWarperTest, Mat)
149
{
150
for (int j = 0; j < test_loop_times; j++)
151
{
152
generateTestData();
153
154
Ptr<WarperCreator> creator = makePtr<AffineWarper>();
155
Ptr<detail::RotationWarper> warper = creator->create(1.0);
156
157
OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));
158
OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));
159
160
OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));
161
OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));
162
163
Near(1.5e-4);
164
}
165
}
166
167
} } // namespace opencv_test::ocl
168
169
#endif // HAVE_OPENCL
170
171