Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/core/test/ocl/test_dft.cpp
16339 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-2012, Multicoreware, Inc., all rights reserved.
14
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// @Authors
18
// Peng Xiao, [email protected]
19
//
20
// Redistribution and use in source and binary forms, with or without modification,
21
// are permitted provided that the following conditions are met:
22
//
23
// * Redistribution's of source code must retain the above copyright notice,
24
// this list of conditions and the following disclaimer.
25
//
26
// * Redistribution's in binary form must reproduce the above copyright notice,
27
// this list of conditions and the following disclaimer in the documentation
28
// and/or other materials provided with the distribution.
29
//
30
// * The name of the copyright holders may not be used to endorse or promote products
31
// derived from this software without specific prior written permission.
32
//
33
// This software is provided by the copyright holders and contributors as is and
34
// any express or implied warranties, including, but not limited to, the implied
35
// warranties of merchantability and fitness for a particular purpose are disclaimed.
36
// In no event shall the Intel Corporation or contributors be liable for any direct,
37
// indirect, incidental, special, exemplary, or consequential damages
38
// (including, but not limited to, procurement of substitute goods or services;
39
// loss of use, data, or profits; or business interruption) however caused
40
// and on any theory of liability, whether in contract, strict liability,
41
// or tort (including negligence or otherwise) arising in any way out of
42
// the use of this software, even if advised of the possibility of such damage.
43
//
44
//M*/
45
46
#include "../test_precomp.hpp"
47
#include "opencv2/ts/ocl_test.hpp"
48
49
#ifdef HAVE_OPENCL
50
51
enum OCL_FFT_TYPE
52
{
53
R2R = 0,
54
C2R = 1,
55
R2C = 2,
56
C2C = 3
57
};
58
59
namespace opencv_test {
60
namespace ocl {
61
62
////////////////////////////////////////////////////////////////////////////
63
// Dft
64
65
PARAM_TEST_CASE(Dft, cv::Size, OCL_FFT_TYPE, MatDepth, bool, bool, bool, bool)
66
{
67
cv::Size dft_size;
68
int dft_flags, depth, cn, dft_type;
69
bool hint;
70
bool is1d;
71
72
TEST_DECLARE_INPUT_PARAMETER(src);
73
TEST_DECLARE_OUTPUT_PARAMETER(dst);
74
75
virtual void SetUp()
76
{
77
dft_size = GET_PARAM(0);
78
dft_type = GET_PARAM(1);
79
depth = GET_PARAM(2);
80
81
dft_flags = 0;
82
switch (dft_type)
83
{
84
case R2R: dft_flags |= cv::DFT_REAL_OUTPUT; cn = 1; break;
85
case C2R: dft_flags |= cv::DFT_REAL_OUTPUT; cn = 2; break;
86
case R2C: dft_flags |= cv::DFT_COMPLEX_OUTPUT; cn = 1; break;
87
case C2C: dft_flags |= cv::DFT_COMPLEX_OUTPUT; cn = 2; break;
88
}
89
90
if (GET_PARAM(3))
91
dft_flags |= cv::DFT_INVERSE;
92
if (GET_PARAM(4))
93
dft_flags |= cv::DFT_ROWS;
94
if (GET_PARAM(5))
95
dft_flags |= cv::DFT_SCALE;
96
hint = GET_PARAM(6);
97
is1d = (dft_flags & DFT_ROWS) != 0 || dft_size.height == 1;
98
}
99
100
void generateTestData()
101
{
102
src = randomMat(dft_size, CV_MAKE_TYPE(depth, cn), 0.0, 100.0);
103
usrc = src.getUMat(ACCESS_READ);
104
}
105
};
106
107
OCL_TEST_P(Dft, Mat)
108
{
109
generateTestData();
110
111
int nonzero_rows = hint ? src.rows - randomInt(1, src.rows-1) : 0;
112
OCL_OFF(cv::dft(src, dst, dft_flags, nonzero_rows));
113
OCL_ON(cv::dft(usrc, udst, dft_flags, nonzero_rows));
114
115
// In case forward R2C 1d transform dst contains only half of output
116
// without complex conjugate
117
if (dft_type == R2C && is1d && (dft_flags & cv::DFT_INVERSE) == 0)
118
{
119
dst = dst(cv::Range(0, dst.rows), cv::Range(0, dst.cols/2 + 1));
120
udst = udst(cv::Range(0, udst.rows), cv::Range(0, udst.cols/2 + 1));
121
}
122
123
double eps = src.size().area() * 1e-4;
124
EXPECT_MAT_NEAR(dst, udst, eps);
125
}
126
127
////////////////////////////////////////////////////////////////////////////
128
// MulSpectrums
129
130
PARAM_TEST_CASE(MulSpectrums, bool, bool)
131
{
132
bool ccorr, useRoi;
133
134
TEST_DECLARE_INPUT_PARAMETER(src1);
135
TEST_DECLARE_INPUT_PARAMETER(src2);
136
TEST_DECLARE_OUTPUT_PARAMETER(dst);
137
138
virtual void SetUp()
139
{
140
ccorr = GET_PARAM(0);
141
useRoi = GET_PARAM(1);
142
}
143
144
void generateTestData()
145
{
146
Size srcRoiSize = randomSize(1, MAX_VALUE);
147
Border src1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
148
randomSubMat(src1, src1_roi, srcRoiSize, src1Border, CV_32FC2, -11, 11);
149
150
151
Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
152
randomSubMat(src2, src2_roi, srcRoiSize, src2Border, CV_32FC2, -11, 11);
153
154
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
155
randomSubMat(dst, dst_roi, srcRoiSize, dstBorder, CV_32FC2, 5, 16);
156
157
UMAT_UPLOAD_INPUT_PARAMETER(src1);
158
UMAT_UPLOAD_INPUT_PARAMETER(src2);
159
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
160
}
161
};
162
163
OCL_TEST_P(MulSpectrums, Mat)
164
{
165
for (int i = 0; i < test_loop_times; ++i)
166
{
167
generateTestData();
168
169
OCL_OFF(cv::mulSpectrums(src1_roi, src2_roi, dst_roi, 0, ccorr));
170
OCL_ON(cv::mulSpectrums(usrc1_roi, usrc2_roi, udst_roi, 0, ccorr));
171
172
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, 1e-6);
173
}
174
}
175
176
OCL_INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MulSpectrums, testing::Combine(Bool(), Bool()));
177
178
OCL_INSTANTIATE_TEST_CASE_P(Core, Dft, Combine(Values(cv::Size(45, 72), cv::Size(36, 36), cv::Size(512, 1), cv::Size(1280, 768)),
179
Values((OCL_FFT_TYPE) R2C, (OCL_FFT_TYPE) C2C, (OCL_FFT_TYPE) R2R, (OCL_FFT_TYPE) C2R),
180
Values(CV_32F, CV_64F),
181
Bool(), // DFT_INVERSE
182
Bool(), // DFT_ROWS
183
Bool(), // DFT_SCALE
184
Bool() // hint
185
)
186
);
187
188
} } // namespace opencv_test::ocl
189
190
#endif // HAVE_OPENCL
191