perf_video.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/videoio.hpp"
  44. namespace opencv_test { namespace {
  45. #if defined(HAVE_NVCUVID)
  46. #if defined(HAVE_FFMPEG_WRAPPER) // should this be set in preprocessor or in cvconfig.h
  47. #define VIDEO_SRC Values("cv/video/768x576.avi", "cv/video/1920x1080.avi")
  48. #else
  49. // CUDA demuxer has to fall back to ffmpeg to process "cv/video/768x576.avi"
  50. #define VIDEO_SRC Values( "cv/video/1920x1080.avi")
  51. #endif
  52. DEF_PARAM_TEST_1(FileName, string);
  53. //////////////////////////////////////////////////////
  54. // VideoReader
  55. PERF_TEST_P(FileName, VideoReader, VIDEO_SRC)
  56. {
  57. declare.time(20);
  58. const string inputFile = perf::TestBase::getDataPath(GetParam());
  59. if (PERF_RUN_CUDA())
  60. {
  61. cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(inputFile);
  62. cv::cuda::GpuMat frame;
  63. TEST_CYCLE_N(10) d_reader->nextFrame(frame);
  64. CUDA_SANITY_CHECK(frame);
  65. }
  66. else
  67. {
  68. cv::VideoCapture reader(inputFile);
  69. ASSERT_TRUE( reader.isOpened() );
  70. cv::Mat frame;
  71. TEST_CYCLE_N(10) reader >> frame;
  72. CPU_SANITY_CHECK(frame);
  73. }
  74. }
  75. #endif
  76. //////////////////////////////////////////////////////
  77. // VideoWriter
  78. #if defined(HAVE_NVCUVID) && defined(_WIN32)
  79. PERF_TEST_P(FileName, VideoWriter, VIDEO_SRC)
  80. {
  81. declare.time(30);
  82. const string inputFile = perf::TestBase::getDataPath(GetParam());
  83. const string outputFile = cv::tempfile(".avi");
  84. const double FPS = 25.0;
  85. cv::VideoCapture reader(inputFile);
  86. ASSERT_TRUE( reader.isOpened() );
  87. cv::Mat frame;
  88. if (PERF_RUN_CUDA())
  89. {
  90. cv::Ptr<cv::cudacodec::VideoWriter> d_writer;
  91. cv::cuda::GpuMat d_frame;
  92. for (int i = 0; i < 10; ++i)
  93. {
  94. reader >> frame;
  95. ASSERT_FALSE(frame.empty());
  96. d_frame.upload(frame);
  97. if (d_writer.empty())
  98. d_writer = cv::cudacodec::createVideoWriter(outputFile, frame.size(), FPS);
  99. startTimer(); next();
  100. d_writer->write(d_frame);
  101. stopTimer();
  102. }
  103. }
  104. else
  105. {
  106. cv::VideoWriter writer;
  107. for (int i = 0; i < 10; ++i)
  108. {
  109. reader >> frame;
  110. ASSERT_FALSE(frame.empty());
  111. if (!writer.isOpened())
  112. writer.open(outputFile, VideoWriter::fourcc('X', 'V', 'I', 'D'), FPS, frame.size());
  113. startTimer(); next();
  114. writer.write(frame);
  115. stopTimer();
  116. }
  117. }
  118. SANITY_CHECK(frame);
  119. }
  120. #endif
  121. }} // namespace