Home | History | Annotate | Download | only in ocl
      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 //    Nathan, liujun (at) multicorewareinc.com
     19 //
     20 // Redistribution and use in source and binary forms, with or without modification,
     21 // are permitted provided that the following conditions are met:
     22 //
     23 //   * Redistribution's of source code must retain the above copyright notice,
     24 //     this list of conditions and the following disclaimer.
     25 //
     26 //   * Redistribution's in binary form must reproduce the above copyright notice,
     27 //     this list of conditions and the following disclaimer in the documentation
     28 //     and/or other materials provided with the distribution.
     29 //
     30 //   * The name of the copyright holders may not be used to endorse or promote products
     31 //     derived from this software without specific prior written permission.
     32 //
     33 // This software is provided by the copyright holders and contributors as is and
     34 // any express or implied warranties, including, but not limited to, the implied
     35 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     36 // In no event shall the Intel Corporation or contributors be liable for any direct,
     37 // indirect, incidental, special, exemplary, or consequential damages
     38 // (including, but not limited to, procurement of substitute goods or services;
     39 // loss of use, data, or profits; or business interruption) however caused
     40 // and on any theory of liability, whether in contract, strict liability,
     41 // or tort (including negligence or otherwise) arising in any way out of
     42 // the use of this software, even if advised of the possibility of such damage.
     43 //
     44 //M*/
     45 
     46 #include "../test_precomp.hpp"
     47 #include "cvconfig.h"
     48 #include "opencv2/ts/ocl_test.hpp"
     49 
     50 #ifdef HAVE_OPENCL
     51 
     52 namespace cvtest {
     53 namespace ocl {
     54 
     55 PARAM_TEST_CASE(AccumulateBase, std::pair<MatDepth, MatDepth>, Channels, bool)
     56 {
     57     int sdepth, ddepth, channels;
     58     bool useRoi;
     59     double alpha;
     60 
     61     TEST_DECLARE_INPUT_PARAMETER(src);
     62     TEST_DECLARE_INPUT_PARAMETER(mask);
     63     TEST_DECLARE_INPUT_PARAMETER(src2);
     64     TEST_DECLARE_OUTPUT_PARAMETER(dst);
     65 
     66     virtual void SetUp()
     67     {
     68         const std::pair<MatDepth, MatDepth> depths = GET_PARAM(0);
     69         sdepth = depths.first, ddepth = depths.second;
     70         channels = GET_PARAM(1);
     71         useRoi = GET_PARAM(2);
     72     }
     73 
     74     void random_roi()
     75     {
     76         const int stype = CV_MAKE_TYPE(sdepth, channels),
     77                 dtype = CV_MAKE_TYPE(ddepth, channels);
     78 
     79         Size roiSize = randomSize(1, 10);
     80         Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
     81         randomSubMat(src, src_roi, roiSize, srcBorder, stype, -MAX_VALUE, MAX_VALUE);
     82 
     83         Border maskBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
     84         randomSubMat(mask, mask_roi, roiSize, maskBorder, CV_8UC1, -MAX_VALUE, MAX_VALUE);
     85         threshold(mask, mask, 80, 255, THRESH_BINARY);
     86 
     87         Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
     88         randomSubMat(src2, src2_roi, roiSize, src2Border, stype, -MAX_VALUE, MAX_VALUE);
     89 
     90         Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
     91         randomSubMat(dst, dst_roi, roiSize, dstBorder, dtype, -MAX_VALUE, MAX_VALUE);
     92 
     93         UMAT_UPLOAD_INPUT_PARAMETER(src);
     94         UMAT_UPLOAD_INPUT_PARAMETER(mask);
     95         UMAT_UPLOAD_INPUT_PARAMETER(src2);
     96         UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
     97 
     98         alpha = randomDouble(-5, 5);
     99     }
    100 };
    101 
    102 /////////////////////////////////// Accumulate ///////////////////////////////////
    103 
    104 typedef AccumulateBase Accumulate;
    105 
    106 OCL_TEST_P(Accumulate, Mat)
    107 {
    108     for (int i = 0; i < test_loop_times; ++i)
    109     {
    110         random_roi();
    111 
    112         OCL_OFF(cv::accumulate(src_roi, dst_roi));
    113         OCL_ON(cv::accumulate(usrc_roi, udst_roi));
    114 
    115         OCL_EXPECT_MATS_NEAR(dst, 1e-6);
    116     }
    117 }
    118 
    119 OCL_TEST_P(Accumulate, Mask)
    120 {
    121     for (int i = 0; i < test_loop_times; ++i)
    122     {
    123         random_roi();
    124 
    125         OCL_OFF(cv::accumulate(src_roi, dst_roi, mask_roi));
    126         OCL_ON(cv::accumulate(usrc_roi, udst_roi, umask_roi));
    127 
    128         OCL_EXPECT_MATS_NEAR(dst, 1e-6);
    129     }
    130 }
    131 
    132 /////////////////////////////////// AccumulateSquare ///////////////////////////////////
    133 
    134 typedef AccumulateBase AccumulateSquare;
    135 
    136 OCL_TEST_P(AccumulateSquare, Mat)
    137 {
    138     for (int i = 0; i < test_loop_times; ++i)
    139     {
    140         random_roi();
    141 
    142         OCL_OFF(cv::accumulateSquare(src_roi, dst_roi));
    143         OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi));
    144 
    145         OCL_EXPECT_MATS_NEAR(dst, 1e-2);
    146     }
    147 }
    148 
    149 OCL_TEST_P(AccumulateSquare, Mask)
    150 {
    151     for (int i = 0; i < test_loop_times; ++i)
    152     {
    153         random_roi();
    154 
    155         OCL_OFF(cv::accumulateSquare(src_roi, dst_roi, mask_roi));
    156         OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi, umask_roi));
    157 
    158         OCL_EXPECT_MATS_NEAR(dst, 1e-2);
    159     }
    160 }
    161 
    162 /////////////////////////////////// AccumulateProduct ///////////////////////////////////
    163 
    164 typedef AccumulateBase AccumulateProduct;
    165 
    166 OCL_TEST_P(AccumulateProduct, Mat)
    167 {
    168     for (int i = 0; i < test_loop_times; ++i)
    169     {
    170         random_roi();
    171 
    172         OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi));
    173         OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi));
    174 
    175         OCL_EXPECT_MATS_NEAR(dst, 1e-2);
    176     }
    177 }
    178 
    179 OCL_TEST_P(AccumulateProduct, Mask)
    180 {
    181     for (int i = 0; i < test_loop_times; ++i)
    182     {
    183         random_roi();
    184 
    185         OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi, mask_roi));
    186         OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi, umask_roi));
    187 
    188         OCL_EXPECT_MATS_NEAR(dst, 1e-2);
    189     }
    190 }
    191 
    192 /////////////////////////////////// AccumulateWeighted ///////////////////////////////////
    193 
    194 typedef AccumulateBase AccumulateWeighted;
    195 
    196 OCL_TEST_P(AccumulateWeighted, Mat)
    197 {
    198     for (int i = 0; i < test_loop_times; ++i)
    199     {
    200         random_roi();
    201 
    202         OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
    203         OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
    204 
    205         OCL_EXPECT_MATS_NEAR(dst, 1e-2);
    206     }
    207 }
    208 
    209 OCL_TEST_P(AccumulateWeighted, Mask)
    210 {
    211     for (int i = 0; i < test_loop_times; ++i)
    212     {
    213         random_roi();
    214 
    215         OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
    216         OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
    217 
    218         OCL_EXPECT_MATS_NEAR(dst, 1e-2);
    219     }
    220 }
    221 
    222 /////////////////////////////////// Instantiation ///////////////////////////////////
    223 
    224 #define OCL_DEPTH_ALL_COMBINATIONS \
    225     testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F), \
    226     std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F), \
    227     std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F), \
    228     std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F), \
    229     std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F), \
    230     std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F), \
    231     std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F))
    232 
    233 OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Accumulate, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
    234 OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateSquare, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
    235 OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateProduct, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
    236 OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateWeighted, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
    237 
    238 } } // namespace cvtest::ocl
    239 
    240 #endif
    241