Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/stitching/perf/opencl/perf_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 "../perf_precomp.hpp"
43
#include "opencv2/stitching/warpers.hpp"
44
#include "opencv2/ts/ocl_perf.hpp"
45
46
#ifdef HAVE_OPENCL
47
48
namespace opencv_test {
49
namespace ocl {
50
51
///////////////////////// Stitching Warpers ///////////////////////////
52
53
enum
54
{
55
SphericalWarperType = 0,
56
CylindricalWarperType = 1,
57
PlaneWarperType = 2,
58
AffineWarperType = 3,
59
};
60
61
class WarperBase
62
{
63
public:
64
explicit WarperBase(int type, Size srcSize)
65
{
66
Ptr<WarperCreator> creator;
67
if (type == SphericalWarperType)
68
creator = makePtr<SphericalWarper>();
69
else if (type == CylindricalWarperType)
70
creator = makePtr<CylindricalWarper>();
71
else if (type == PlaneWarperType)
72
creator = makePtr<PlaneWarper>();
73
else if (type == AffineWarperType)
74
creator = makePtr<AffineWarper>();
75
CV_Assert(!creator.empty());
76
77
K = Mat::eye(3, 3, CV_32FC1);
78
K.at<float>(0,0) = (float)srcSize.width;
79
K.at<float>(0,2) = (float)srcSize.width/2;
80
K.at<float>(1,1) = (float)srcSize.height;
81
K.at<float>(1,2) = (float)srcSize.height/2;
82
K.at<float>(2,2) = 1.0f;
83
R = Mat::eye(3, 3, CV_32FC1);
84
float scale = (float)srcSize.width;
85
86
warper = creator->create(scale);
87
}
88
89
Rect buildMaps(Size src_size, OutputArray xmap, OutputArray ymap) const
90
{
91
return warper->buildMaps(src_size, K, R, xmap, ymap);
92
}
93
94
Point warp(InputArray src, int interp_mode, int border_mode, OutputArray dst) const
95
{
96
return warper->warp(src, K, R, interp_mode, border_mode, dst);
97
}
98
99
private:
100
Ptr<detail::RotationWarper> warper;
101
Mat K, R;
102
};
103
104
CV_ENUM(WarperType, SphericalWarperType, CylindricalWarperType, PlaneWarperType, AffineWarperType)
105
106
typedef tuple<Size, WarperType> StitchingWarpersParams;
107
typedef TestBaseWithParam<StitchingWarpersParams> StitchingWarpersFixture;
108
109
static void prepareWarperSrc(InputOutputArray src, Size srcSize)
110
{
111
src.create(srcSize, CV_8UC1);
112
src.setTo(Scalar::all(64));
113
ellipse(src, Point(srcSize.width/2, srcSize.height/2), Size(srcSize.width/2, srcSize.height/2),
114
360, 0, 360, Scalar::all(255), 2);
115
ellipse(src, Point(srcSize.width/2, srcSize.height/2), Size(srcSize.width/3, srcSize.height/3),
116
360, 0, 360, Scalar::all(128), 2);
117
rectangle(src, Point(10, 10), Point(srcSize.width - 10, srcSize.height - 10), Scalar::all(128), 2);
118
}
119
120
OCL_PERF_TEST_P(StitchingWarpersFixture, StitchingWarpers_BuildMaps,
121
::testing::Combine(OCL_TEST_SIZES, WarperType::all()))
122
{
123
const StitchingWarpersParams params = GetParam();
124
const Size srcSize = get<0>(params);
125
const WarperBase warper(get<1>(params), srcSize);
126
127
UMat xmap, ymap;
128
129
OCL_TEST_CYCLE() warper.buildMaps(srcSize, xmap, ymap);
130
131
SANITY_CHECK(xmap, 1e-3);
132
SANITY_CHECK(ymap, 1e-3);
133
}
134
135
OCL_PERF_TEST_P(StitchingWarpersFixture, StitchingWarpers_Warp,
136
::testing::Combine(OCL_TEST_SIZES, WarperType::all()))
137
{
138
const StitchingWarpersParams params = GetParam();
139
const Size srcSize = get<0>(params);
140
const WarperBase warper(get<1>(params), srcSize);
141
142
UMat src, dst;
143
prepareWarperSrc(src, srcSize);
144
declare.in(src, WARMUP_READ);
145
146
OCL_TEST_CYCLE() warper.warp(src, INTER_LINEAR, BORDER_REPLICATE, dst);
147
148
#if 0
149
namedWindow("src", WINDOW_NORMAL);
150
namedWindow("dst", WINDOW_NORMAL);
151
imshow("src", src);
152
imshow("dst", dst);
153
std::cout << dst.size() << " " << dst.size().area() << std::endl;
154
cv::waitKey();
155
#endif
156
157
SANITY_CHECK(dst, 1e-5);
158
}
159
160
} } // namespace opencv_test::ocl
161
162
#endif // HAVE_OPENCL
163
164