Path: blob/master/modules/superres/perf/perf_superres.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.13// Copyright (C) 2009, Willow Garage Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// Redistribution and use in source and binary forms, with or without modification,17// are permitted provided that the following conditions are met:18//19// * Redistribution's of source code must retain the above copyright notice,20// this list of conditions and the following disclaimer.21//22// * Redistribution's in binary form must reproduce the above copyright notice,23// this list of conditions and the following disclaimer in the documentation24// and/or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// warranties of merchantability and fitness for a particular purpose are disclaimed.32// In no event shall the Intel Corporation or contributors be liable for any direct,33// indirect, incidental, special, exemplary, or consequential damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#include "perf_precomp.hpp"43#include "opencv2/ts/ocl_perf.hpp"4445namespace opencv_test46{47using namespace perf;48using namespace cv::superres;49using namespace cv::cuda;5051namespace52{53class OneFrameSource_CPU : public FrameSource54{55public:56explicit OneFrameSource_CPU(const Mat& frame) : frame_(frame) {}5758void nextFrame(OutputArray frame)59{60frame.getMatRef() = frame_;61}6263void reset()64{65}6667private:68Mat frame_;69};7071class OneFrameSource_CUDA : public FrameSource72{73public:74explicit OneFrameSource_CUDA(const GpuMat& frame) : frame_(frame) {}7576void nextFrame(OutputArray frame)77{78frame.getGpuMatRef() = frame_;79}8081void reset()82{83}8485private:86GpuMat frame_;87};8889class ZeroOpticalFlow : public DenseOpticalFlowExt90{91public:92virtual void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)93{94cv::Size size = frame0.size();9596if (!flow2.needed())97{98flow1.create(size, CV_32FC2);99flow1.setTo(cv::Scalar::all(0));100}101else102{103flow1.create(size, CV_32FC1);104flow2.create(size, CV_32FC1);105106flow1.setTo(cv::Scalar::all(0));107flow2.setTo(cv::Scalar::all(0));108}109}110111virtual void collectGarbage()112{113}114};115} // namespace116117PERF_TEST_P(Size_MatType, SuperResolution_BTVL1,118Combine(Values(szSmall64, szSmall128),119Values(MatType(CV_8UC1), MatType(CV_8UC3))))120{121declare.time(5 * 60);122123const Size size = get<0>(GetParam());124const int type = get<1>(GetParam());125126Mat frame(size, type);127declare.in(frame, WARMUP_RNG);128129const int scale = 2;130const int iterations = 50;131const int temporalAreaRadius = 1;132Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);133134if (PERF_RUN_CUDA())135{136Ptr<SuperResolution> superRes = createSuperResolution_BTVL1_CUDA();137138superRes->setScale(scale);139superRes->setIterations(iterations);140superRes->setTemporalAreaRadius(temporalAreaRadius);141superRes->setOpticalFlow(opticalFlow);142143superRes->setInput(makePtr<OneFrameSource_CUDA>(GpuMat(frame)));144145GpuMat dst;146superRes->nextFrame(dst);147148TEST_CYCLE_N(10) superRes->nextFrame(dst);149150CUDA_SANITY_CHECK(dst, 2);151}152else153{154Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();155156superRes->setScale(scale);157superRes->setIterations(iterations);158superRes->setTemporalAreaRadius(temporalAreaRadius);159superRes->setOpticalFlow(opticalFlow);160161superRes->setInput(makePtr<OneFrameSource_CPU>(frame));162163Mat dst;164superRes->nextFrame(dst);165166TEST_CYCLE_N(10) superRes->nextFrame(dst);167168CPU_SANITY_CHECK(dst);169}170}171172#ifdef HAVE_OPENCL173174namespace ocl {175176typedef Size_MatType SuperResolution_BTVL1;177178OCL_PERF_TEST_P(SuperResolution_BTVL1 ,BTVL1,179Combine(Values(szSmall64, szSmall128),180Values(MatType(CV_8UC1), MatType(CV_8UC3))))181{182Size_MatType_t params = GetParam();183const Size size = get<0>(params);184const int type = get<1>(params);185186Mat frame(size, type);187UMat dst(1, 1, 0);188declare.in(frame, WARMUP_RNG);189190const int scale = 2;191const int iterations = 50;192const int temporalAreaRadius = 1;193194Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);195Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();196197superRes->setScale(scale);198superRes->setIterations(iterations);199superRes->setTemporalAreaRadius(temporalAreaRadius);200superRes->setOpticalFlow(opticalFlow);201202superRes->setInput(makePtr<OneFrameSource_CPU>(frame));203204// skip first frame205superRes->nextFrame(dst);206207OCL_TEST_CYCLE_N(10) superRes->nextFrame(dst);208209SANITY_CHECK_NOTHING();210}211212} // namespace ocl213214#endif // HAVE_OPENCL215216} // namespace217218219