Merge pull request #1263 from abidrahmank:pyCLAHE_24
[profile/ivi/opencv.git] / modules / superres / perf / perf_superres_ocl.cpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
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.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
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.
26 //
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.
29 //
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.
40 //
41 //M*/
42
43 #include "perf_precomp.hpp"
44
45 #ifdef HAVE_OPENCL
46
47 #include "opencv2/ocl/ocl.hpp"
48 using namespace std;
49 using namespace testing;
50 using namespace perf;
51 using namespace cv;
52 using namespace cv::superres;
53
54 namespace
55 {
56     class OneFrameSource_OCL : public FrameSource
57     {
58     public:
59         explicit OneFrameSource_OCL(const ocl::oclMat& frame) : frame_(frame) {}
60
61         void nextFrame(OutputArray frame)
62         {
63             ocl::getOclMatRef(frame) = frame_;
64         }
65         void reset()
66         {
67         }
68
69     private:
70         ocl::oclMat frame_;
71     };
72
73
74     class ZeroOpticalFlowOCL : public DenseOpticalFlowExt
75     {
76     public:
77         void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
78         {
79             ocl::oclMat& frame0_ = ocl::getOclMatRef(frame0);
80             ocl::oclMat& flow1_ = ocl::getOclMatRef(flow1);
81             ocl::oclMat& flow2_ = ocl::getOclMatRef(flow2);
82
83             cv::Size size = frame0_.size();
84
85             if(!flow2.needed())
86             {
87                 flow1_.create(size, CV_32FC2);
88                 flow1_.setTo(Scalar::all(0));
89             }
90             else
91             {
92                 flow1_.create(size, CV_32FC1);
93                 flow2_.create(size, CV_32FC1);
94
95                 flow1_.setTo(Scalar::all(0));
96                 flow2_.setTo(Scalar::all(0));
97             }
98         }
99
100         void collectGarbage()
101         {
102         }
103     };
104 }
105
106 PERF_TEST_P(Size_MatType, SuperResolution_BTVL1_OCL,
107     Combine(Values(szSmall64, szSmall128),
108     Values(MatType(CV_8UC1), MatType(CV_8UC3))))
109 {
110     std::vector<cv::ocl::Info>info;
111     cv::ocl::getDevice(info);
112
113     declare.time(5 * 60);
114
115     const Size size = std::tr1::get<0>(GetParam());
116     const int type = std::tr1::get<1>(GetParam());
117
118     Mat frame(size, type);
119     declare.in(frame, WARMUP_RNG);
120
121     ocl::oclMat frame_ocl;
122     frame_ocl.upload(frame);
123
124
125     const int scale = 2;
126     const int iterations = 50;
127     const int temporalAreaRadius = 1;
128     Ptr<DenseOpticalFlowExt> opticalFlowOcl(new ZeroOpticalFlowOCL);
129
130     Ptr<SuperResolution> superRes_ocl = createSuperResolution_BTVL1_OCL();
131
132     superRes_ocl->set("scale", scale);
133     superRes_ocl->set("iterations", iterations);
134     superRes_ocl->set("temporalAreaRadius", temporalAreaRadius);
135     superRes_ocl->set("opticalFlow", opticalFlowOcl);
136
137     superRes_ocl->setInput(new OneFrameSource_OCL(frame_ocl));
138
139     ocl::oclMat dst_ocl;
140     superRes_ocl->nextFrame(dst_ocl);
141
142     TEST_CYCLE_N(10) superRes_ocl->nextFrame(dst_ocl);
143     frame_ocl.release();
144     CPU_SANITY_CHECK(dst_ocl);
145 }
146 #endif