Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/superres/perf/perf_superres.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 "perf_precomp.hpp"
44
#include "opencv2/ts/ocl_perf.hpp"
45
46
namespace opencv_test
47
{
48
using namespace perf;
49
using namespace cv::superres;
50
using namespace cv::cuda;
51
52
namespace
53
{
54
class OneFrameSource_CPU : public FrameSource
55
{
56
public:
57
explicit OneFrameSource_CPU(const Mat& frame) : frame_(frame) {}
58
59
void nextFrame(OutputArray frame)
60
{
61
frame.getMatRef() = frame_;
62
}
63
64
void reset()
65
{
66
}
67
68
private:
69
Mat frame_;
70
};
71
72
class OneFrameSource_CUDA : public FrameSource
73
{
74
public:
75
explicit OneFrameSource_CUDA(const GpuMat& frame) : frame_(frame) {}
76
77
void nextFrame(OutputArray frame)
78
{
79
frame.getGpuMatRef() = frame_;
80
}
81
82
void reset()
83
{
84
}
85
86
private:
87
GpuMat frame_;
88
};
89
90
class ZeroOpticalFlow : public DenseOpticalFlowExt
91
{
92
public:
93
virtual void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
94
{
95
cv::Size size = frame0.size();
96
97
if (!flow2.needed())
98
{
99
flow1.create(size, CV_32FC2);
100
flow1.setTo(cv::Scalar::all(0));
101
}
102
else
103
{
104
flow1.create(size, CV_32FC1);
105
flow2.create(size, CV_32FC1);
106
107
flow1.setTo(cv::Scalar::all(0));
108
flow2.setTo(cv::Scalar::all(0));
109
}
110
}
111
112
virtual void collectGarbage()
113
{
114
}
115
};
116
} // namespace
117
118
PERF_TEST_P(Size_MatType, SuperResolution_BTVL1,
119
Combine(Values(szSmall64, szSmall128),
120
Values(MatType(CV_8UC1), MatType(CV_8UC3))))
121
{
122
declare.time(5 * 60);
123
124
const Size size = get<0>(GetParam());
125
const int type = get<1>(GetParam());
126
127
Mat frame(size, type);
128
declare.in(frame, WARMUP_RNG);
129
130
const int scale = 2;
131
const int iterations = 50;
132
const int temporalAreaRadius = 1;
133
Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);
134
135
if (PERF_RUN_CUDA())
136
{
137
Ptr<SuperResolution> superRes = createSuperResolution_BTVL1_CUDA();
138
139
superRes->setScale(scale);
140
superRes->setIterations(iterations);
141
superRes->setTemporalAreaRadius(temporalAreaRadius);
142
superRes->setOpticalFlow(opticalFlow);
143
144
superRes->setInput(makePtr<OneFrameSource_CUDA>(GpuMat(frame)));
145
146
GpuMat dst;
147
superRes->nextFrame(dst);
148
149
TEST_CYCLE_N(10) superRes->nextFrame(dst);
150
151
CUDA_SANITY_CHECK(dst, 2);
152
}
153
else
154
{
155
Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();
156
157
superRes->setScale(scale);
158
superRes->setIterations(iterations);
159
superRes->setTemporalAreaRadius(temporalAreaRadius);
160
superRes->setOpticalFlow(opticalFlow);
161
162
superRes->setInput(makePtr<OneFrameSource_CPU>(frame));
163
164
Mat dst;
165
superRes->nextFrame(dst);
166
167
TEST_CYCLE_N(10) superRes->nextFrame(dst);
168
169
CPU_SANITY_CHECK(dst);
170
}
171
}
172
173
#ifdef HAVE_OPENCL
174
175
namespace ocl {
176
177
typedef Size_MatType SuperResolution_BTVL1;
178
179
OCL_PERF_TEST_P(SuperResolution_BTVL1 ,BTVL1,
180
Combine(Values(szSmall64, szSmall128),
181
Values(MatType(CV_8UC1), MatType(CV_8UC3))))
182
{
183
Size_MatType_t params = GetParam();
184
const Size size = get<0>(params);
185
const int type = get<1>(params);
186
187
Mat frame(size, type);
188
UMat dst(1, 1, 0);
189
declare.in(frame, WARMUP_RNG);
190
191
const int scale = 2;
192
const int iterations = 50;
193
const int temporalAreaRadius = 1;
194
195
Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);
196
Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();
197
198
superRes->setScale(scale);
199
superRes->setIterations(iterations);
200
superRes->setTemporalAreaRadius(temporalAreaRadius);
201
superRes->setOpticalFlow(opticalFlow);
202
203
superRes->setInput(makePtr<OneFrameSource_CPU>(frame));
204
205
// skip first frame
206
superRes->nextFrame(dst);
207
208
OCL_TEST_CYCLE_N(10) superRes->nextFrame(dst);
209
210
SANITY_CHECK_NOTHING();
211
}
212
213
} // namespace ocl
214
215
#endif // HAVE_OPENCL
216
217
} // namespace
218
219