perf_dis_optflow.cpp 2.4 KB

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