1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
43 #include "perf_precomp.hpp"
47 #include "opencv2/ocl/ocl.hpp"
49 using namespace testing;
52 using namespace cv::superres;
56 class OneFrameSource_OCL : public FrameSource
59 explicit OneFrameSource_OCL(const ocl::oclMat& frame) : frame_(frame) {}
61 void nextFrame(OutputArray frame)
63 ocl::getOclMatRef(frame) = frame_;
74 class ZeroOpticalFlowOCL : public DenseOpticalFlowExt
77 void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
79 ocl::oclMat& frame0_ = ocl::getOclMatRef(frame0);
80 ocl::oclMat& flow1_ = ocl::getOclMatRef(flow1);
81 ocl::oclMat& flow2_ = ocl::getOclMatRef(flow2);
83 cv::Size size = frame0_.size();
87 flow1_.create(size, CV_32FC2);
88 flow1_.setTo(Scalar::all(0));
92 flow1_.create(size, CV_32FC1);
93 flow2_.create(size, CV_32FC1);
95 flow1_.setTo(Scalar::all(0));
96 flow2_.setTo(Scalar::all(0));
100 void collectGarbage()
106 PERF_TEST_P(Size_MatType, SuperResolution_BTVL1_OCL,
107 Combine(Values(szSmall64, szSmall128),
108 Values(MatType(CV_8UC1), MatType(CV_8UC3))))
110 std::vector<cv::ocl::Info>info;
111 cv::ocl::getDevice(info);
113 declare.time(5 * 60);
115 const Size size = std::tr1::get<0>(GetParam());
116 const int type = std::tr1::get<1>(GetParam());
118 Mat frame(size, type);
119 declare.in(frame, WARMUP_RNG);
121 ocl::oclMat frame_ocl;
122 frame_ocl.upload(frame);
126 const int iterations = 50;
127 const int temporalAreaRadius = 1;
128 Ptr<DenseOpticalFlowExt> opticalFlowOcl(new ZeroOpticalFlowOCL);
130 Ptr<SuperResolution> superRes_ocl = createSuperResolution_BTVL1_OCL();
132 superRes_ocl->set("scale", scale);
133 superRes_ocl->set("iterations", iterations);
134 superRes_ocl->set("temporalAreaRadius", temporalAreaRadius);
135 superRes_ocl->set("opticalFlow", opticalFlowOcl);
137 superRes_ocl->setInput(new OneFrameSource_OCL(frame_ocl));
140 superRes_ocl->nextFrame(dst_ocl);
142 TEST_CYCLE_N(10) superRes_ocl->nextFrame(dst_ocl);
144 CPU_SANITY_CHECK(dst_ocl);