Home | History | Annotate | Download | only in opencl
      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 //    Fangfang Bai, fangfang (at) multicorewareinc.com
     19 //    Jin Ma,       jin (at) multicorewareinc.com
     20 //
     21 // Redistribution and use in source and binary forms, with or without modification,
     22 // are permitted provided that the following conditions are met:
     23 //
     24 //   * Redistribution's of source code must retain the above copyright notice,
     25 //     this list of conditions and the following disclaimer.
     26 //
     27 //   * Redistribution's in binary form must reproduce the above copyright notice,
     28 //     this list of conditions and the following disclaimer in the documentation
     29 //     and/or other materials provided with the distribution.
     30 //
     31 //   * The name of the copyright holders may not be used to endorse or promote products
     32 //     derived from this software without specific prior written permission.
     33 //
     34 // This software is provided by the copyright holders and contributors as is and
     35 // any express or implied warranties, including, but not limited to, the implied
     36 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     37 // In no event shall the Intel Corporation or contributors be liable for any direct,
     38 // indirect, incidental, special, exemplary, or consequential damages
     39 // (including, but not limited to, procurement of substitute goods or services;
     40 // loss of use, data, or profits; or business interruption) however caused
     41 // and on any theory of liability, whether in contract, strict liability,
     42 // or tort (including negligence or otherwise) arising in any way out of
     43 // the use of this software, even if advised of the possibility of such damage.
     44 //
     45 //M*/
     46 
     47 #include "../perf_precomp.hpp"
     48 #include "opencv2/ts/ocl_perf.hpp"
     49 
     50 #ifdef HAVE_OPENCL
     51 
     52 namespace cvtest {
     53 namespace ocl {
     54 
     55 ///////////// WarpAffine ////////////////////////
     56 
     57 CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC)
     58 
     59 typedef tuple<Size, MatType, InterType> WarpAffineParams;
     60 typedef TestBaseWithParam<WarpAffineParams> WarpAffineFixture;
     61 
     62 OCL_PERF_TEST_P(WarpAffineFixture, WarpAffine,
     63             ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, InterType::all()))
     64 {
     65     static const double coeffs[2][3] =
     66     {
     67         { cos(CV_PI / 6), -sin(CV_PI / 6), 100.0  },
     68         { sin(CV_PI / 6), cos(CV_PI / 6) , -100.0 }
     69     };
     70     Mat M(2, 3, CV_64F, (void *)coeffs);
     71 
     72     const WarpAffineParams params = GetParam();
     73     const Size srcSize = get<0>(params);
     74     const int type = get<1>(params), interpolation = get<2>(params);
     75     const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : interpolation == INTER_CUBIC ? 2e-3 : 1e-4;
     76 
     77     checkDeviceMaxMemoryAllocSize(srcSize, type);
     78 
     79     UMat src(srcSize, type), dst(srcSize, type);
     80     declare.in(src, WARMUP_RNG).out(dst);
     81 
     82     OCL_TEST_CYCLE() cv::warpAffine(src, dst, M, srcSize, interpolation);
     83 
     84     SANITY_CHECK(dst, eps);
     85 }
     86 
     87 ///////////// WarpPerspective ////////////////////////
     88 
     89 typedef WarpAffineParams WarpPerspectiveParams;
     90 typedef TestBaseWithParam<WarpPerspectiveParams> WarpPerspectiveFixture;
     91 
     92 OCL_PERF_TEST_P(WarpPerspectiveFixture, WarpPerspective,
     93                 ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
     94                                    OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR))))
     95 {
     96     static const double coeffs[3][3] =
     97     {
     98         {cos(CV_PI / 6), -sin(CV_PI / 6), 100.0},
     99         {sin(CV_PI / 6), cos(CV_PI / 6), -100.0},
    100         {0.0, 0.0, 1.0}
    101     };
    102     Mat M(3, 3, CV_64F, (void *)coeffs);
    103 
    104     const WarpPerspectiveParams params = GetParam();
    105     const Size srcSize = get<0>(params);
    106     const int type = get<1>(params), interpolation = get<2>(params);
    107     const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
    108 
    109     checkDeviceMaxMemoryAllocSize(srcSize, type);
    110 
    111     UMat src(srcSize, type), dst(srcSize, type);
    112     declare.in(src, WARMUP_RNG).out(dst);
    113 
    114     OCL_TEST_CYCLE() cv::warpPerspective(src, dst, M, srcSize, interpolation);
    115 
    116     SANITY_CHECK(dst, eps);
    117 }
    118 
    119 ///////////// Resize ////////////////////////
    120 
    121 typedef tuple<Size, MatType, InterType, double> ResizeParams;
    122 typedef TestBaseWithParam<ResizeParams> ResizeFixture;
    123 
    124 OCL_PERF_TEST_P(ResizeFixture, Resize,
    125             ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
    126                                OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR)),
    127                                ::testing::Values(0.5, 2.0)))
    128 {
    129     const ResizeParams params = GetParam();
    130     const Size srcSize = get<0>(params);
    131     const int type = get<1>(params), interType = get<2>(params);
    132     double scale = get<3>(params);
    133     const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));
    134     const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
    135 
    136     checkDeviceMaxMemoryAllocSize(srcSize, type);
    137     checkDeviceMaxMemoryAllocSize(dstSize, type);
    138 
    139     UMat src(srcSize, type), dst(dstSize, type);
    140     declare.in(src, WARMUP_RNG).out(dst);
    141 
    142     OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, interType);
    143 
    144     SANITY_CHECK(dst, eps);
    145 }
    146 
    147 typedef tuple<Size, MatType, double> ResizeAreaParams;
    148 typedef TestBaseWithParam<ResizeAreaParams> ResizeAreaFixture;
    149 
    150 OCL_PERF_TEST_P(ResizeAreaFixture, Resize,
    151             ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134, ::testing::Values(0.3, 0.5, 0.6)))
    152 {
    153     const ResizeAreaParams params = GetParam();
    154     const Size srcSize = get<0>(params);
    155     const int type = get<1>(params);
    156     double scale = get<2>(params);
    157     const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));
    158     const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
    159 
    160     checkDeviceMaxMemoryAllocSize(srcSize, type);
    161     checkDeviceMaxMemoryAllocSize(dstSize, type);
    162 
    163     UMat src(srcSize, type), dst(dstSize, type);
    164     declare.in(src, WARMUP_RNG).out(dst);
    165 
    166     OCL_TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, cv::INTER_AREA);
    167 
    168     SANITY_CHECK(dst, eps);
    169 }
    170 
    171 ///////////// Remap ////////////////////////
    172 
    173 typedef tuple<Size, MatType, InterType> RemapParams;
    174 typedef TestBaseWithParam<RemapParams> RemapFixture;
    175 
    176 OCL_PERF_TEST_P(RemapFixture, Remap,
    177             ::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES_134,
    178                                OCL_PERF_ENUM(InterType(INTER_NEAREST), InterType(INTER_LINEAR))))
    179 {
    180     const RemapParams params = GetParam();
    181     const Size srcSize = get<0>(params);
    182     const int type = get<1>(params), interpolation = get<2>(params), borderMode = BORDER_CONSTANT;
    183     const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
    184 
    185     checkDeviceMaxMemoryAllocSize(srcSize, type);
    186 
    187     UMat src(srcSize, type), dst(srcSize, type);
    188     UMat xmap(srcSize, CV_32FC1), ymap(srcSize, CV_32FC1);
    189 
    190     {
    191         Mat _xmap = xmap.getMat(ACCESS_WRITE), _ymap = ymap.getMat(ACCESS_WRITE);
    192         for (int i = 0; i < srcSize.height; ++i)
    193         {
    194             float * const xmap_row = _xmap.ptr<float>(i);
    195             float * const ymap_row = _ymap.ptr<float>(i);
    196 
    197             for (int j = 0; j < srcSize.width; ++j)
    198             {
    199                 xmap_row[j] = (j - srcSize.width * 0.5f) * 0.75f + srcSize.width * 0.5f;
    200                 ymap_row[j] = (i - srcSize.height * 0.5f) * 0.75f + srcSize.height * 0.5f;
    201             }
    202         }
    203     }
    204     declare.in(src, WARMUP_RNG).in(xmap, ymap, WARMUP_READ).out(dst);
    205 
    206     OCL_TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode);
    207 
    208     SANITY_CHECK(dst, eps);
    209 }
    210 
    211 } } // namespace cvtest::ocl
    212 
    213 #endif // HAVE_OPENCL
    214