perf_3vs4.cpp 3.45 KB
Newer Older
wester committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.

#include "../perf_precomp.hpp"
#include "opencv2/ts/ocl_perf.hpp"

#ifdef HAVE_OPENCL

namespace cvtest {
namespace ocl {

///////////// 3 channels Vs 4 ////////////////////////

enum
{
    Pure = 0, Split, Convert
};

CV_ENUM(Modes, Pure, Split, Convert)

typedef tuple <Size, MatType, Modes> _3vs4Params;
typedef TestBaseWithParam<_3vs4Params> _3vs4_Fixture;

OCL_PERF_TEST_P(_3vs4_Fixture, Resize,
                ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC3, CV_32FC3), Modes::all()))
{
    _3vs4Params params = GetParam();
    const Size srcSize = get<0>(params);
    const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
    const int mode = get<2>(params);

    checkDeviceMaxMemoryAllocSize(srcSize, type);

    UMat src(srcSize, type), dst(srcSize, type);
    declare.in(src, WARMUP_RNG).out(dst);

    if (mode == Pure)
    {
        OCL_TEST_CYCLE() resize(src, dst, Size(), 0.5, 0.5, INTER_LINEAR);
    }
    else if (mode == Split)
    {
        std::vector<UMat> srcs(3), dsts(3);

        for (int i = 0; i < 3; ++i)
        {
            dsts[i] = UMat(srcSize, depth);
            srcs[i] = UMat(srcSize, depth);
        }

        OCL_TEST_CYCLE()
        {
            split(src, srcs);

            for (size_t i = 0; i < srcs.size(); ++i)
                resize(srcs[i], dsts[i], Size(), 0.5, 0.5, INTER_LINEAR);

            merge(dsts, dst);
        }
    }
    else if (mode == Convert)
    {
        int type4 = CV_MAKE_TYPE(depth, 4);
        UMat src4(srcSize, type4), dst4(srcSize, type4);

        OCL_TEST_CYCLE()
        {
            cvtColor(src, src4, COLOR_RGB2RGBA);
            resize(src4, dst4, Size(), 0.5, 0.5, INTER_LINEAR);
            cvtColor(dst4, dst, COLOR_RGBA2RGB);
        }
    }

    SANITY_CHECK_NOTHING();
}

OCL_PERF_TEST_P(_3vs4_Fixture, Subtract,
                ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC3, CV_32FC3), Modes::all()))
{
    _3vs4Params params = GetParam();
    const Size srcSize = get<0>(params);
    const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
    const int mode = get<2>(params);

    checkDeviceMaxMemoryAllocSize(srcSize, type);

    Scalar s(14);
    UMat src(srcSize, type), dst(srcSize, type);
    declare.in(src, WARMUP_RNG).out(dst);

    if (mode == Pure)
    {
        OCL_TEST_CYCLE() subtract(src, s, dst);
    }
    else if (mode == Split)
    {
        std::vector<UMat> srcs(3), dsts(3);

        for (int i = 0; i < 3; ++i)
        {
            dsts[i] = UMat(srcSize, depth);
            srcs[i] = UMat(srcSize, depth);
        }

        OCL_TEST_CYCLE()
        {
            split(src, srcs);

            for (size_t i = 0; i < srcs.size(); ++i)
                subtract(srcs[i], s, dsts[i]);

            merge(dsts, dst);
        }
    }
    else if (mode == Convert)
    {
        int type4 = CV_MAKE_TYPE(depth, 4);
        UMat src4(srcSize, type4), dst4(srcSize, type4);

        OCL_TEST_CYCLE()
        {
            cvtColor(src, src4, COLOR_RGB2RGBA);
            subtract(src4, s, dst4);
            cvtColor(dst4, dst, COLOR_RGBA2RGB);
        }
    }

    SANITY_CHECK_NOTHING();
}

} } // namespace cvtest::ocl

#endif // HAVE_OPENCL