Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/test/ocl/test_match_template.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
//
18
// Redistribution and use in source and binary forms, with or without modification,
19
// are permitted provided that the following conditions are met:
20
//
21
// * Redistribution's of source code must retain the above copyright notice,
22
// this list of conditions and the following disclaimer.
23
//
24
// * Redistribution's in binary form must reproduce the above copyright notice,
25
// this list of conditions and the following disclaimer in the documentation
26
// and/or other materials provided with the distribution.
27
//
28
// * The name of the copyright holders may not be used to endorse or promote products
29
// derived from this software without specific prior written permission.
30
//
31
// This software is provided by the copyright holders and contributors as is and
32
// any express or implied warranties, including, but not limited to, the implied
33
// warranties of merchantability and fitness for a particular purpose are disclaimed.
34
// In no event shall the Intel Corporation or contributors be liable for any direct,
35
// indirect, incidental, special, exemplary, or consequential damages
36
// (including, but not limited to, procurement of substitute goods or services;
37
// loss of use, data, or profits; or business interruption) however caused
38
// and on any theory of liability, whether in contract, strict liability,
39
// or tort (including negligence or otherwise) arising in any way out of
40
// the use of this software, even if advised of the possibility of such damage.
41
//
42
//M*/
43
44
#include "../test_precomp.hpp"
45
#include "opencv2/ts/ocl_test.hpp"
46
47
#ifdef HAVE_OPENCL
48
49
namespace opencv_test {
50
namespace ocl {
51
52
///////////////////////////////////////////// matchTemplate //////////////////////////////////////////////////////////
53
54
CV_ENUM(MatchTemplType, CV_TM_CCORR, CV_TM_CCORR_NORMED, CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED)
55
56
PARAM_TEST_CASE(MatchTemplate, MatDepth, Channels, MatchTemplType, bool)
57
{
58
int type;
59
int depth;
60
int method;
61
bool use_roi;
62
63
TEST_DECLARE_INPUT_PARAMETER(image);
64
TEST_DECLARE_INPUT_PARAMETER(templ);
65
TEST_DECLARE_OUTPUT_PARAMETER(result);
66
67
virtual void SetUp()
68
{
69
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
70
depth = GET_PARAM(0);
71
method = GET_PARAM(2);
72
use_roi = GET_PARAM(3);
73
}
74
75
void generateTestData()
76
{
77
Size image_roiSize = randomSize(2, 100);
78
Size templ_roiSize = Size(randomInt(1, image_roiSize.width), randomInt(1, image_roiSize.height));
79
Size result_roiSize = Size(image_roiSize.width - templ_roiSize.width + 1,
80
image_roiSize.height - templ_roiSize.height + 1);
81
82
const double upValue = 256;
83
84
Border imageBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
85
randomSubMat(image, image_roi, image_roiSize, imageBorder, type, -upValue, upValue);
86
87
Border templBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
88
randomSubMat(templ, templ_roi, templ_roiSize, templBorder, type, -upValue, upValue);
89
90
Border resultBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
91
randomSubMat(result, result_roi, result_roiSize, resultBorder, CV_32FC1, -upValue, upValue);
92
93
UMAT_UPLOAD_INPUT_PARAMETER(image);
94
UMAT_UPLOAD_INPUT_PARAMETER(templ);
95
UMAT_UPLOAD_OUTPUT_PARAMETER(result);
96
}
97
98
void Near()
99
{
100
bool isNormed =
101
method == TM_CCORR_NORMED ||
102
method == TM_SQDIFF_NORMED ||
103
method == TM_CCOEFF_NORMED;
104
105
if (isNormed)
106
OCL_EXPECT_MATS_NEAR(result, 3e-2);
107
else
108
OCL_EXPECT_MATS_NEAR_RELATIVE_SPARSE(result, 1.5e-2);
109
}
110
};
111
112
OCL_TEST_P(MatchTemplate, Mat)
113
{
114
for (int j = 0; j < test_loop_times; j++)
115
{
116
generateTestData();
117
118
OCL_OFF(cv::matchTemplate(image_roi, templ_roi, result_roi, method));
119
OCL_ON(cv::matchTemplate(uimage_roi, utempl_roi, uresult_roi, method));
120
121
Near();
122
}
123
}
124
125
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, MatchTemplate, Combine(
126
Values(CV_8U, CV_32F),
127
Values(1, 2, 3, 4),
128
MatchTemplType::all(),
129
Bool())
130
);
131
} } // namespace opencv_test::ocl
132
133
#endif
134
135