perf_disflow.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "perf_precomp.hpp"
  5. namespace opencv_test { namespace {
  6. void MakeArtificialExample(Mat &dst_frame1, Mat &dst_frame2);
  7. typedef tuple<String, Size> DISParams;
  8. typedef TestBaseWithParam<DISParams> DenseOpticalFlow_DIS;
  9. PERF_TEST_P(DenseOpticalFlow_DIS, perf,
  10. Combine(Values("PRESET_ULTRAFAST", "PRESET_FAST", "PRESET_MEDIUM"), Values(szVGA, sz720p, sz1080p)))
  11. {
  12. DISParams params = GetParam();
  13. // use strings to print preset names in the perf test results:
  14. String preset_string = get<0>(params);
  15. int preset = DISOpticalFlow::PRESET_FAST;
  16. if (preset_string == "PRESET_ULTRAFAST")
  17. preset = DISOpticalFlow::PRESET_ULTRAFAST;
  18. else if (preset_string == "PRESET_FAST")
  19. preset = DISOpticalFlow::PRESET_FAST;
  20. else if (preset_string == "PRESET_MEDIUM")
  21. preset = DISOpticalFlow::PRESET_MEDIUM;
  22. Size sz = get<1>(params);
  23. Mat frame1(sz, CV_8U);
  24. Mat frame2(sz, CV_8U);
  25. Mat flow;
  26. MakeArtificialExample(frame1, frame2);
  27. TEST_CYCLE_N(10)
  28. {
  29. Ptr<DenseOpticalFlow> algo = DISOpticalFlow::create(preset);
  30. algo->calc(frame1, frame2, flow);
  31. }
  32. SANITY_CHECK_NOTHING();
  33. }
  34. void MakeArtificialExample(Mat &dst_frame1, Mat &dst_frame2)
  35. {
  36. int src_scale = 2;
  37. int OF_scale = 6;
  38. double sigma = dst_frame1.cols / 300;
  39. Mat tmp(Size(dst_frame1.cols / (1 << src_scale), dst_frame1.rows / (1 << src_scale)), CV_8U);
  40. randu(tmp, 0, 255);
  41. resize(tmp, dst_frame1, dst_frame1.size(), 0.0, 0.0, INTER_LINEAR_EXACT);
  42. resize(tmp, dst_frame2, dst_frame2.size(), 0.0, 0.0, INTER_LINEAR_EXACT);
  43. Mat displacement_field(Size(dst_frame1.cols / (1 << OF_scale), dst_frame1.rows / (1 << OF_scale)),
  44. CV_32FC2);
  45. randn(displacement_field, 0.0, sigma);
  46. resize(displacement_field, displacement_field, dst_frame2.size(), 0.0, 0.0, INTER_CUBIC);
  47. for (int i = 0; i < displacement_field.rows; i++)
  48. for (int j = 0; j < displacement_field.cols; j++)
  49. displacement_field.at<Vec2f>(i, j) += Vec2f((float)j, (float)i);
  50. remap(dst_frame2, dst_frame2, displacement_field, Mat(), INTER_LINEAR, BORDER_REPLICATE);
  51. }
  52. }} // namespace