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 // 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:
22 // * Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
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 oclMaterials provided with the distribution.
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.
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.
46 #include "test_precomp.hpp"
49 ////////////////////////////////////////////////////////////////////////////////
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))
53 IMPLEMENT_PARAM_CLASS(TemplateSize, cv::Size);
55 const char *TEMPLATE_METHOD_NAMES[6] = {"TM_SQDIFF", "TM_SQDIFF_NORMED", "TM_CCORR", "TM_CCORR_NORMED", "TM_CCOEFF", "TM_CCOEFF_NORMED"};
57 #define MTEMP_SIZES testing::Values(cv::Size(128, 256), cv::Size(1024, 768))
59 PARAM_TEST_CASE(MatchTemplate8U, cv::Size, TemplateSize, Channels, TemplateMethod)
69 templ_size = GET_PARAM(1);
71 method = GET_PARAM(3);
75 TEST_P(MatchTemplate8U, Accuracy)
78 std::cout << "Method: " << TEMPLATE_METHOD_NAMES[method] << std::endl;
79 std::cout << "Image Size: (" << size.width << ", " << size.height << ")" << std::endl;
80 std::cout << "Template Size: (" << templ_size.width << ", " << templ_size.height << ")" << std::endl;
81 std::cout << "Channels: " << cn << std::endl;
83 cv::Mat image = randomMat(size, CV_MAKETYPE(CV_8U, cn));
84 cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_8U, cn));
86 cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ);
87 cv::ocl::matchTemplate(ocl_image, ocl_templ, dst, method);
90 cv::matchTemplate(image, templ, dst_gold, method);
93 dst.download(mat_dst);
95 EXPECT_MAT_NEAR(dst_gold, mat_dst, templ_size.area() * 1e-1);
98 PARAM_TEST_CASE(MatchTemplate32F, cv::Size, TemplateSize, Channels, TemplateMethod)
104 //std::vector<cv::ocl::Info> oclinfo;
109 templ_size = GET_PARAM(1);
111 method = GET_PARAM(3);
115 TEST_P(MatchTemplate32F, Accuracy)
117 cv::Mat image = randomMat(size, CV_MAKETYPE(CV_32F, cn));
118 cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_32F, cn));
120 cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ);
121 cv::ocl::matchTemplate(ocl_image, ocl_templ, dst, method);
124 cv::matchTemplate(image, templ, dst_gold, method);
127 dst.download(mat_dst);
129 EXPECT_MAT_NEAR(dst_gold, mat_dst, templ_size.area() * 1e-1);
132 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MatchTemplate8U,
135 testing::Values(TemplateSize(cv::Size(5, 5)), TemplateSize(cv::Size(16, 16)), TemplateSize(cv::Size(30, 30))),
136 testing::Values(Channels(1), Channels(3), Channels(4)),
141 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MatchTemplate32F, testing::Combine(
143 testing::Values(TemplateSize(cv::Size(5, 5)), TemplateSize(cv::Size(16, 16)), TemplateSize(cv::Size(30, 30))),
144 testing::Values(Channels(1), Channels(3), Channels(4)),
145 testing::Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR))));