Path: blob/master/modules/imgproc/test/ocl/test_match_template.cpp
16344 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.13// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16//17// Redistribution and use in source and binary forms, with or without modification,18// are permitted provided that the following conditions are met:19//20// * Redistribution's of source code must retain the above copyright notice,21// this list of conditions and the following disclaimer.22//23// * Redistribution's in binary form must reproduce the above copyright notice,24// this list of conditions and the following disclaimer in the documentation25// and/or other materials provided with the distribution.26//27// * The name of the copyright holders may not be used to endorse or promote products28// derived from this software without specific prior written permission.29//30// This software is provided by the copyright holders and contributors as is and31// any express or implied warranties, including, but not limited to, the implied32// warranties of merchantability and fitness for a particular purpose are disclaimed.33// In no event shall the Intel Corporation or contributors be liable for any direct,34// indirect, incidental, special, exemplary, or consequential damages35// (including, but not limited to, procurement of substitute goods or services;36// loss of use, data, or profits; or business interruption) however caused37// and on any theory of liability, whether in contract, strict liability,38// or tort (including negligence or otherwise) arising in any way out of39// the use of this software, even if advised of the possibility of such damage.40//41//M*/4243#include "../test_precomp.hpp"44#include "opencv2/ts/ocl_test.hpp"4546#ifdef HAVE_OPENCL4748namespace opencv_test {49namespace ocl {5051///////////////////////////////////////////// matchTemplate //////////////////////////////////////////////////////////5253CV_ENUM(MatchTemplType, CV_TM_CCORR, CV_TM_CCORR_NORMED, CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED)5455PARAM_TEST_CASE(MatchTemplate, MatDepth, Channels, MatchTemplType, bool)56{57int type;58int depth;59int method;60bool use_roi;6162TEST_DECLARE_INPUT_PARAMETER(image);63TEST_DECLARE_INPUT_PARAMETER(templ);64TEST_DECLARE_OUTPUT_PARAMETER(result);6566virtual void SetUp()67{68type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));69depth = GET_PARAM(0);70method = GET_PARAM(2);71use_roi = GET_PARAM(3);72}7374void generateTestData()75{76Size image_roiSize = randomSize(2, 100);77Size templ_roiSize = Size(randomInt(1, image_roiSize.width), randomInt(1, image_roiSize.height));78Size result_roiSize = Size(image_roiSize.width - templ_roiSize.width + 1,79image_roiSize.height - templ_roiSize.height + 1);8081const double upValue = 256;8283Border imageBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);84randomSubMat(image, image_roi, image_roiSize, imageBorder, type, -upValue, upValue);8586Border templBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);87randomSubMat(templ, templ_roi, templ_roiSize, templBorder, type, -upValue, upValue);8889Border resultBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);90randomSubMat(result, result_roi, result_roiSize, resultBorder, CV_32FC1, -upValue, upValue);9192UMAT_UPLOAD_INPUT_PARAMETER(image);93UMAT_UPLOAD_INPUT_PARAMETER(templ);94UMAT_UPLOAD_OUTPUT_PARAMETER(result);95}9697void Near()98{99bool isNormed =100method == TM_CCORR_NORMED ||101method == TM_SQDIFF_NORMED ||102method == TM_CCOEFF_NORMED;103104if (isNormed)105OCL_EXPECT_MATS_NEAR(result, 3e-2);106else107OCL_EXPECT_MATS_NEAR_RELATIVE_SPARSE(result, 1.5e-2);108}109};110111OCL_TEST_P(MatchTemplate, Mat)112{113for (int j = 0; j < test_loop_times; j++)114{115generateTestData();116117OCL_OFF(cv::matchTemplate(image_roi, templ_roi, result_roi, method));118OCL_ON(cv::matchTemplate(uimage_roi, utempl_roi, uresult_roi, method));119120Near();121}122}123124OCL_INSTANTIATE_TEST_CASE_P(ImageProc, MatchTemplate, Combine(125Values(CV_8U, CV_32F),126Values(1, 2, 3, 4),127MatchTemplType::all(),128Bool())129);130} } // namespace opencv_test::ocl131132#endif133134135