Merge pull request #1704 from SpecLad:merge-2.4
[profile/ivi/opencv.git] / modules / ocl / test / test_match_template.cpp
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 //    Peng Xiao, pengxiao@multicorewareinc.com
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 //   * Redistribution's of source code must retain the above copyright notice,
23 //     this list of conditions and the following disclaimer.
24 //
25 //   * Redistribution's in binary form must reproduce the above copyright notice,
26 //     this list of conditions and the following disclaimer in the documentation
27 //     and/or other materials provided with the distribution.
28 //
29 //   * The name of the copyright holders may not be used to endorse or promote products
30 //     derived from this software without specific prior written permission.
31 //
32 // This software is provided by the copyright holders and contributors as is and
33 // any express or implied warranties, including, but not limited to, the implied
34 // warranties of merchantability and fitness for a particular purpose are disclaimed.
35 // In no event shall the Intel Corporation or contributors be liable for any direct,
36 // indirect, incidental, special, exemplary, or consequential damages
37 // (including, but not limited to, procurement of substitute goods or services;
38 // loss of use, data, or profits; or business interruption) however caused
39 // and on any theory of liability, whether in contract, strict liability,
40 // or tort (including negligence or otherwise) arising in any way out of
41 // the use of this software, even if advised of the possibility of such damage.
42 //
43 //M*/
44
45
46 #include "test_precomp.hpp"
47
48 #ifdef HAVE_OPENCL
49 ////////////////////////////////////////////////////////////////////////////////
50 // MatchTemplate
51 #define ALL_TEMPLATE_METHODS testing::Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR), TemplateMethod(cv::TM_CCOEFF), TemplateMethod(cv::TM_SQDIFF_NORMED), TemplateMethod(cv::TM_CCORR_NORMED), TemplateMethod(cv::TM_CCOEFF_NORMED))
52
53 IMPLEMENT_PARAM_CLASS(TemplateSize, cv::Size);
54
55 #define MTEMP_SIZES testing::Values(cv::Size(128, 256), cv::Size(1024, 768))
56
57 PARAM_TEST_CASE(MatchTemplate8U, cv::Size, TemplateSize, Channels, TemplateMethod)
58 {
59     cv::Size size;
60     cv::Size templ_size;
61     int cn;
62     int method;
63
64     virtual void SetUp()
65     {
66         size = GET_PARAM(0);
67         templ_size = GET_PARAM(1);
68         cn = GET_PARAM(2);
69         method = GET_PARAM(3);
70     }
71 };
72
73 OCL_TEST_P(MatchTemplate8U, Accuracy)
74 {
75     cv::Mat image = randomMat(size, CV_MAKETYPE(CV_8U, cn), 0, 255);
76     cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_8U, cn), 0, 255);
77
78     cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ);
79     cv::ocl::matchTemplate(ocl_image, ocl_templ, dst, method);
80
81     cv::Mat dst_gold;
82     cv::matchTemplate(image, templ, dst_gold, method);
83
84     cv::Mat mat_dst;
85     dst.download(mat_dst);
86
87     EXPECT_MAT_NEAR(dst_gold, mat_dst, templ_size.area() * 1e-1);
88 }
89
90 PARAM_TEST_CASE(MatchTemplate32F, cv::Size, TemplateSize, Channels, TemplateMethod)
91 {
92     cv::Size size;
93     cv::Size templ_size;
94     int cn;
95     int method;
96
97     virtual void SetUp()
98     {
99         size = GET_PARAM(0);
100         templ_size = GET_PARAM(1);
101         cn = GET_PARAM(2);
102         method = GET_PARAM(3);
103     }
104 };
105
106 OCL_TEST_P(MatchTemplate32F, Accuracy)
107 {
108     cv::Mat image = randomMat(size, CV_MAKETYPE(CV_32F, cn), 0, 255);
109     cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_32F, cn), 0, 255);
110
111     cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ);
112     cv::ocl::matchTemplate(ocl_image, ocl_templ, dst, method);
113
114     cv::Mat dst_gold;
115     cv::matchTemplate(image, templ, dst_gold, method);
116
117     cv::Mat mat_dst;
118     dst.download(mat_dst);
119
120     EXPECT_MAT_NEAR(dst_gold, mat_dst, templ_size.area() * 1e-1);
121 }
122
123 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MatchTemplate8U,
124                         testing::Combine(
125                             MTEMP_SIZES,
126                             testing::Values(TemplateSize(cv::Size(5, 5)), TemplateSize(cv::Size(16, 16)), TemplateSize(cv::Size(30, 30))),
127                             testing::Values(Channels(1), Channels(3), Channels(4)),
128                             ALL_TEMPLATE_METHODS
129                         )
130                        );
131
132 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MatchTemplate32F, testing::Combine(
133                             MTEMP_SIZES,
134                             testing::Values(TemplateSize(cv::Size(5, 5)), TemplateSize(cv::Size(16, 16)), TemplateSize(cv::Size(30, 30))),
135                             testing::Values(Channels(1), Channels(3), Channels(4)),
136                             testing::Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR))));
137 #endif