perf_bgsegm.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. #ifdef HAVE_OPENCV_CUDAIMGPROC
  44. # include "opencv2/cudaimgproc.hpp"
  45. #endif
  46. namespace opencv_test { namespace {
  47. //////////////////////////////////////////////////////
  48. // FGDStatModel
  49. #ifdef HAVE_VIDEO_INPUT
  50. DEF_PARAM_TEST_1(Video, string);
  51. PERF_TEST_P(Video, FGDStatModel,
  52. Values(string("cv/video/768x576.avi")))
  53. {
  54. const int numIters = 10;
  55. declare.time(60);
  56. const string inputFile = perf::TestBase::getDataPath(GetParam());
  57. cv::VideoCapture cap(inputFile);
  58. ASSERT_TRUE(cap.isOpened());
  59. cv::Mat frame;
  60. cap >> frame;
  61. ASSERT_FALSE(frame.empty());
  62. if (PERF_RUN_CUDA())
  63. {
  64. cv::cuda::GpuMat d_frame(frame), foreground;
  65. cv::Ptr<cv::cuda::BackgroundSubtractorFGD> d_fgd = cv::cuda::createBackgroundSubtractorFGD();
  66. d_fgd->apply(d_frame, foreground);
  67. int i = 0;
  68. // collect performance data
  69. for (; i < numIters; ++i)
  70. {
  71. cap >> frame;
  72. ASSERT_FALSE(frame.empty());
  73. d_frame.upload(frame);
  74. startTimer();
  75. if(!next())
  76. break;
  77. d_fgd->apply(d_frame, foreground);
  78. stopTimer();
  79. }
  80. // process last frame in sequence to get data for sanity test
  81. for (; i < numIters; ++i)
  82. {
  83. cap >> frame;
  84. ASSERT_FALSE(frame.empty());
  85. d_frame.upload(frame);
  86. d_fgd->apply(d_frame, foreground);
  87. }
  88. }
  89. else
  90. {
  91. FAIL_NO_CPU();
  92. }
  93. SANITY_CHECK_NOTHING();
  94. }
  95. #endif
  96. //////////////////////////////////////////////////////
  97. // GMG
  98. #ifdef HAVE_VIDEO_INPUT
  99. DEF_PARAM_TEST(Video_Cn_MaxFeatures, string, MatCn, int);
  100. PERF_TEST_P(Video_Cn_MaxFeatures, GMG,
  101. Combine(Values(string("cv/video/768x576.avi")),
  102. CUDA_CHANNELS_1_3_4,
  103. Values(20, 40, 60)))
  104. {
  105. const int numIters = 150;
  106. const std::string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
  107. const int cn = GET_PARAM(1);
  108. const int maxFeatures = GET_PARAM(2);
  109. cv::VideoCapture cap(inputFile);
  110. ASSERT_TRUE(cap.isOpened());
  111. cv::Mat frame;
  112. cap >> frame;
  113. ASSERT_FALSE(frame.empty());
  114. if (cn != 3)
  115. {
  116. cv::Mat temp;
  117. if (cn == 1)
  118. cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
  119. else
  120. cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
  121. cv::swap(temp, frame);
  122. }
  123. if (PERF_RUN_CUDA())
  124. {
  125. cv::cuda::GpuMat d_frame(frame);
  126. cv::cuda::GpuMat foreground;
  127. cv::Ptr<cv::cuda::BackgroundSubtractorGMG> d_gmg = cv::cuda::createBackgroundSubtractorGMG();
  128. d_gmg->setMaxFeatures(maxFeatures);
  129. d_gmg->apply(d_frame, foreground);
  130. int i = 0;
  131. // collect performance data
  132. for (; i < numIters; ++i)
  133. {
  134. cap >> frame;
  135. if (frame.empty())
  136. {
  137. cap.release();
  138. cap.open(inputFile);
  139. cap >> frame;
  140. }
  141. if (cn != 3)
  142. {
  143. cv::Mat temp;
  144. if (cn == 1)
  145. cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
  146. else
  147. cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
  148. cv::swap(temp, frame);
  149. }
  150. d_frame.upload(frame);
  151. startTimer();
  152. if(!next())
  153. break;
  154. d_gmg->apply(d_frame, foreground);
  155. stopTimer();
  156. }
  157. // process last frame in sequence to get data for sanity test
  158. for (; i < numIters; ++i)
  159. {
  160. cap >> frame;
  161. if (frame.empty())
  162. {
  163. cap.release();
  164. cap.open(inputFile);
  165. cap >> frame;
  166. }
  167. if (cn != 3)
  168. {
  169. cv::Mat temp;
  170. if (cn == 1)
  171. cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
  172. else
  173. cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA);
  174. cv::swap(temp, frame);
  175. }
  176. d_frame.upload(frame);
  177. d_gmg->apply(d_frame, foreground);
  178. }
  179. }
  180. else
  181. {
  182. FAIL_NO_CPU();
  183. }
  184. SANITY_CHECK_NOTHING();
  185. }
  186. #endif
  187. }} // namespace