Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/test/ocl/test_accumulate.cpp
16344 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
// Nathan, [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
namespace opencv_test {
52
namespace ocl {
53
54
PARAM_TEST_CASE(AccumulateBase, std::pair<MatDepth, MatDepth>, Channels, bool)
55
{
56
int sdepth, ddepth, channels;
57
bool useRoi;
58
double alpha;
59
60
TEST_DECLARE_INPUT_PARAMETER(src);
61
TEST_DECLARE_INPUT_PARAMETER(mask);
62
TEST_DECLARE_INPUT_PARAMETER(src2);
63
TEST_DECLARE_OUTPUT_PARAMETER(dst);
64
65
virtual void SetUp()
66
{
67
const std::pair<MatDepth, MatDepth> depths = GET_PARAM(0);
68
sdepth = depths.first, ddepth = depths.second;
69
channels = GET_PARAM(1);
70
useRoi = GET_PARAM(2);
71
}
72
73
void random_roi()
74
{
75
const int stype = CV_MAKE_TYPE(sdepth, channels),
76
dtype = CV_MAKE_TYPE(ddepth, channels);
77
78
Size roiSize = randomSize(1, 10);
79
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
80
randomSubMat(src, src_roi, roiSize, srcBorder, stype, -MAX_VALUE, MAX_VALUE);
81
82
Border maskBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
83
randomSubMat(mask, mask_roi, roiSize, maskBorder, CV_8UC1, -MAX_VALUE, MAX_VALUE);
84
cvtest::threshold(mask, mask, 80, 255, THRESH_BINARY);
85
86
Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
87
randomSubMat(src2, src2_roi, roiSize, src2Border, stype, -MAX_VALUE, MAX_VALUE);
88
89
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
90
randomSubMat(dst, dst_roi, roiSize, dstBorder, dtype, -MAX_VALUE, MAX_VALUE);
91
92
UMAT_UPLOAD_INPUT_PARAMETER(src);
93
UMAT_UPLOAD_INPUT_PARAMETER(mask);
94
UMAT_UPLOAD_INPUT_PARAMETER(src2);
95
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
96
97
alpha = randomDouble(-5, 5);
98
}
99
};
100
101
/////////////////////////////////// Accumulate ///////////////////////////////////
102
103
typedef AccumulateBase Accumulate;
104
105
OCL_TEST_P(Accumulate, Mat)
106
{
107
for (int i = 0; i < test_loop_times; ++i)
108
{
109
random_roi();
110
111
OCL_OFF(cv::accumulate(src_roi, dst_roi));
112
OCL_ON(cv::accumulate(usrc_roi, udst_roi));
113
114
OCL_EXPECT_MATS_NEAR(dst, 1e-6);
115
}
116
}
117
118
OCL_TEST_P(Accumulate, Mask)
119
{
120
for (int i = 0; i < test_loop_times; ++i)
121
{
122
random_roi();
123
124
OCL_OFF(cv::accumulate(src_roi, dst_roi, mask_roi));
125
OCL_ON(cv::accumulate(usrc_roi, udst_roi, umask_roi));
126
127
OCL_EXPECT_MATS_NEAR(dst, 1e-6);
128
}
129
}
130
131
/////////////////////////////////// AccumulateSquare ///////////////////////////////////
132
133
typedef AccumulateBase AccumulateSquare;
134
135
OCL_TEST_P(AccumulateSquare, Mat)
136
{
137
for (int i = 0; i < test_loop_times; ++i)
138
{
139
random_roi();
140
141
OCL_OFF(cv::accumulateSquare(src_roi, dst_roi));
142
OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi));
143
144
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
145
}
146
}
147
148
OCL_TEST_P(AccumulateSquare, Mask)
149
{
150
for (int i = 0; i < test_loop_times; ++i)
151
{
152
random_roi();
153
154
OCL_OFF(cv::accumulateSquare(src_roi, dst_roi, mask_roi));
155
OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi, umask_roi));
156
157
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
158
}
159
}
160
161
/////////////////////////////////// AccumulateProduct ///////////////////////////////////
162
163
typedef AccumulateBase AccumulateProduct;
164
165
OCL_TEST_P(AccumulateProduct, Mat)
166
{
167
for (int i = 0; i < test_loop_times; ++i)
168
{
169
random_roi();
170
171
OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi));
172
OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi));
173
174
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
175
}
176
}
177
178
OCL_TEST_P(AccumulateProduct, Mask)
179
{
180
for (int i = 0; i < test_loop_times; ++i)
181
{
182
random_roi();
183
184
OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi, mask_roi));
185
OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi, umask_roi));
186
187
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
188
}
189
}
190
191
/////////////////////////////////// AccumulateWeighted ///////////////////////////////////
192
193
typedef AccumulateBase AccumulateWeighted;
194
195
OCL_TEST_P(AccumulateWeighted, Mat)
196
{
197
for (int i = 0; i < test_loop_times; ++i)
198
{
199
random_roi();
200
201
OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
202
OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
203
204
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
205
}
206
}
207
208
OCL_TEST_P(AccumulateWeighted, Mask)
209
{
210
for (int i = 0; i < test_loop_times; ++i)
211
{
212
random_roi();
213
214
OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
215
OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
216
217
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
218
}
219
}
220
221
/////////////////////////////////// Instantiation ///////////////////////////////////
222
223
#define OCL_DEPTH_ALL_COMBINATIONS \
224
testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F), \
225
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F), \
226
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F), \
227
std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F), \
228
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F), \
229
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F), \
230
std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F))
231
232
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Accumulate, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
233
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateSquare, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
234
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateProduct, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
235
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateWeighted, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
236
237
} } // namespace opencv_test::ocl
238
239
#endif
240
241