perf_superres.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage 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. #include "perf_precomp.hpp"
  43. #include "opencv2/ts/ocl_perf.hpp"
  44. namespace opencv_test
  45. {
  46. using namespace perf;
  47. using namespace cv::superres;
  48. using namespace cv::cuda;
  49. namespace
  50. {
  51. class OneFrameSource_CPU : public FrameSource
  52. {
  53. public:
  54. explicit OneFrameSource_CPU(const Mat& frame) : frame_(frame) {}
  55. void nextFrame(OutputArray frame)
  56. {
  57. frame.getMatRef() = frame_;
  58. }
  59. void reset()
  60. {
  61. }
  62. private:
  63. Mat frame_;
  64. };
  65. class OneFrameSource_CUDA : public FrameSource
  66. {
  67. public:
  68. explicit OneFrameSource_CUDA(const GpuMat& frame) : frame_(frame) {}
  69. void nextFrame(OutputArray frame)
  70. {
  71. frame.getGpuMatRef() = frame_;
  72. }
  73. void reset()
  74. {
  75. }
  76. private:
  77. GpuMat frame_;
  78. };
  79. class ZeroOpticalFlow : public DenseOpticalFlowExt
  80. {
  81. public:
  82. virtual void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
  83. {
  84. cv::Size size = frame0.size();
  85. if (!flow2.needed())
  86. {
  87. flow1.create(size, CV_32FC2);
  88. flow1.setTo(cv::Scalar::all(0));
  89. }
  90. else
  91. {
  92. flow1.create(size, CV_32FC1);
  93. flow2.create(size, CV_32FC1);
  94. flow1.setTo(cv::Scalar::all(0));
  95. flow2.setTo(cv::Scalar::all(0));
  96. }
  97. }
  98. virtual void collectGarbage()
  99. {
  100. }
  101. };
  102. } // namespace
  103. PERF_TEST_P(Size_MatType, SuperResolution_BTVL1,
  104. Combine(Values(szSmall64, szSmall128),
  105. Values(MatType(CV_8UC1), MatType(CV_8UC3))))
  106. {
  107. declare.time(5 * 60);
  108. const Size size = get<0>(GetParam());
  109. const int type = get<1>(GetParam());
  110. Mat frame(size, type);
  111. declare.in(frame, WARMUP_RNG);
  112. const int scale = 2;
  113. const int iterations = 50;
  114. const int temporalAreaRadius = 1;
  115. Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);
  116. if (PERF_RUN_CUDA())
  117. {
  118. Ptr<SuperResolution> superRes = createSuperResolution_BTVL1_CUDA();
  119. superRes->setScale(scale);
  120. superRes->setIterations(iterations);
  121. superRes->setTemporalAreaRadius(temporalAreaRadius);
  122. superRes->setOpticalFlow(opticalFlow);
  123. superRes->setInput(makePtr<OneFrameSource_CUDA>(GpuMat(frame)));
  124. GpuMat dst;
  125. superRes->nextFrame(dst);
  126. TEST_CYCLE_N(10) superRes->nextFrame(dst);
  127. CUDA_SANITY_CHECK(dst, 2);
  128. }
  129. else
  130. {
  131. Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();
  132. superRes->setScale(scale);
  133. superRes->setIterations(iterations);
  134. superRes->setTemporalAreaRadius(temporalAreaRadius);
  135. superRes->setOpticalFlow(opticalFlow);
  136. superRes->setInput(makePtr<OneFrameSource_CPU>(frame));
  137. Mat dst;
  138. superRes->nextFrame(dst);
  139. TEST_CYCLE_N(10) superRes->nextFrame(dst);
  140. CPU_SANITY_CHECK(dst);
  141. }
  142. }
  143. #ifdef HAVE_OPENCL
  144. namespace ocl {
  145. typedef Size_MatType SuperResolution_BTVL1;
  146. OCL_PERF_TEST_P(SuperResolution_BTVL1 ,BTVL1,
  147. Combine(Values(szSmall64, szSmall128),
  148. Values(MatType(CV_8UC1), MatType(CV_8UC3))))
  149. {
  150. Size_MatType_t params = GetParam();
  151. const Size size = get<0>(params);
  152. const int type = get<1>(params);
  153. Mat frame(size, type);
  154. UMat dst(1, 1, 0);
  155. declare.in(frame, WARMUP_RNG);
  156. const int scale = 2;
  157. const int iterations = 50;
  158. const int temporalAreaRadius = 1;
  159. Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);
  160. Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();
  161. superRes->setScale(scale);
  162. superRes->setIterations(iterations);
  163. superRes->setTemporalAreaRadius(temporalAreaRadius);
  164. superRes->setOpticalFlow(opticalFlow);
  165. superRes->setInput(makePtr<OneFrameSource_CPU>(frame));
  166. // skip first frame
  167. superRes->nextFrame(dst);
  168. OCL_TEST_CYCLE_N(10) superRes->nextFrame(dst);
  169. SANITY_CHECK_NOTHING();
  170. }
  171. } // namespace ocl
  172. #endif // HAVE_OPENCL
  173. } // namespace