perf_superres.cpp 5.6 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
/*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"

using namespace std;
using namespace std::tr1;
using namespace testing;
using namespace perf;
using namespace cv;
using namespace cv::superres;
wester committed
51
using namespace cv::gpu;
wester committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

namespace
{
    class OneFrameSource_CPU : public FrameSource
    {
    public:
        explicit OneFrameSource_CPU(const Mat& frame) : frame_(frame) {}

        void nextFrame(OutputArray frame)
        {
            frame.getMatRef() = frame_;
        }

        void reset()
        {
        }

    private:
        Mat frame_;
    };

wester committed
73
    class OneFrameSource_GPU : public FrameSource
wester committed
74 75
    {
    public:
wester committed
76
        explicit OneFrameSource_GPU(const GpuMat& frame) : frame_(frame) {}
wester committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

        void nextFrame(OutputArray frame)
        {
            frame.getGpuMatRef() = frame_;
        }

        void reset()
        {
        }

    private:
        GpuMat frame_;
    };

    class ZeroOpticalFlow : public DenseOpticalFlowExt
    {
    public:
wester committed
94
        void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
wester committed
95 96 97 98 99 100
        {
            cv::Size size = frame0.size();

            if (!flow2.needed())
            {
                flow1.create(size, CV_32FC2);
wester committed
101 102 103 104 105

                if (flow1.kind() == cv::_InputArray::GPU_MAT)
                    flow1.getGpuMatRef().setTo(cv::Scalar::all(0));
                else
                    flow1.getMatRef().setTo(cv::Scalar::all(0));
wester committed
106 107 108 109 110 111
            }
            else
            {
                flow1.create(size, CV_32FC1);
                flow2.create(size, CV_32FC1);

wester committed
112 113 114 115 116 117 118 119 120
                if (flow1.kind() == cv::_InputArray::GPU_MAT)
                    flow1.getGpuMatRef().setTo(cv::Scalar::all(0));
                else
                    flow1.getMatRef().setTo(cv::Scalar::all(0));

                if (flow2.kind() == cv::_InputArray::GPU_MAT)
                    flow2.getGpuMatRef().setTo(cv::Scalar::all(0));
                else
                    flow2.getMatRef().setTo(cv::Scalar::all(0));
wester committed
121 122 123
            }
        }

wester committed
124
        void collectGarbage()
wester committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
        {
        }
    };
}

PERF_TEST_P(Size_MatType, SuperResolution_BTVL1,
            Combine(Values(szSmall64, szSmall128),
                    Values(MatType(CV_8UC1), MatType(CV_8UC3))))
{
    declare.time(5 * 60);

    const Size size = get<0>(GetParam());
    const int type = get<1>(GetParam());

    Mat frame(size, type);
    declare.in(frame, WARMUP_RNG);

    const int scale = 2;
    const int iterations = 50;
    const int temporalAreaRadius = 1;
    Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);

wester committed
147
    if (PERF_RUN_GPU())
wester committed
148
    {
wester committed
149
        Ptr<SuperResolution> superRes = createSuperResolution_BTVL1_GPU();
wester committed
150

wester committed
151 152 153 154
        superRes->set("scale", scale);
        superRes->set("iterations", iterations);
        superRes->set("temporalAreaRadius", temporalAreaRadius);
        superRes->set("opticalFlow", opticalFlow);
wester committed
155

wester committed
156
        superRes->setInput(new OneFrameSource_GPU(GpuMat(frame)));
wester committed
157 158 159 160 161 162

        GpuMat dst;
        superRes->nextFrame(dst);

        TEST_CYCLE_N(10) superRes->nextFrame(dst);

wester committed
163
        GPU_SANITY_CHECK(dst);
wester committed
164 165 166 167 168
    }
    else
    {
        Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();

wester committed
169 170 171 172
        superRes->set("scale", scale);
        superRes->set("iterations", iterations);
        superRes->set("temporalAreaRadius", temporalAreaRadius);
        superRes->set("opticalFlow", opticalFlow);
wester committed
173

wester committed
174
        superRes->setInput(new OneFrameSource_CPU(frame));
wester committed
175 176 177 178 179 180 181 182 183

        Mat dst;
        superRes->nextFrame(dst);

        TEST_CYCLE_N(10) superRes->nextFrame(dst);

        CPU_SANITY_CHECK(dst);
    }
}