123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- /*M///////////////////////////////////////////////////////////////////////////////////////
- //
- // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
- //
- // By downloading, copying, installing or using the software you agree to this license.
- // If you do not agree to this license, do not download, install,
- // copy or use the software.
- //
- //
- // License Agreement
- // For Open Source Computer Vision Library
- //
- // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
- // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
- // Third party copyrights are property of their respective owners.
- //
- // Redistribution and use in source and binary forms, with or without modification,
- // are permitted provided that the following conditions are met:
- //
- // * Redistribution's of source code must retain the above copyright notice,
- // this list of conditions and the following disclaimer.
- //
- // * Redistribution's in binary form must reproduce the above copyright notice,
- // this list of conditions and the following disclaimer in the documentation
- // and/or other materials provided with the distribution.
- //
- // * The name of the copyright holders may not be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // This software is provided by the copyright holders and contributors "as is" and
- // any express or implied warranties, including, but not limited to, the implied
- // warranties of merchantability and fitness for a particular purpose are disclaimed.
- // In no event shall the Intel Corporation or contributors be liable for any direct,
- // indirect, incidental, special, exemplary, or consequential damages
- // (including, but not limited to, procurement of substitute goods or services;
- // loss of use, data, or profits; or business interruption) however caused
- // and on any theory of liability, whether in contract, strict liability,
- // or tort (including negligence or otherwise) arising in any way out of
- // the use of this software, even if advised of the possibility of such damage.
- //
- //M*/
- #include "perf_precomp.hpp"
- namespace opencv_test { namespace {
- #define ARITHM_MAT_DEPTH Values(CV_8U, CV_16U, CV_32F, CV_64F)
- //////////////////////////////////////////////////////////////////////
- // Merge
- DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, MatCn);
- PERF_TEST_P(Sz_Depth_Cn, Merge,
- Combine(CUDA_TYPICAL_MAT_SIZES,
- ARITHM_MAT_DEPTH,
- Values(2, 3, 4)))
- {
- const cv::Size size = GET_PARAM(0);
- const int depth = GET_PARAM(1);
- const int channels = GET_PARAM(2);
- std::vector<cv::Mat> src(channels);
- for (int i = 0; i < channels; ++i)
- {
- src[i].create(size, depth);
- declare.in(src[i], WARMUP_RNG);
- }
- if (PERF_RUN_CUDA())
- {
- std::vector<cv::cuda::GpuMat> d_src(channels);
- for (int i = 0; i < channels; ++i)
- d_src[i].upload(src[i]);
- cv::cuda::GpuMat dst;
- TEST_CYCLE() cv::cuda::merge(d_src, dst);
- CUDA_SANITY_CHECK(dst, 1e-10);
- }
- else
- {
- cv::Mat dst;
- TEST_CYCLE() cv::merge(src, dst);
- CPU_SANITY_CHECK(dst);
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Split
- PERF_TEST_P(Sz_Depth_Cn, Split,
- Combine(CUDA_TYPICAL_MAT_SIZES,
- ARITHM_MAT_DEPTH,
- Values(2, 3, 4)))
- {
- const cv::Size size = GET_PARAM(0);
- const int depth = GET_PARAM(1);
- const int channels = GET_PARAM(2);
- cv::Mat src(size, CV_MAKE_TYPE(depth, channels));
- declare.in(src, WARMUP_RNG);
- if (PERF_RUN_CUDA())
- {
- const cv::cuda::GpuMat d_src(src);
- std::vector<cv::cuda::GpuMat> dst;
- TEST_CYCLE() cv::cuda::split(d_src, dst);
- const cv::cuda::GpuMat& dst0 = dst[0];
- const cv::cuda::GpuMat& dst1 = dst[1];
- CUDA_SANITY_CHECK(dst0, 1e-10);
- CUDA_SANITY_CHECK(dst1, 1e-10);
- }
- else
- {
- std::vector<cv::Mat> dst;
- TEST_CYCLE() cv::split(src, dst);
- const cv::Mat& dst0 = dst[0];
- const cv::Mat& dst1 = dst[1];
- CPU_SANITY_CHECK(dst0);
- CPU_SANITY_CHECK(dst1);
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Transpose
- PERF_TEST_P(Sz_Type, Transpose,
- Combine(CUDA_TYPICAL_MAT_SIZES,
- Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_16SC2, CV_32SC1, CV_32SC2, CV_64FC1)))
- {
- const cv::Size size = GET_PARAM(0);
- const int type = GET_PARAM(1);
- cv::Mat src(size, type);
- declare.in(src, WARMUP_RNG);
- if (PERF_RUN_CUDA())
- {
- const cv::cuda::GpuMat d_src(src);
- cv::cuda::GpuMat dst;
- TEST_CYCLE() cv::cuda::transpose(d_src, dst);
- CUDA_SANITY_CHECK(dst, 1e-10);
- }
- else
- {
- cv::Mat dst;
- TEST_CYCLE() cv::transpose(src, dst);
- CPU_SANITY_CHECK(dst);
- }
- }
- //////////////////////////////////////////////////////////////////////
- // Flip
- enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
- CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
- DEF_PARAM_TEST(Sz_Depth_Cn_Code, cv::Size, MatDepth, MatCn, FlipCode);
- PERF_TEST_P(Sz_Depth_Cn_Code, Flip,
- Combine(CUDA_TYPICAL_MAT_SIZES,
- Values(CV_8U, CV_16U, CV_32F),
- CUDA_CHANNELS_1_3_4,
- FlipCode::all()))
- {
- const cv::Size size = GET_PARAM(0);
- const int depth = GET_PARAM(1);
- const int channels = GET_PARAM(2);
- const int flipCode = GET_PARAM(3);
- const int type = CV_MAKE_TYPE(depth, channels);
- cv::Mat src(size, type);
- declare.in(src, WARMUP_RNG);
- if (PERF_RUN_CUDA())
- {
- const cv::cuda::GpuMat d_src(src);
- cv::cuda::GpuMat dst;
- TEST_CYCLE() cv::cuda::flip(d_src, dst, flipCode);
- CUDA_SANITY_CHECK(dst);
- }
- else
- {
- cv::Mat dst;
- TEST_CYCLE() cv::flip(src, dst, flipCode);
- CPU_SANITY_CHECK(dst);
- }
- }
- //////////////////////////////////////////////////////////////////////
- // LutOneChannel
- PERF_TEST_P(Sz_Type, LutOneChannel,
- Combine(CUDA_TYPICAL_MAT_SIZES,
- Values(CV_8UC1, CV_8UC3)))
- {
- const cv::Size size = GET_PARAM(0);
- const int type = GET_PARAM(1);
- cv::Mat src(size, type);
- declare.in(src, WARMUP_RNG);
- cv::Mat lut(1, 256, CV_8UC1);
- declare.in(lut, WARMUP_RNG);
- if (PERF_RUN_CUDA())
- {
- cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
- const cv::cuda::GpuMat d_src(src);
- cv::cuda::GpuMat dst;
- TEST_CYCLE() lutAlg->transform(d_src, dst);
- CUDA_SANITY_CHECK(dst);
- }
- else
- {
- cv::Mat dst;
- TEST_CYCLE() cv::LUT(src, lut, dst);
- CPU_SANITY_CHECK(dst);
- }
- }
- //////////////////////////////////////////////////////////////////////
- // LutMultiChannel
- PERF_TEST_P(Sz_Type, LutMultiChannel,
- Combine(CUDA_TYPICAL_MAT_SIZES,
- Values<MatType>(CV_8UC3)))
- {
- const cv::Size size = GET_PARAM(0);
- const int type = GET_PARAM(1);
- cv::Mat src(size, type);
- declare.in(src, WARMUP_RNG);
- cv::Mat lut(1, 256, CV_MAKE_TYPE(CV_8U, src.channels()));
- declare.in(lut, WARMUP_RNG);
- if (PERF_RUN_CUDA())
- {
- cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
- const cv::cuda::GpuMat d_src(src);
- cv::cuda::GpuMat dst;
- TEST_CYCLE() lutAlg->transform(d_src, dst);
- CUDA_SANITY_CHECK(dst);
- }
- else
- {
- cv::Mat dst;
- TEST_CYCLE() cv::LUT(src, lut, dst);
- CPU_SANITY_CHECK(dst);
- }
- }
- //////////////////////////////////////////////////////////////////////
- // CopyMakeBorder
- DEF_PARAM_TEST(Sz_Depth_Cn_Border, cv::Size, MatDepth, MatCn, BorderMode);
- PERF_TEST_P(Sz_Depth_Cn_Border, CopyMakeBorder,
- Combine(CUDA_TYPICAL_MAT_SIZES,
- Values(CV_8U, CV_16U, CV_32F),
- CUDA_CHANNELS_1_3_4,
- ALL_BORDER_MODES))
- {
- const cv::Size size = GET_PARAM(0);
- const int depth = GET_PARAM(1);
- const int channels = GET_PARAM(2);
- const int borderMode = GET_PARAM(3);
- const int type = CV_MAKE_TYPE(depth, channels);
- cv::Mat src(size, type);
- declare.in(src, WARMUP_RNG);
- if (PERF_RUN_CUDA())
- {
- const cv::cuda::GpuMat d_src(src);
- cv::cuda::GpuMat dst;
- TEST_CYCLE() cv::cuda::copyMakeBorder(d_src, dst, 5, 5, 5, 5, borderMode);
- CUDA_SANITY_CHECK(dst);
- }
- else
- {
- cv::Mat dst;
- TEST_CYCLE() cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderMode);
- CPU_SANITY_CHECK(dst);
- }
- }
- }} // namespace
|