Path: blob/master/modules/imgproc/perf/opencl/perf_3vs4.cpp
16344 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.34// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.5// Third party copyrights are property of their respective owners.67#include "../perf_precomp.hpp"8#include "opencv2/ts/ocl_perf.hpp"910#ifdef HAVE_OPENCL1112namespace opencv_test {13namespace ocl {1415///////////// 3 channels Vs 4 ////////////////////////1617enum18{19Pure = 0, Split, Convert20};2122CV_ENUM(Modes, Pure, Split, Convert)2324typedef tuple <Size, MatType, Modes> _3vs4Params;25typedef TestBaseWithParam<_3vs4Params> _3vs4_Fixture;2627OCL_PERF_TEST_P(_3vs4_Fixture, Resize,28::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC3, CV_32FC3), Modes::all()))29{30_3vs4Params params = GetParam();31const Size srcSize = get<0>(params);32const int type = get<1>(params), depth = CV_MAT_DEPTH(type);33const int mode = get<2>(params);3435checkDeviceMaxMemoryAllocSize(srcSize, type);3637UMat src(srcSize, type), dst(srcSize, type);38declare.in(src, WARMUP_RNG).out(dst);3940if (mode == Pure)41{42OCL_TEST_CYCLE() resize(src, dst, Size(), 0.5, 0.5, INTER_LINEAR_EXACT);43}44else if (mode == Split)45{46std::vector<UMat> srcs(3), dsts(3);4748for (int i = 0; i < 3; ++i)49{50dsts[i] = UMat(srcSize, depth);51srcs[i] = UMat(srcSize, depth);52}5354OCL_TEST_CYCLE()55{56split(src, srcs);5758for (size_t i = 0; i < srcs.size(); ++i)59resize(srcs[i], dsts[i], Size(), 0.5, 0.5, INTER_LINEAR_EXACT);6061merge(dsts, dst);62}63}64else if (mode == Convert)65{66int type4 = CV_MAKE_TYPE(depth, 4);67UMat src4(srcSize, type4), dst4(srcSize, type4);6869OCL_TEST_CYCLE()70{71cvtColor(src, src4, COLOR_RGB2RGBA);72resize(src4, dst4, Size(), 0.5, 0.5, INTER_LINEAR_EXACT);73cvtColor(dst4, dst, COLOR_RGBA2RGB);74}75}7677SANITY_CHECK_NOTHING();78}7980OCL_PERF_TEST_P(_3vs4_Fixture, Subtract,81::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC3, CV_32FC3), Modes::all()))82{83_3vs4Params params = GetParam();84const Size srcSize = get<0>(params);85const int type = get<1>(params), depth = CV_MAT_DEPTH(type);86const int mode = get<2>(params);8788checkDeviceMaxMemoryAllocSize(srcSize, type);8990Scalar s(14);91UMat src(srcSize, type), dst(srcSize, type);92declare.in(src, WARMUP_RNG).out(dst);9394if (mode == Pure)95{96OCL_TEST_CYCLE() subtract(src, s, dst);97}98else if (mode == Split)99{100std::vector<UMat> srcs(3), dsts(3);101102for (int i = 0; i < 3; ++i)103{104dsts[i] = UMat(srcSize, depth);105srcs[i] = UMat(srcSize, depth);106}107108OCL_TEST_CYCLE()109{110split(src, srcs);111112for (size_t i = 0; i < srcs.size(); ++i)113subtract(srcs[i], s, dsts[i]);114115merge(dsts, dst);116}117}118else if (mode == Convert)119{120int type4 = CV_MAKE_TYPE(depth, 4);121UMat src4(srcSize, type4), dst4(srcSize, type4);122123OCL_TEST_CYCLE()124{125cvtColor(src, src4, COLOR_RGB2RGBA);126subtract(src4, s, dst4);127cvtColor(dst4, dst, COLOR_RGBA2RGB);128}129}130131SANITY_CHECK_NOTHING();132}133134} } // namespace opencv_test::ocl135136#endif // HAVE_OPENCL137138139