mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 06:26:29 +08:00
Merge pull request #19215 from OrestChura:oc/bRect_perftests
[G-API]: Performance tests for boundingRect * Update boundingRect() tests with the changes from fitLine() PR * Add performance tests for boundingRect * Applying comment about g_type_of_t * Addressing comments * Addressing comment: replace cmp_f by CompareF in perf.tests + add the default constructor for CompareF * Fix typo
This commit is contained in:
parent
3eaeca58da
commit
d34a34f328
@ -43,6 +43,12 @@ class CannyPerfTest : public TestPerfParams<tuple<compare_f, MatType,c
|
||||
class GoodFeaturesPerfTest : public TestPerfParams<tuple<compare_vector_f<cv::Point2f>, std::string,
|
||||
int,int,double,double,int,bool,
|
||||
cv::GCompileArgs>> {};
|
||||
class BoundingRectMatPerfTest :
|
||||
public TestPerfParams<tuple<CompareRects, MatType,cv::Size,bool, cv::GCompileArgs>> {};
|
||||
class BoundingRectVector32SPerfTest :
|
||||
public TestPerfParams<tuple<CompareRects, cv::Size, cv::GCompileArgs>> {};
|
||||
class BoundingRectVector32FPerfTest :
|
||||
public TestPerfParams<tuple<CompareRects, cv::Size, cv::GCompileArgs>> {};
|
||||
class EqHistPerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCompileArgs>> {};
|
||||
class BGR2RGBPerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCompileArgs>> {};
|
||||
class RGB2GrayPerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCompileArgs>> {};
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include "gapi_imgproc_perf_tests.hpp"
|
||||
|
||||
#include "../../test/common/gapi_imgproc_tests_common.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
@ -793,6 +795,82 @@ PERF_TEST_P_(GoodFeaturesPerfTest, TestPerformance)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
PERF_TEST_P_(BoundingRectMatPerfTest, TestPerformance)
|
||||
{
|
||||
CompareRects cmpF;
|
||||
cv::Size sz;
|
||||
MatType type;
|
||||
bool initByVector = false;
|
||||
cv::GCompileArgs compile_args;
|
||||
std::tie(cmpF, type, sz, initByVector, compile_args) = GetParam();
|
||||
|
||||
if (initByVector)
|
||||
{
|
||||
initMatByPointsVectorRandU<cv::Point_>(type, sz, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
initMatrixRandU(type, sz, -1, false);
|
||||
}
|
||||
|
||||
cv::Rect out_rect_gapi;
|
||||
cv::GComputation c(boundingRectTestGAPI(in_mat1, std::move(compile_args), out_rect_gapi));
|
||||
|
||||
TEST_CYCLE()
|
||||
{
|
||||
c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi));
|
||||
}
|
||||
|
||||
boundingRectTestOpenCVCompare(in_mat1, out_rect_gapi, cmpF);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(BoundingRectVector32SPerfTest, TestPerformance)
|
||||
{
|
||||
CompareRects cmpF;
|
||||
cv::Size sz;
|
||||
cv::GCompileArgs compile_args;
|
||||
std::tie(cmpF, sz, compile_args) = GetParam();
|
||||
|
||||
std::vector<cv::Point2i> in_vector;
|
||||
initPointsVectorRandU(sz.width, in_vector);
|
||||
|
||||
cv::Rect out_rect_gapi;
|
||||
cv::GComputation c(boundingRectTestGAPI(in_vector, std::move(compile_args), out_rect_gapi));
|
||||
|
||||
TEST_CYCLE()
|
||||
{
|
||||
c.apply(cv::gin(in_vector), cv::gout(out_rect_gapi));
|
||||
}
|
||||
|
||||
boundingRectTestOpenCVCompare(in_vector, out_rect_gapi, cmpF);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(BoundingRectVector32FPerfTest, TestPerformance)
|
||||
{
|
||||
CompareRects cmpF;
|
||||
cv::Size sz;
|
||||
cv::GCompileArgs compile_args;
|
||||
std::tie(cmpF, sz, compile_args) = GetParam();
|
||||
|
||||
std::vector<cv::Point2f> in_vector;
|
||||
initPointsVectorRandU(sz.width, in_vector);
|
||||
|
||||
cv::Rect out_rect_gapi;
|
||||
cv::GComputation c(boundingRectTestGAPI(in_vector, std::move(compile_args), out_rect_gapi));
|
||||
|
||||
TEST_CYCLE()
|
||||
{
|
||||
c.apply(cv::gin(in_vector), cv::gout(out_rect_gapi));
|
||||
}
|
||||
|
||||
boundingRectTestOpenCVCompare(in_vector, out_rect_gapi, cmpF);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
PERF_TEST_P_(EqHistPerfTest, TestPerformance)
|
||||
{
|
||||
compare_f cmpF = get<0>(GetParam());
|
||||
|
@ -194,6 +194,30 @@ INSTANTIATE_TEST_CASE_P(GoodFeaturesInternalPerfTestCPU, GoodFeaturesPerfTest,
|
||||
Values(true),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BoundingRectMatPerfTestCPU, BoundingRectMatPerfTest,
|
||||
Combine(Values(IoUToleranceRect(0).to_compare_obj()),
|
||||
Values(CV_8UC1),
|
||||
Values(szVGA, sz720p, sz1080p),
|
||||
Values(false),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BoundingRectMatVectorPerfTestCPU, BoundingRectMatPerfTest,
|
||||
Combine(Values(IoUToleranceRect(1e-5).to_compare_obj()),
|
||||
Values(CV_32S, CV_32F),
|
||||
Values(szVGA, sz720p, sz1080p),
|
||||
Values(true),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BoundingRectVector32SPerfTestCPU, BoundingRectVector32SPerfTest,
|
||||
Combine(Values(IoUToleranceRect(0).to_compare_obj()),
|
||||
Values(szVGA, sz720p, sz1080p),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BoundingRectVector32FPerfTestCPU, BoundingRectVector32FPerfTest,
|
||||
Combine(Values(IoUToleranceRect(1e-5).to_compare_obj()),
|
||||
Values(szVGA, sz720p, sz1080p),
|
||||
Values(cv::compile_args(IMGPROC_CPU))));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(EqHistPerfTestCPU, EqHistPerfTest,
|
||||
Combine(Values(AbsExact().to_compare_f()),
|
||||
Values(szVGA, sz720p, sz1080p),
|
||||
|
@ -76,9 +76,8 @@ GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursHNoOffsetTest,
|
||||
cv::ContourApproximationModes),
|
||||
4, sz, type, mode, method)
|
||||
GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursHOffsetTest, <>, 0)
|
||||
GAPI_TEST_FIXTURE(BoundingRectMatTest, initMatrixRandU, FIXTURE_API(CompareRects), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(BoundingRectMatVector32STest, initNothing, FIXTURE_API(CompareRects), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(BoundingRectMatVector32FTest, initNothing, FIXTURE_API(CompareRects), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(BoundingRectMatTest, initNothing, FIXTURE_API(CompareRects,bool),
|
||||
2, cmpF, initByVector)
|
||||
GAPI_TEST_FIXTURE(BoundingRectVector32STest, initNothing, FIXTURE_API(CompareRects), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(BoundingRectVector32FTest, initNothing, FIXTURE_API(CompareRects), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(FitLine2DMatVectorTest, initMatByPointsVectorRandU<cv::Point_>,
|
||||
|
49
modules/gapi/test/common/gapi_imgproc_tests_common.hpp
Normal file
49
modules/gapi/test/common/gapi_imgproc_tests_common.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
//
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
|
||||
#ifndef OPENCV_GAPI_IMGPROC_TESTS_COMMON_HPP
|
||||
#define OPENCV_GAPI_IMGPROC_TESTS_COMMON_HPP
|
||||
|
||||
#include "gapi_tests_common.hpp"
|
||||
#include "../../include/opencv2/gapi/imgproc.hpp"
|
||||
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
template<typename In>
|
||||
static cv::GComputation boundingRectTestGAPI(const In& in, cv::GCompileArgs&& args,
|
||||
cv::Rect& out_rect_gapi)
|
||||
{
|
||||
cv::detail::g_type_of_t<In> g_in;
|
||||
auto out = cv::gapi::boundingRect(g_in);
|
||||
cv::GComputation c(cv::GIn(g_in), cv::GOut(out));
|
||||
c.apply(cv::gin(in), cv::gout(out_rect_gapi), std::move(args));
|
||||
return c;
|
||||
}
|
||||
|
||||
template<typename In>
|
||||
static void boundingRectTestOpenCVCompare(const In& in, const cv::Rect& out_rect_gapi,
|
||||
const CompareRects& cmpF)
|
||||
{
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
cv::Rect out_rect_ocv = cv::boundingRect(in);
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv));
|
||||
}
|
||||
|
||||
template<typename In>
|
||||
static void boundingRectTestBody(const In& in, const CompareRects& cmpF, cv::GCompileArgs&& args)
|
||||
{
|
||||
cv::Rect out_rect_gapi;
|
||||
boundingRectTestGAPI(in, std::move(args), out_rect_gapi);
|
||||
|
||||
boundingRectTestOpenCVCompare(in, out_rect_gapi, cmpF);
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
|
||||
#endif // OPENCV_GAPI_VIDEO_TESTS_COMMON_HPP
|
@ -11,6 +11,8 @@
|
||||
#include <opencv2/gapi/imgproc.hpp>
|
||||
#include "gapi_imgproc_tests.hpp"
|
||||
|
||||
#include "gapi_imgproc_tests_common.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
@ -623,133 +625,32 @@ TEST_P(FindContoursHOffsetTest, AccuracyTest)
|
||||
|
||||
TEST_P(BoundingRectMatTest, AccuracyTest)
|
||||
{
|
||||
cv::Rect out_rect_gapi, out_rect_ocv;
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::boundingRect(in);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
if (initByVector)
|
||||
{
|
||||
out_rect_ocv = cv::boundingRect(in_mat1);
|
||||
initMatByPointsVectorRandU<cv::Point_>(type, sz, dtype);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
else
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv));
|
||||
initMatrixRandU(type, sz, dtype);
|
||||
}
|
||||
boundingRectTestBody(in_mat1, cmpF, getCompileArgs());
|
||||
}
|
||||
|
||||
TEST_P(BoundingRectMatVector32STest, AccuracyTest)
|
||||
{
|
||||
cv::Rect out_rect_gapi, out_rect_ocv;
|
||||
|
||||
std::vector<cv::Point2i> in_vectorS(sz.width);
|
||||
cv::randu(in_vectorS, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
in_mat1 = cv::Mat(in_vectorS);
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::boundingRect(in);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
out_rect_ocv = cv::boundingRect(in_mat1);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(BoundingRectMatVector32FTest, AccuracyTest)
|
||||
{
|
||||
cv::RNG& rng = theRNG();
|
||||
cv::Rect out_rect_gapi, out_rect_ocv;
|
||||
|
||||
std::vector<cv::Point2f> in_vectorF(sz.width);
|
||||
const int fscale = 256; // avoid bits near ULP, generate stable test input
|
||||
for (int i = 0; i < sz.width; i++)
|
||||
{
|
||||
cv::Point2f pt(rng.uniform(0, 255 * fscale) / static_cast<float>(fscale),
|
||||
rng.uniform(0, 255 * fscale) / static_cast<float>(fscale));
|
||||
in_vectorF.push_back(pt);
|
||||
}
|
||||
in_mat1 = cv::Mat(in_vectorF);
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in;
|
||||
auto out = cv::gapi::boundingRect(in);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
out_rect_ocv = cv::boundingRect(in_mat1);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_P(BoundingRectVector32STest, AccuracyTest)
|
||||
|
||||
{
|
||||
cv::Rect out_rect_gapi, out_rect_ocv;
|
||||
std::vector<cv::Point2i> in_vector;
|
||||
initPointsVectorRandU(sz.width, in_vector);
|
||||
|
||||
std::vector<cv::Point2i> in_vectorS(sz.width);
|
||||
cv::randu(in_vectorS, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GArray<cv::Point2i> in;
|
||||
auto out = cv::gapi::boundingRect(in);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(in_vectorS), cv::gout(out_rect_gapi), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
out_rect_ocv = cv::boundingRect(in_vectorS);
|
||||
}
|
||||
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv));
|
||||
}
|
||||
boundingRectTestBody(in_vector, cmpF, getCompileArgs());
|
||||
}
|
||||
|
||||
TEST_P(BoundingRectVector32FTest, AccuracyTest)
|
||||
{
|
||||
cv::RNG& rng = theRNG();
|
||||
cv::Rect out_rect_gapi, out_rect_ocv;
|
||||
std::vector<cv::Point2f> in_vector;
|
||||
initPointsVectorRandU(sz.width, in_vector);
|
||||
|
||||
std::vector<cv::Point2f> in_vectorF(sz.width);
|
||||
const int fscale = 256; // avoid bits near ULP, generate stable test input
|
||||
for (int i = 0; i < sz.width; i++)
|
||||
{
|
||||
cv::Point2f pt(rng.uniform(0, 255 * fscale) / static_cast<float>(fscale),
|
||||
rng.uniform(0, 255 * fscale) / static_cast<float>(fscale));
|
||||
in_vectorF.push_back(pt);
|
||||
}
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GArray<cv::Point2f> in;
|
||||
auto out = cv::gapi::boundingRect(in);
|
||||
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(in_vectorF), cv::gout(out_rect_gapi), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
{
|
||||
out_rect_ocv = cv::boundingRect(in_vectorF);
|
||||
}
|
||||
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv));
|
||||
}
|
||||
boundingRectTestBody(in_vector, cmpF, getCompileArgs());
|
||||
}
|
||||
|
||||
TEST_P(FitLine2DMatVectorTest, AccuracyTest)
|
||||
|
@ -593,6 +593,8 @@ using compare_vec_f = std::function<bool(const cv::Vec<Elem, cn> &a, const cv::V
|
||||
template<typename T1, typename T2>
|
||||
struct CompareF
|
||||
{
|
||||
CompareF() = default;
|
||||
|
||||
using callable_t = std::function<bool(const T1& a, const T2& b)>;
|
||||
CompareF(callable_t&& cmp, std::string&& cmp_name) :
|
||||
_comparator(std::move(cmp)), _name(std::move(cmp_name)) {}
|
||||
|
@ -303,23 +303,17 @@ INSTANTIATE_TEST_CASE_P(BoundingRectMatTestCPU, BoundingRectMatTest,
|
||||
cv::Size(128, 128)),
|
||||
Values(-1),
|
||||
Values(IMGPROC_CPU),
|
||||
Values(IoUToleranceRect(0).to_compare_obj())));
|
||||
Values(IoUToleranceRect(0).to_compare_obj()),
|
||||
Values(false)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BoundingRectMatVector32STestCPU, BoundingRectMatVector32STest,
|
||||
Combine(Values(-1),
|
||||
INSTANTIATE_TEST_CASE_P(BoundingRectMatVectorTestCPU, BoundingRectMatTest,
|
||||
Combine(Values(CV_32S, CV_32F),
|
||||
Values(cv::Size(1280, 1),
|
||||
cv::Size(128, 1)),
|
||||
Values(-1),
|
||||
Values(IMGPROC_CPU),
|
||||
Values(IoUToleranceRect(0).to_compare_obj())));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BoundingRectMatVector32FTestCPU, BoundingRectMatVector32FTest,
|
||||
Combine(Values(-1),
|
||||
Values(cv::Size(1280, 1),
|
||||
cv::Size(128, 1)),
|
||||
Values(-1),
|
||||
Values(IMGPROC_CPU),
|
||||
Values(IoUToleranceRect(1e-5).to_compare_obj())));
|
||||
Values(IoUToleranceRect(1e-5).to_compare_obj()),
|
||||
Values(true)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BoundingRectVector32STestCPU, BoundingRectVector32STest,
|
||||
Combine(Values(-1),
|
||||
|
Loading…
Reference in New Issue
Block a user