• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, liujun@multicorewareinc.com
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 "cvconfig.h"
48 #include "opencv2/ts/ocl_test.hpp"
49 
50 #ifdef HAVE_OPENCL
51 
52 namespace cvtest {
53 namespace ocl {
54 
PARAM_TEST_CASE(BlendLinear,MatDepth,Channels,bool)55 PARAM_TEST_CASE(BlendLinear, MatDepth, Channels, bool)
56 {
57     int depth, channels;
58     bool useRoi;
59 
60     TEST_DECLARE_INPUT_PARAMETER(src1);
61     TEST_DECLARE_INPUT_PARAMETER(src2);
62     TEST_DECLARE_INPUT_PARAMETER(weights2);
63     TEST_DECLARE_INPUT_PARAMETER(weights1);
64     TEST_DECLARE_OUTPUT_PARAMETER(dst);
65 
66     virtual void SetUp()
67     {
68         depth = GET_PARAM(0);
69         channels = GET_PARAM(1);
70         useRoi = GET_PARAM(2);
71     }
72 
73     void random_roi()
74     {
75         const int type = CV_MAKE_TYPE(depth, channels);
76         const double upValue = 256;
77 
78         Size roiSize = randomSize(1, MAX_VALUE);
79         Border src1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
80         randomSubMat(src1, src1_roi, roiSize, src1Border, type, -upValue, upValue);
81 
82         Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
83         randomSubMat(src2, src2_roi, roiSize, src2Border, type, -upValue, upValue);
84 
85         Border weights1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
86         randomSubMat(weights1, weights1_roi, roiSize, weights1Border, CV_32FC1, -upValue, upValue);
87 
88         Border weights2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
89         randomSubMat(weights2, weights2_roi, roiSize, weights2Border, CV_32FC1, 1e-2, upValue);
90 
91         weights2_roi -= weights1_roi;
92         CV_Assert(checkNorm2(weights2_roi, weights2(Rect(weights2Border.lef, weights2Border.top,
93                                                         roiSize.width, roiSize.height))) < 1e-6);
94 
95         Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
96         randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);
97 
98         UMAT_UPLOAD_INPUT_PARAMETER(src1);
99         UMAT_UPLOAD_INPUT_PARAMETER(src2);
100         UMAT_UPLOAD_INPUT_PARAMETER(weights1);
101         UMAT_UPLOAD_INPUT_PARAMETER(weights2);
102         UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
103     }
104 
105     void Near(double eps = 0.0)
106     {
107         OCL_EXPECT_MATS_NEAR(dst, eps);
108     }
109 };
110 
OCL_TEST_P(BlendLinear,Accuracy)111 OCL_TEST_P(BlendLinear, Accuracy)
112 {
113     for (int i = 0; i < test_loop_times; ++i)
114     {
115         random_roi();
116 
117         OCL_OFF(cv::blendLinear(src1_roi, src2_roi, weights1_roi, weights2_roi, dst_roi));
118         OCL_ON(cv::blendLinear(usrc1_roi, usrc2_roi, uweights1_roi, uweights2_roi, udst_roi));
119 
120         Near(depth <= CV_32S ? 1.0 : 0.5);
121     }
122 }
123 
124 OCL_INSTANTIATE_TEST_CASE_P(ImgProc, BlendLinear, Combine(testing::Values(CV_8U, CV_32F), OCL_ALL_CHANNELS, Bool()));
125 
126 } } // namespace cvtest::ocl
127 
128 #endif
129