Blame view

3rdparty/opencv-4.5.4/modules/gapi/perf/perf_bench.cpp 2.35 KB
f4334277   Hu Chunming   提交3rdparty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  #include "perf_precomp.hpp"
  #include "../test/common/gapi_tests_common.hpp"
  
  namespace opencv_test
  {
  
  struct SobelEdgeDetector:  public TestPerfParams<cv::Size> {};
  PERF_TEST_P_(SobelEdgeDetector, Fluid)
  {
      Size sz = GetParam();
      initMatsRandU(CV_8UC3, sz, CV_8UC3, false);
  
      GMat in;
      GMat gx  = gapi::Sobel(in, CV_32F, 1, 0);
      GMat gy  = gapi::Sobel(in, CV_32F, 0, 1);
      GMat mag = gapi::sqrt(gapi::mul(gx, gx) + gapi::mul(gy, gy));
      GMat out = gapi::convertTo(mag, CV_8U);
      GComputation sobel(in, out);
      auto pkg = gapi::combine(gapi::core::fluid::kernels(),
                               gapi::imgproc::fluid::kernels());
      auto cc = sobel.compile(cv::descr_of(in_mat1),
                              cv::compile_args(cv::gapi::use_only{pkg}));
      cc(in_mat1, out_mat_gapi);
  
      TEST_CYCLE()
      {
          cc(in_mat1, out_mat_gapi);
      }
      SANITY_CHECK_NOTHING();
  }
  PERF_TEST_P_(SobelEdgeDetector, OpenCV)
  {
      Size sz = GetParam();
      initMatsRandU(CV_8UC3, sz, CV_8UC3, false);
  
      Mat gx, gy;
      Mat mag;
      auto cc = [&](const cv::Mat &in_mat, cv::Mat &out_mat) {
          using namespace cv;
  
          Sobel(in_mat, gx, CV_32F, 1, 0);
          Sobel(in_mat, gy, CV_32F, 0, 1);
          sqrt(gx.mul(gx) + gy.mul(gy), mag);
          mag.convertTo(out_mat, CV_8U);
      };
      cc(in_mat1, out_mat_gapi);
  
      TEST_CYCLE()
      {
          cc(in_mat1, out_mat_gapi);
      }
      SANITY_CHECK_NOTHING();
  }
  PERF_TEST_P_(SobelEdgeDetector, OpenCV_Smarter)
  {
      Size sz = GetParam();
      initMatsRandU(CV_8UC3, sz, CV_8UC3, false);
  
      Mat gx, gy;
      Mat ggx, ggy;
      Mat sum;
      Mat mag;
  
      auto cc = [&](const cv::Mat &in_mat, cv::Mat &out_mat) {
          cv::Sobel(in_mat, gx, CV_32F, 1, 0);
          cv::Sobel(in_mat, gy, CV_32F, 0, 1);
          cv::multiply(gx, gx, ggx);
          cv::multiply(gy, gy, ggy);
          cv::add(ggx, ggy, sum);
          cv::sqrt(sum, mag);
          mag.convertTo(out_mat, CV_8U);
      };
      cc(in_mat1, out_mat_gapi);
  
      TEST_CYCLE()
      {
          cc(in_mat1, out_mat_gapi);
      }
      SANITY_CHECK_NOTHING();
  }
  INSTANTIATE_TEST_CASE_P(Benchmark, SobelEdgeDetector,
                          Values(cv::Size(320, 240),
                                 cv::Size(640, 480),
                                 cv::Size(1280, 720),
                                 cv::Size(1920, 1080),
                                 cv::Size(3840, 2170)));
  
  } // opencv_test