Path: blob/master/modules/imgproc/test/ocl/test_accumulate.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// @Authors17// Nathan, [email protected]18//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 documentation27// and/or other materials provided with the distribution.28//29// * The name of the copyright holders may not be used to endorse or promote products30// derived from this software without specific prior written permission.31//32// This software is provided by the copyright holders and contributors as is and33// any express or implied warranties, including, but not limited to, the implied34// 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 damages37// (including, but not limited to, procurement of substitute goods or services;38// loss of use, data, or profits; or business interruption) however caused39// and on any theory of liability, whether in contract, strict liability,40// or tort (including negligence or otherwise) arising in any way out of41// the use of this software, even if advised of the possibility of such damage.42//43//M*/4445#include "../test_precomp.hpp"46#include "opencv2/ts/ocl_test.hpp"4748#ifdef HAVE_OPENCL4950namespace opencv_test {51namespace ocl {5253PARAM_TEST_CASE(AccumulateBase, std::pair<MatDepth, MatDepth>, Channels, bool)54{55int sdepth, ddepth, channels;56bool useRoi;57double alpha;5859TEST_DECLARE_INPUT_PARAMETER(src);60TEST_DECLARE_INPUT_PARAMETER(mask);61TEST_DECLARE_INPUT_PARAMETER(src2);62TEST_DECLARE_OUTPUT_PARAMETER(dst);6364virtual void SetUp()65{66const std::pair<MatDepth, MatDepth> depths = GET_PARAM(0);67sdepth = depths.first, ddepth = depths.second;68channels = GET_PARAM(1);69useRoi = GET_PARAM(2);70}7172void random_roi()73{74const int stype = CV_MAKE_TYPE(sdepth, channels),75dtype = CV_MAKE_TYPE(ddepth, channels);7677Size roiSize = randomSize(1, 10);78Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);79randomSubMat(src, src_roi, roiSize, srcBorder, stype, -MAX_VALUE, MAX_VALUE);8081Border maskBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);82randomSubMat(mask, mask_roi, roiSize, maskBorder, CV_8UC1, -MAX_VALUE, MAX_VALUE);83cvtest::threshold(mask, mask, 80, 255, THRESH_BINARY);8485Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);86randomSubMat(src2, src2_roi, roiSize, src2Border, stype, -MAX_VALUE, MAX_VALUE);8788Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);89randomSubMat(dst, dst_roi, roiSize, dstBorder, dtype, -MAX_VALUE, MAX_VALUE);9091UMAT_UPLOAD_INPUT_PARAMETER(src);92UMAT_UPLOAD_INPUT_PARAMETER(mask);93UMAT_UPLOAD_INPUT_PARAMETER(src2);94UMAT_UPLOAD_OUTPUT_PARAMETER(dst);9596alpha = randomDouble(-5, 5);97}98};99100/////////////////////////////////// Accumulate ///////////////////////////////////101102typedef AccumulateBase Accumulate;103104OCL_TEST_P(Accumulate, Mat)105{106for (int i = 0; i < test_loop_times; ++i)107{108random_roi();109110OCL_OFF(cv::accumulate(src_roi, dst_roi));111OCL_ON(cv::accumulate(usrc_roi, udst_roi));112113OCL_EXPECT_MATS_NEAR(dst, 1e-6);114}115}116117OCL_TEST_P(Accumulate, Mask)118{119for (int i = 0; i < test_loop_times; ++i)120{121random_roi();122123OCL_OFF(cv::accumulate(src_roi, dst_roi, mask_roi));124OCL_ON(cv::accumulate(usrc_roi, udst_roi, umask_roi));125126OCL_EXPECT_MATS_NEAR(dst, 1e-6);127}128}129130/////////////////////////////////// AccumulateSquare ///////////////////////////////////131132typedef AccumulateBase AccumulateSquare;133134OCL_TEST_P(AccumulateSquare, Mat)135{136for (int i = 0; i < test_loop_times; ++i)137{138random_roi();139140OCL_OFF(cv::accumulateSquare(src_roi, dst_roi));141OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi));142143OCL_EXPECT_MATS_NEAR(dst, 1e-2);144}145}146147OCL_TEST_P(AccumulateSquare, Mask)148{149for (int i = 0; i < test_loop_times; ++i)150{151random_roi();152153OCL_OFF(cv::accumulateSquare(src_roi, dst_roi, mask_roi));154OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi, umask_roi));155156OCL_EXPECT_MATS_NEAR(dst, 1e-2);157}158}159160/////////////////////////////////// AccumulateProduct ///////////////////////////////////161162typedef AccumulateBase AccumulateProduct;163164OCL_TEST_P(AccumulateProduct, Mat)165{166for (int i = 0; i < test_loop_times; ++i)167{168random_roi();169170OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi));171OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi));172173OCL_EXPECT_MATS_NEAR(dst, 1e-2);174}175}176177OCL_TEST_P(AccumulateProduct, Mask)178{179for (int i = 0; i < test_loop_times; ++i)180{181random_roi();182183OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi, mask_roi));184OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi, umask_roi));185186OCL_EXPECT_MATS_NEAR(dst, 1e-2);187}188}189190/////////////////////////////////// AccumulateWeighted ///////////////////////////////////191192typedef AccumulateBase AccumulateWeighted;193194OCL_TEST_P(AccumulateWeighted, Mat)195{196for (int i = 0; i < test_loop_times; ++i)197{198random_roi();199200OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));201OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));202203OCL_EXPECT_MATS_NEAR(dst, 1e-2);204}205}206207OCL_TEST_P(AccumulateWeighted, Mask)208{209for (int i = 0; i < test_loop_times; ++i)210{211random_roi();212213OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));214OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));215216OCL_EXPECT_MATS_NEAR(dst, 1e-2);217}218}219220/////////////////////////////////// Instantiation ///////////////////////////////////221222#define OCL_DEPTH_ALL_COMBINATIONS \223testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F), \224std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F), \225std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F), \226std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F), \227std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F), \228std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F), \229std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F))230231OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Accumulate, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));232OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateSquare, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));233OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateProduct, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));234OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateWeighted, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));235236} } // namespace opencv_test::ocl237238#endif239240241