1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
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.
18 // Nathan, liujun@multicorewareinc.com
20 // Redistribution and use in source and binary forms, with or without modification,
21 // are permitted provided that the following conditions are met:
23 // * Redistribution's of source code must retain the above copyright notice,
24 // this list of conditions and the following disclaimer.
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.
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.
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.
46 #include "test_precomp.hpp"
48 #include "opencv2/ts/ocl_test.hpp"
55 PARAM_TEST_CASE(AccumulateBase, std::pair<MatDepth, MatDepth>, Channels, bool)
57 int sdepth, ddepth, channels;
61 TEST_DECLARE_INPUT_PARAMETER(src);
62 TEST_DECLARE_INPUT_PARAMETER(mask);
63 TEST_DECLARE_INPUT_PARAMETER(src2);
64 TEST_DECLARE_OUTPUT_PARAMETER(dst);
68 const std::pair<MatDepth, MatDepth> depths = GET_PARAM(0);
69 sdepth = depths.first, ddepth = depths.second;
70 channels = GET_PARAM(1);
71 useRoi = GET_PARAM(2);
76 const int stype = CV_MAKE_TYPE(sdepth, channels),
77 dtype = CV_MAKE_TYPE(ddepth, channels);
79 Size roiSize = randomSize(1, 10);
80 Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
81 randomSubMat(src, src_roi, roiSize, srcBorder, stype, -MAX_VALUE, MAX_VALUE);
83 Border maskBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
84 randomSubMat(mask, mask_roi, roiSize, maskBorder, CV_8UC1, -MAX_VALUE, MAX_VALUE);
85 threshold(mask, mask, 80, 255, THRESH_BINARY);
87 Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
88 randomSubMat(src2, src2_roi, roiSize, src2Border, stype, -MAX_VALUE, MAX_VALUE);
90 Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
91 randomSubMat(dst, dst_roi, roiSize, dstBorder, dtype, -MAX_VALUE, MAX_VALUE);
93 UMAT_UPLOAD_INPUT_PARAMETER(src);
94 UMAT_UPLOAD_INPUT_PARAMETER(mask);
95 UMAT_UPLOAD_INPUT_PARAMETER(src2);
96 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
98 alpha = randomDouble(-5, 5);
102 /////////////////////////////////// Accumulate ///////////////////////////////////
104 typedef AccumulateBase Accumulate;
106 OCL_TEST_P(Accumulate, Mat)
108 for (int i = 0; i < test_loop_times; ++i)
112 OCL_OFF(cv::accumulate(src_roi, dst_roi));
113 OCL_ON(cv::accumulate(usrc_roi, udst_roi));
115 OCL_EXPECT_MATS_NEAR(dst, 1e-6);
119 OCL_TEST_P(Accumulate, Mask)
121 for (int i = 0; i < test_loop_times; ++i)
125 OCL_OFF(cv::accumulate(src_roi, dst_roi, mask_roi));
126 OCL_ON(cv::accumulate(usrc_roi, udst_roi, umask_roi));
128 OCL_EXPECT_MATS_NEAR(dst, 1e-6);
132 /////////////////////////////////// AccumulateSquare ///////////////////////////////////
134 typedef AccumulateBase AccumulateSquare;
136 OCL_TEST_P(AccumulateSquare, Mat)
138 for (int i = 0; i < test_loop_times; ++i)
142 OCL_OFF(cv::accumulateSquare(src_roi, dst_roi));
143 OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi));
145 OCL_EXPECT_MATS_NEAR(dst, 1e-2);
149 OCL_TEST_P(AccumulateSquare, Mask)
151 for (int i = 0; i < test_loop_times; ++i)
155 OCL_OFF(cv::accumulateSquare(src_roi, dst_roi, mask_roi));
156 OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi, umask_roi));
158 OCL_EXPECT_MATS_NEAR(dst, 1e-2);
162 /////////////////////////////////// AccumulateProduct ///////////////////////////////////
164 typedef AccumulateBase AccumulateProduct;
166 OCL_TEST_P(AccumulateProduct, Mat)
168 for (int i = 0; i < test_loop_times; ++i)
172 OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi));
173 OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi));
175 OCL_EXPECT_MATS_NEAR(dst, 1e-2);
179 OCL_TEST_P(AccumulateProduct, Mask)
181 for (int i = 0; i < test_loop_times; ++i)
185 OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi, mask_roi));
186 OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi, umask_roi));
188 OCL_EXPECT_MATS_NEAR(dst, 1e-2);
192 /////////////////////////////////// AccumulateWeighted ///////////////////////////////////
194 typedef AccumulateBase AccumulateWeighted;
196 OCL_TEST_P(AccumulateWeighted, Mat)
198 for (int i = 0; i < test_loop_times; ++i)
202 OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
203 OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
205 OCL_EXPECT_MATS_NEAR(dst, 1e-2);
209 OCL_TEST_P(AccumulateWeighted, Mask)
211 for (int i = 0; i < test_loop_times; ++i)
215 OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
216 OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
218 OCL_EXPECT_MATS_NEAR(dst, 1e-2);
222 /////////////////////////////////// Instantiation ///////////////////////////////////
224 #define OCL_DEPTH_ALL_COMBINATIONS \
225 testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F), \
226 std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F), \
227 std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F), \
228 std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F), \
229 std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F), \
230 std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F), \
231 std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F))
233 OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Accumulate, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
234 OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateSquare, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
235 OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateProduct, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
236 OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateWeighted, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
238 } } // namespace cvtest::ocl