|
2 | 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory
|
3 | 3 | // of this distribution and at http://opencv.org/license.html.
|
4 | 4 | //
|
5 |
| -// Copyright (C) 2018-2020 Intel Corporation |
| 5 | +// Copyright (C) 2018-2021 Intel Corporation |
6 | 6 |
|
7 | 7 |
|
8 | 8 | #ifndef OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP
|
|
12 | 12 |
|
13 | 13 | #include "gapi_core_perf_tests.hpp"
|
14 | 14 |
|
| 15 | +#include "../../test/common/gapi_core_tests_common.hpp" |
| 16 | + |
15 | 17 | namespace opencv_test
|
16 | 18 | {
|
17 | 19 | using namespace perf;
|
@@ -1905,6 +1907,135 @@ PERF_TEST_P_(ConvertToPerfTest, TestPerformance)
|
1905 | 1907 |
|
1906 | 1908 | //------------------------------------------------------------------------------
|
1907 | 1909 |
|
| 1910 | +PERF_TEST_P_(KMeansNDPerfTest, TestPerformance) |
| 1911 | +{ |
| 1912 | + cv::Size sz; |
| 1913 | + CompareMats cmpF; |
| 1914 | + int K = -1; |
| 1915 | + cv::KmeansFlags flags = cv::KMEANS_RANDOM_CENTERS; |
| 1916 | + cv::GCompileArgs compile_args; |
| 1917 | + std::tie(sz, cmpF, K, flags, compile_args) = GetParam(); |
| 1918 | + |
| 1919 | + MatType2 type = CV_32FC1; |
| 1920 | + initMatrixRandU(type, sz, -1, false); |
| 1921 | + |
| 1922 | + double compact_gapi = -1.; |
| 1923 | + cv::Mat labels_gapi, centers_gapi; |
| 1924 | + if (flags & cv::KMEANS_USE_INITIAL_LABELS) |
| 1925 | + { |
| 1926 | + const int amount = sz.height; |
| 1927 | + cv::Mat bestLabels(cv::Size{1, amount}, CV_32SC1); |
| 1928 | + cv::randu(bestLabels, 0, K); |
| 1929 | + |
| 1930 | + cv::GComputation c(kmeansTestGAPI(in_mat1, bestLabels, K, flags, std::move(compile_args), |
| 1931 | + compact_gapi, labels_gapi, centers_gapi)); |
| 1932 | + TEST_CYCLE() |
| 1933 | + { |
| 1934 | + c.apply(cv::gin(in_mat1, bestLabels), |
| 1935 | + cv::gout(compact_gapi, labels_gapi, centers_gapi)); |
| 1936 | + } |
| 1937 | + kmeansTestOpenCVCompare(in_mat1, bestLabels, K, flags, compact_gapi, labels_gapi, |
| 1938 | + centers_gapi, cmpF); |
| 1939 | + } |
| 1940 | + else |
| 1941 | + { |
| 1942 | + cv::GComputation c(kmeansTestGAPI(in_mat1, K, flags, std::move(compile_args), compact_gapi, |
| 1943 | + labels_gapi, centers_gapi)); |
| 1944 | + TEST_CYCLE() |
| 1945 | + { |
| 1946 | + c.apply(cv::gin(in_mat1), cv::gout(compact_gapi, labels_gapi, centers_gapi)); |
| 1947 | + } |
| 1948 | + kmeansTestValidate(sz, type, K, compact_gapi, labels_gapi, centers_gapi); |
| 1949 | + } |
| 1950 | + SANITY_CHECK_NOTHING(); |
| 1951 | +} |
| 1952 | + |
| 1953 | +PERF_TEST_P_(KMeans2DPerfTest, TestPerformance) |
| 1954 | +{ |
| 1955 | + int amount = -1; |
| 1956 | + int K = -1; |
| 1957 | + cv::KmeansFlags flags = cv::KMEANS_RANDOM_CENTERS; |
| 1958 | + cv::GCompileArgs compile_args; |
| 1959 | + std::tie(amount, K, flags, compile_args) = GetParam(); |
| 1960 | + |
| 1961 | + std::vector<cv::Point2f> in_vector{}; |
| 1962 | + initPointsVectorRandU(amount, in_vector); |
| 1963 | + |
| 1964 | + double compact_gapi = -1.; |
| 1965 | + std::vector<int> labels_gapi{}; |
| 1966 | + std::vector<cv::Point2f> centers_gapi{}; |
| 1967 | + if (flags & cv::KMEANS_USE_INITIAL_LABELS) |
| 1968 | + { |
| 1969 | + std::vector<int> bestLabels(amount); |
| 1970 | + cv::randu(bestLabels, 0, K); |
| 1971 | + |
| 1972 | + cv::GComputation c(kmeansTestGAPI(in_vector, bestLabels, K, flags, std::move(compile_args), |
| 1973 | + compact_gapi, labels_gapi, centers_gapi)); |
| 1974 | + TEST_CYCLE() |
| 1975 | + { |
| 1976 | + c.apply(cv::gin(in_vector, bestLabels), |
| 1977 | + cv::gout(compact_gapi, labels_gapi, centers_gapi)); |
| 1978 | + } |
| 1979 | + kmeansTestOpenCVCompare(in_vector, bestLabels, K, flags, compact_gapi, labels_gapi, |
| 1980 | + centers_gapi); |
| 1981 | + } |
| 1982 | + else |
| 1983 | + { |
| 1984 | + cv::GComputation c(kmeansTestGAPI(in_vector, K, flags, std::move(compile_args), |
| 1985 | + compact_gapi, labels_gapi, centers_gapi)); |
| 1986 | + TEST_CYCLE() |
| 1987 | + { |
| 1988 | + c.apply(cv::gin(in_vector), cv::gout(compact_gapi, labels_gapi, centers_gapi)); |
| 1989 | + } |
| 1990 | + kmeansTestValidate({-1, amount}, -1, K, compact_gapi, labels_gapi, centers_gapi); |
| 1991 | + } |
| 1992 | + SANITY_CHECK_NOTHING(); |
| 1993 | +} |
| 1994 | + |
| 1995 | +PERF_TEST_P_(KMeans3DPerfTest, TestPerformance) |
| 1996 | +{ |
| 1997 | + int amount = -1; |
| 1998 | + int K = -1; |
| 1999 | + cv::KmeansFlags flags = cv::KMEANS_RANDOM_CENTERS; |
| 2000 | + cv::GCompileArgs compile_args; |
| 2001 | + std::tie(amount, K, flags, compile_args) = GetParam(); |
| 2002 | + |
| 2003 | + std::vector<cv::Point3f> in_vector{}; |
| 2004 | + initPointsVectorRandU(amount, in_vector); |
| 2005 | + |
| 2006 | + double compact_gapi = -1.; |
| 2007 | + std::vector<int> labels_gapi; |
| 2008 | + std::vector<cv::Point3f> centers_gapi; |
| 2009 | + if (flags & cv::KMEANS_USE_INITIAL_LABELS) |
| 2010 | + { |
| 2011 | + std::vector<int> bestLabels(amount); |
| 2012 | + cv::randu(bestLabels, 0, K); |
| 2013 | + |
| 2014 | + cv::GComputation c(kmeansTestGAPI(in_vector, bestLabels, K, flags, std::move(compile_args), |
| 2015 | + compact_gapi, labels_gapi, centers_gapi)); |
| 2016 | + TEST_CYCLE() |
| 2017 | + { |
| 2018 | + c.apply(cv::gin(in_vector, bestLabels), |
| 2019 | + cv::gout(compact_gapi, labels_gapi, centers_gapi)); |
| 2020 | + } |
| 2021 | + kmeansTestOpenCVCompare(in_vector, bestLabels, K, flags, compact_gapi, labels_gapi, |
| 2022 | + centers_gapi); |
| 2023 | + } |
| 2024 | + else |
| 2025 | + { |
| 2026 | + cv::GComputation c(kmeansTestGAPI(in_vector, K, flags, std::move(compile_args), |
| 2027 | + compact_gapi, labels_gapi, centers_gapi)); |
| 2028 | + TEST_CYCLE() |
| 2029 | + { |
| 2030 | + c.apply(cv::gin(in_vector), cv::gout(compact_gapi, labels_gapi, centers_gapi)); |
| 2031 | + } |
| 2032 | + kmeansTestValidate({-1, amount}, -1, K, compact_gapi, labels_gapi, centers_gapi); |
| 2033 | + } |
| 2034 | + SANITY_CHECK_NOTHING(); |
| 2035 | +} |
| 2036 | + |
| 2037 | +//------------------------------------------------------------------------------ |
| 2038 | + |
1908 | 2039 | PERF_TEST_P_(ResizePerfTest, TestPerformance)
|
1909 | 2040 | {
|
1910 | 2041 | compare_f cmpF = get<0>(GetParam());
|
|
0 commit comments