Home | History | Annotate | Download | only in perf
      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) 2000-2008, Intel Corporation, all rights reserved.
     14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
     15 // Third party copyrights are property of their respective owners.
     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 documentation
     25 //     and/or other materials provided with the distribution.
     26 //
     27 //   * The name of the copyright holders may not be used to endorse or promote products
     28 //     derived from this software without specific prior written permission.
     29 //
     30 // This software is provided by the copyright holders and contributors "as is" and
     31 // any express or implied warranties, including, but not limited to, the implied
     32 // 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 damages
     35 // (including, but not limited to, procurement of substitute goods or services;
     36 // loss of use, data, or profits; or business interruption) however caused
     37 // and on any theory of liability, whether in contract, strict liability,
     38 // or tort (including negligence or otherwise) arising in any way out of
     39 // the use of this software, even if advised of the possibility of such damage.
     40 //
     41 //M*/
     42 
     43 #include "perf_precomp.hpp"
     44 
     45 using namespace std;
     46 using namespace testing;
     47 using namespace perf;
     48 
     49 //////////////////////////////////////////////////////////////////////
     50 // Blur
     51 
     52 DEF_PARAM_TEST(Sz_Type_KernelSz, cv::Size, MatType, int);
     53 
     54 PERF_TEST_P(Sz_Type_KernelSz, Blur,
     55             Combine(CUDA_TYPICAL_MAT_SIZES,
     56                     Values(CV_8UC1, CV_8UC4),
     57                     Values(3, 5, 7)))
     58 {
     59     declare.time(20.0);
     60 
     61     const cv::Size size = GET_PARAM(0);
     62     const int type = GET_PARAM(1);
     63     const int ksize = GET_PARAM(2);
     64 
     65     cv::Mat src(size, type);
     66     declare.in(src, WARMUP_RNG);
     67 
     68     if (PERF_RUN_CUDA())
     69     {
     70         const cv::cuda::GpuMat d_src(src);
     71         cv::cuda::GpuMat dst;
     72 
     73         cv::Ptr<cv::cuda::Filter> blurFilter = cv::cuda::createBoxFilter(d_src.type(), -1, cv::Size(ksize, ksize));
     74 
     75         TEST_CYCLE() blurFilter->apply(d_src, dst);
     76 
     77         CUDA_SANITY_CHECK(dst, 1);
     78     }
     79     else
     80     {
     81         cv::Mat dst;
     82 
     83         TEST_CYCLE() cv::blur(src, dst, cv::Size(ksize, ksize));
     84 
     85         CPU_SANITY_CHECK(dst);
     86     }
     87 }
     88 
     89 //////////////////////////////////////////////////////////////////////
     90 // Filter2D
     91 
     92 PERF_TEST_P(Sz_Type_KernelSz, Filter2D, Combine(CUDA_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(3, 5, 7, 9, 11, 13, 15)))
     93 {
     94     declare.time(20.0);
     95 
     96     const cv::Size size = GET_PARAM(0);
     97     const int type = GET_PARAM(1);
     98     const int ksize = GET_PARAM(2);
     99 
    100     cv::Mat src(size, type);
    101     declare.in(src, WARMUP_RNG);
    102 
    103     cv::Mat kernel(ksize, ksize, CV_32FC1);
    104     declare.in(kernel, WARMUP_RNG);
    105 
    106     if (PERF_RUN_CUDA())
    107     {
    108         const cv::cuda::GpuMat d_src(src);
    109         cv::cuda::GpuMat dst;
    110 
    111         cv::Ptr<cv::cuda::Filter> filter2D = cv::cuda::createLinearFilter(d_src.type(), -1, kernel);
    112 
    113         TEST_CYCLE() filter2D->apply(d_src, dst);
    114 
    115         CUDA_SANITY_CHECK(dst);
    116     }
    117     else
    118     {
    119         cv::Mat dst;
    120 
    121         TEST_CYCLE() cv::filter2D(src, dst, -1, kernel);
    122 
    123         CPU_SANITY_CHECK(dst);
    124     }
    125 }
    126 
    127 //////////////////////////////////////////////////////////////////////
    128 // Laplacian
    129 
    130 PERF_TEST_P(Sz_Type_KernelSz, Laplacian, Combine(CUDA_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(1, 3)))
    131 {
    132     declare.time(20.0);
    133 
    134     const cv::Size size = GET_PARAM(0);
    135     const int type = GET_PARAM(1);
    136     const int ksize = GET_PARAM(2);
    137 
    138     cv::Mat src(size, type);
    139     declare.in(src, WARMUP_RNG);
    140 
    141     if (PERF_RUN_CUDA())
    142     {
    143         const cv::cuda::GpuMat d_src(src);
    144         cv::cuda::GpuMat dst;
    145 
    146         cv::Ptr<cv::cuda::Filter> laplacian = cv::cuda::createLaplacianFilter(d_src.type(), -1, ksize);
    147 
    148         TEST_CYCLE() laplacian->apply(d_src, dst);
    149 
    150         CUDA_SANITY_CHECK(dst);
    151     }
    152     else
    153     {
    154         cv::Mat dst;
    155 
    156         TEST_CYCLE() cv::Laplacian(src, dst, -1, ksize);
    157 
    158         CPU_SANITY_CHECK(dst);
    159     }
    160 }
    161 
    162 //////////////////////////////////////////////////////////////////////
    163 // Sobel
    164 
    165 PERF_TEST_P(Sz_Type_KernelSz, Sobel, Combine(CUDA_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1), Values(3, 5, 7, 9, 11, 13, 15)))
    166 {
    167     declare.time(20.0);
    168 
    169     const cv::Size size = GET_PARAM(0);
    170     const int type = GET_PARAM(1);
    171     const int ksize = GET_PARAM(2);
    172 
    173     cv::Mat src(size, type);
    174     declare.in(src, WARMUP_RNG);
    175 
    176     if (PERF_RUN_CUDA())
    177     {
    178         const cv::cuda::GpuMat d_src(src);
    179         cv::cuda::GpuMat dst;
    180 
    181         cv::Ptr<cv::cuda::Filter> sobel = cv::cuda::createSobelFilter(d_src.type(), -1, 1, 1, ksize);
    182 
    183         TEST_CYCLE() sobel->apply(d_src, dst);
    184 
    185         CUDA_SANITY_CHECK(dst);
    186     }
    187     else
    188     {
    189         cv::Mat dst;
    190 
    191         TEST_CYCLE() cv::Sobel(src, dst, -1, 1, 1, ksize);
    192 
    193         CPU_SANITY_CHECK(dst);
    194     }
    195 }
    196 
    197 //////////////////////////////////////////////////////////////////////
    198 // Scharr
    199 
    200 PERF_TEST_P(Sz_Type, Scharr, Combine(CUDA_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1)))
    201 {
    202     declare.time(20.0);
    203 
    204     const cv::Size size = GET_PARAM(0);
    205     const int type = GET_PARAM(1);
    206 
    207     cv::Mat src(size, type);
    208     declare.in(src, WARMUP_RNG);
    209 
    210     if (PERF_RUN_CUDA())
    211     {
    212         const cv::cuda::GpuMat d_src(src);
    213         cv::cuda::GpuMat dst;
    214 
    215         cv::Ptr<cv::cuda::Filter> scharr = cv::cuda::createScharrFilter(d_src.type(), -1, 1, 0);
    216 
    217         TEST_CYCLE() scharr->apply(d_src, dst);
    218 
    219         CUDA_SANITY_CHECK(dst);
    220     }
    221     else
    222     {
    223         cv::Mat dst;
    224 
    225         TEST_CYCLE() cv::Scharr(src, dst, -1, 1, 0);
    226 
    227         CPU_SANITY_CHECK(dst);
    228     }
    229 }
    230 
    231 //////////////////////////////////////////////////////////////////////
    232 // GaussianBlur
    233 
    234 PERF_TEST_P(Sz_Type_KernelSz, GaussianBlur, Combine(CUDA_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1), Values(3, 5, 7, 9, 11, 13, 15)))
    235 {
    236     declare.time(20.0);
    237 
    238     const cv::Size size = GET_PARAM(0);
    239     const int type = GET_PARAM(1);
    240     const int ksize = GET_PARAM(2);
    241 
    242     cv::Mat src(size, type);
    243     declare.in(src, WARMUP_RNG);
    244 
    245     if (PERF_RUN_CUDA())
    246     {
    247         const cv::cuda::GpuMat d_src(src);
    248         cv::cuda::GpuMat dst;
    249 
    250         cv::Ptr<cv::cuda::Filter> gauss = cv::cuda::createGaussianFilter(d_src.type(), -1, cv::Size(ksize, ksize), 0.5);
    251 
    252         TEST_CYCLE() gauss->apply(d_src, dst);
    253 
    254         CUDA_SANITY_CHECK(dst);
    255     }
    256     else
    257     {
    258         cv::Mat dst;
    259 
    260         TEST_CYCLE() cv::GaussianBlur(src, dst, cv::Size(ksize, ksize), 0.5);
    261 
    262         CPU_SANITY_CHECK(dst);
    263     }
    264 }
    265 
    266 //////////////////////////////////////////////////////////////////////
    267 // Erode
    268 
    269 PERF_TEST_P(Sz_Type, Erode, Combine(CUDA_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4)))
    270 {
    271     declare.time(20.0);
    272 
    273     const cv::Size size = GET_PARAM(0);
    274     const int type = GET_PARAM(1);
    275 
    276     cv::Mat src(size, type);
    277     declare.in(src, WARMUP_RNG);
    278 
    279     const cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
    280 
    281     if (PERF_RUN_CUDA())
    282     {
    283         const cv::cuda::GpuMat d_src(src);
    284         cv::cuda::GpuMat dst;
    285 
    286         cv::Ptr<cv::cuda::Filter> erode = cv::cuda::createMorphologyFilter(cv::MORPH_ERODE, src.type(), ker);
    287 
    288         TEST_CYCLE() erode->apply(d_src, dst);
    289 
    290         CUDA_SANITY_CHECK(dst);
    291     }
    292     else
    293     {
    294         cv::Mat dst;
    295 
    296         TEST_CYCLE() cv::erode(src, dst, ker);
    297 
    298         CPU_SANITY_CHECK(dst);
    299     }
    300 }
    301 
    302 //////////////////////////////////////////////////////////////////////
    303 // Dilate
    304 
    305 PERF_TEST_P(Sz_Type, Dilate, Combine(CUDA_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4)))
    306 {
    307     declare.time(20.0);
    308 
    309     const cv::Size size = GET_PARAM(0);
    310     const int type = GET_PARAM(1);
    311 
    312     cv::Mat src(size, type);
    313     declare.in(src, WARMUP_RNG);
    314 
    315     const cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
    316 
    317     if (PERF_RUN_CUDA())
    318     {
    319         const cv::cuda::GpuMat d_src(src);
    320         cv::cuda::GpuMat dst;
    321 
    322         cv::Ptr<cv::cuda::Filter> dilate = cv::cuda::createMorphologyFilter(cv::MORPH_DILATE, src.type(), ker);
    323 
    324         TEST_CYCLE() dilate->apply(d_src, dst);
    325 
    326         CUDA_SANITY_CHECK(dst);
    327     }
    328     else
    329     {
    330         cv::Mat dst;
    331 
    332         TEST_CYCLE() cv::dilate(src, dst, ker);
    333 
    334         CPU_SANITY_CHECK(dst);
    335     }
    336 }
    337 
    338 //////////////////////////////////////////////////////////////////////
    339 // MorphologyEx
    340 
    341 CV_ENUM(MorphOp, MORPH_OPEN, MORPH_CLOSE, MORPH_GRADIENT, MORPH_TOPHAT, MORPH_BLACKHAT)
    342 
    343 DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, MorphOp);
    344 
    345 PERF_TEST_P(Sz_Type_Op, MorphologyEx, Combine(CUDA_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4), MorphOp::all()))
    346 {
    347     declare.time(20.0);
    348 
    349     const cv::Size size = GET_PARAM(0);
    350     const int type = GET_PARAM(1);
    351     const int morphOp = GET_PARAM(2);
    352 
    353     cv::Mat src(size, type);
    354     declare.in(src, WARMUP_RNG);
    355 
    356     const cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
    357 
    358     if (PERF_RUN_CUDA())
    359     {
    360         const cv::cuda::GpuMat d_src(src);
    361         cv::cuda::GpuMat dst;
    362 
    363         cv::Ptr<cv::cuda::Filter> morph = cv::cuda::createMorphologyFilter(morphOp, src.type(), ker);
    364 
    365         TEST_CYCLE() morph->apply(d_src, dst);
    366 
    367         CUDA_SANITY_CHECK(dst);
    368     }
    369     else
    370     {
    371         cv::Mat dst;
    372 
    373         TEST_CYCLE() cv::morphologyEx(src, dst, morphOp, ker);
    374 
    375         CPU_SANITY_CHECK(dst);
    376     }
    377 }
    378