perf_bgfg_utils.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. namespace opencv_test {
  5. //#define DEBUG_BGFG
  6. using namespace testing;
  7. using namespace cvtest;
  8. using namespace perf;
  9. namespace {
  10. using namespace cv;
  11. static void cvtFrameFmt(std::vector<Mat>& input, std::vector<Mat>& output)
  12. {
  13. for(int i = 0; i< (int)(input.size()); i++)
  14. {
  15. cvtColor(input[i], output[i], COLOR_RGB2GRAY);
  16. }
  17. }
  18. static void prepareData(VideoCapture& cap, int cn, std::vector<Mat>& frame_buffer, int skipFrames = 0)
  19. {
  20. std::vector<Mat> frame_buffer_init;
  21. int nFrame = (int)frame_buffer.size();
  22. for (int i = 0; i < skipFrames; i++)
  23. {
  24. cv::Mat frame;
  25. cap >> frame;
  26. }
  27. for (int i = 0; i < nFrame; i++)
  28. {
  29. cv::Mat frame;
  30. cap >> frame;
  31. ASSERT_FALSE(frame.empty());
  32. frame_buffer_init.push_back(frame);
  33. }
  34. if (cn == 1)
  35. cvtFrameFmt(frame_buffer_init, frame_buffer);
  36. else
  37. frame_buffer.swap(frame_buffer_init);
  38. }
  39. }}