Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/test/ocl/test_blend.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(BlendLinear, MatDepth, Channels, bool)
55
{
56
int depth, channels;
57
bool useRoi;
58
59
TEST_DECLARE_INPUT_PARAMETER(src1);
60
TEST_DECLARE_INPUT_PARAMETER(src2);
61
TEST_DECLARE_INPUT_PARAMETER(weights2);
62
TEST_DECLARE_INPUT_PARAMETER(weights1);
63
TEST_DECLARE_OUTPUT_PARAMETER(dst);
64
65
virtual void SetUp()
66
{
67
depth = GET_PARAM(0);
68
channels = GET_PARAM(1);
69
useRoi = GET_PARAM(2);
70
}
71
72
void random_roi()
73
{
74
const int type = CV_MAKE_TYPE(depth, channels);
75
const double upValue = 256;
76
77
Size roiSize = randomSize(1, MAX_VALUE);
78
Border src1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
79
randomSubMat(src1, src1_roi, roiSize, src1Border, type, -upValue, upValue);
80
81
Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
82
randomSubMat(src2, src2_roi, roiSize, src2Border, type, -upValue, upValue);
83
84
Border weights1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
85
randomSubMat(weights1, weights1_roi, roiSize, weights1Border, CV_32FC1, -upValue, upValue);
86
87
Border weights2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
88
randomSubMat(weights2, weights2_roi, roiSize, weights2Border, CV_32FC1, 1e-2, upValue);
89
90
weights2_roi -= weights1_roi;
91
CV_Assert(checkNorm2(weights2_roi, weights2(Rect(weights2Border.lef, weights2Border.top,
92
roiSize.width, roiSize.height))) < 1e-6);
93
94
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
95
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);
96
97
UMAT_UPLOAD_INPUT_PARAMETER(src1);
98
UMAT_UPLOAD_INPUT_PARAMETER(src2);
99
UMAT_UPLOAD_INPUT_PARAMETER(weights1);
100
UMAT_UPLOAD_INPUT_PARAMETER(weights2);
101
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
102
}
103
104
void Near(double eps = 0.0)
105
{
106
OCL_EXPECT_MATS_NEAR(dst, eps);
107
}
108
};
109
110
OCL_TEST_P(BlendLinear, Accuracy)
111
{
112
for (int i = 0; i < test_loop_times; ++i)
113
{
114
random_roi();
115
116
OCL_OFF(cv::blendLinear(src1_roi, src2_roi, weights1_roi, weights2_roi, dst_roi));
117
OCL_ON(cv::blendLinear(usrc1_roi, usrc2_roi, uweights1_roi, uweights2_roi, udst_roi));
118
119
Near(depth <= CV_32S ? 1.0 : 0.5);
120
}
121
}
122
123
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, BlendLinear, Combine(testing::Values(CV_8U, CV_32F), OCL_ALL_CHANNELS, Bool()));
124
125
} } // namespace opencv_test::ocl
126
127
#endif
128
129