diff --git a/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp b/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp index 931637d2f1..16e5f13729 100644 --- a/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp @@ -43,12 +43,44 @@ class CannyPerfTest : public TestPerfParams, std::string, int,int,double,double,int,bool, cv::GCompileArgs>> {}; +class FindContoursPerfTest : public TestPerfParams> {}; +class FindContoursHPerfTest : public TestPerfParams> {}; class BoundingRectMatPerfTest : public TestPerfParams> {}; class BoundingRectVector32SPerfTest : public TestPerfParams> {}; class BoundingRectVector32FPerfTest : public TestPerfParams> {}; +class FitLine2DMatVectorPerfTest : public TestPerfParams, + MatType,cv::Size,cv::DistanceTypes, + cv::GCompileArgs>> {}; +class FitLine2DVector32SPerfTest : public TestPerfParams, + cv::Size,cv::DistanceTypes, + cv::GCompileArgs>> {}; +class FitLine2DVector32FPerfTest : public TestPerfParams, + cv::Size,cv::DistanceTypes, + cv::GCompileArgs>> {}; +class FitLine2DVector64FPerfTest : public TestPerfParams, + cv::Size,cv::DistanceTypes, + cv::GCompileArgs>> {}; +class FitLine3DMatVectorPerfTest : public TestPerfParams, + MatType,cv::Size,cv::DistanceTypes, + cv::GCompileArgs>> {}; +class FitLine3DVector32SPerfTest : public TestPerfParams, + cv::Size,cv::DistanceTypes, + cv::GCompileArgs>> {}; +class FitLine3DVector32FPerfTest : public TestPerfParams, + cv::Size,cv::DistanceTypes, + cv::GCompileArgs>> {}; +class FitLine3DVector64FPerfTest : public TestPerfParams, + cv::Size,cv::DistanceTypes, + cv::GCompileArgs>> {}; class EqHistPerfTest : public TestPerfParams> {}; class BGR2RGBPerfTest : public TestPerfParams> {}; class RGB2GrayPerfTest : public TestPerfParams> {}; diff --git a/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp b/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp index 626ceccb8f..57c8130338 100644 --- a/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp @@ -795,6 +795,64 @@ PERF_TEST_P_(GoodFeaturesPerfTest, TestPerformance) //------------------------------------------------------------------------------ +PERF_TEST_P_(FindContoursPerfTest, TestPerformance) +{ + CompareMats cmpF; + MatType type; + cv::Size sz; + cv::RetrievalModes mode; + cv::ContourApproximationModes method; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, sz, mode, method, compile_args) = GetParam(); + + cv::Mat in; + initMatForFindingContours(in, sz, type); + cv::Point offset = cv::Point(); + std::vector out_hier_gapi = std::vector(); + + std::vector> out_cnts_gapi; + cv::GComputation c(findContoursTestGAPI(in, mode, method, std::move(compile_args), + out_cnts_gapi, out_hier_gapi, offset)); + + TEST_CYCLE() + { + c.apply(gin(in, offset), gout(out_cnts_gapi)); + } + + findContoursTestOpenCVCompare(in, mode, method, out_cnts_gapi, out_hier_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(FindContoursHPerfTest, TestPerformance) +{ + CompareMats cmpF; + MatType type; + cv::Size sz; + cv::RetrievalModes mode; + cv::ContourApproximationModes method; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, sz, mode, method, compile_args) = GetParam(); + + cv::Mat in; + initMatForFindingContours(in, sz, type); + cv::Point offset = cv::Point(); + + std::vector> out_cnts_gapi; + std::vector out_hier_gapi; + cv::GComputation c(findContoursTestGAPI(in, mode, method, std::move(compile_args), + out_cnts_gapi, out_hier_gapi, offset)); + + TEST_CYCLE() + { + c.apply(gin(in, offset), gout(out_cnts_gapi, out_hier_gapi)); + } + + findContoursTestOpenCVCompare(in, mode, method, out_cnts_gapi, out_hier_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + PERF_TEST_P_(BoundingRectMatPerfTest, TestPerformance) { CompareRects cmpF; @@ -871,6 +929,198 @@ PERF_TEST_P_(BoundingRectVector32FPerfTest, TestPerformance) //------------------------------------------------------------------------------ +PERF_TEST_P_(FitLine2DMatVectorPerfTest, TestPerformance) +{ + CompareVecs cmpF; + cv::Size sz; + MatType type; + cv::DistanceTypes distType; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, sz, distType, compile_args) = GetParam(); + + initMatByPointsVectorRandU(type, sz, -1); + + cv::Vec4f out_vec_gapi; + cv::GComputation c(fitLineTestGAPI(in_mat1, distType, std::move(compile_args), out_vec_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1), cv::gout(out_vec_gapi)); + } + + fitLineTestOpenCVCompare(in_mat1, distType, out_vec_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(FitLine2DVector32SPerfTest, TestPerformance) +{ + CompareVecs cmpF; + cv::Size sz; + cv::DistanceTypes distType; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, distType, compile_args) = GetParam(); + + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); + + cv::Vec4f out_vec_gapi; + cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args), + out_vec_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi)); + } + + fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(FitLine2DVector32FPerfTest, TestPerformance) +{ + CompareVecs cmpF; + cv::Size sz; + cv::DistanceTypes distType; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, distType, compile_args) = GetParam(); + + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); + + cv::Vec4f out_vec_gapi; + cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args), + out_vec_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi)); + } + + fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(FitLine2DVector64FPerfTest, TestPerformance) +{ + CompareVecs cmpF; + cv::Size sz; + cv::DistanceTypes distType; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, distType, compile_args) = GetParam(); + + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); + + cv::Vec4f out_vec_gapi; + cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args), + out_vec_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi)); + } + + fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(FitLine3DMatVectorPerfTest, TestPerformance) +{ + CompareVecs cmpF; + cv::Size sz; + MatType type; + cv::DistanceTypes distType; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, sz, distType, compile_args) = GetParam(); + + initMatByPointsVectorRandU(type, sz, -1); + + cv::Vec6f out_vec_gapi; + cv::GComputation c(fitLineTestGAPI(in_mat1, distType, std::move(compile_args), out_vec_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1), cv::gout(out_vec_gapi)); + } + + fitLineTestOpenCVCompare(in_mat1, distType, out_vec_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(FitLine3DVector32SPerfTest, TestPerformance) +{ + CompareVecs cmpF; + cv::Size sz; + cv::DistanceTypes distType; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, distType, compile_args) = GetParam(); + + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); + + cv::Vec6f out_vec_gapi; + cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args), + out_vec_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi)); + } + + fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(FitLine3DVector32FPerfTest, TestPerformance) +{ + CompareVecs cmpF; + cv::Size sz; + cv::DistanceTypes distType; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, distType, compile_args) = GetParam(); + + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); + + cv::Vec6f out_vec_gapi; + cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args), + out_vec_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi)); + } + + fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(FitLine3DVector64FPerfTest, TestPerformance) +{ + CompareVecs cmpF; + cv::Size sz; + cv::DistanceTypes distType; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, distType, compile_args) = GetParam(); + + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); + + cv::Vec6f out_vec_gapi; + cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args), + out_vec_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi)); + } + + fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + PERF_TEST_P_(EqHistPerfTest, TestPerformance) { compare_f cmpF = get<0>(GetParam()); diff --git a/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp b/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp index dcb78b78aa..d4c37c10af 100644 --- a/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp +++ b/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp @@ -194,6 +194,42 @@ INSTANTIATE_TEST_CASE_P(GoodFeaturesInternalPerfTestCPU, GoodFeaturesPerfTest, Values(true), Values(cv::compile_args(IMGPROC_CPU)))); +INSTANTIATE_TEST_CASE_P(FindContoursPerfTestCPU, FindContoursPerfTest, + Combine(Values(AbsExact().to_compare_obj()), + Values(CV_8UC1), + Values(szVGA, sz720p, sz1080p), + Values(RETR_EXTERNAL, RETR_LIST, RETR_CCOMP, RETR_TREE), + Values(CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, + CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FindContours32SPerfTestCPU, FindContoursPerfTest, + Combine(Values(AbsExact().to_compare_obj()), + Values(CV_32SC1), + Values(szVGA, sz720p, sz1080p), + Values(RETR_CCOMP, RETR_FLOODFILL), + Values(CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, + CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FindContoursHPerfTestCPU, FindContoursHPerfTest, + Combine(Values(AbsExact().to_compare_obj()), + Values(CV_8UC1), + Values(szVGA, sz720p, sz1080p), + Values(RETR_EXTERNAL, RETR_LIST, RETR_CCOMP, RETR_TREE), + Values(CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, + CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FindContoursH32SPerfTestCPU, FindContoursHPerfTest, + Combine(Values(AbsExact().to_compare_obj()), + Values(CV_32SC1), + Values(szVGA, sz720p, sz1080p), + Values(RETR_CCOMP, RETR_FLOODFILL), + Values(CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, + CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS), + Values(cv::compile_args(IMGPROC_CPU)))); + INSTANTIATE_TEST_CASE_P(BoundingRectMatPerfTestCPU, BoundingRectMatPerfTest, Combine(Values(IoUToleranceRect(0).to_compare_obj()), Values(CV_8UC1), @@ -218,6 +254,66 @@ INSTANTIATE_TEST_CASE_P(BoundingRectVector32FPerfTestCPU, BoundingRectVector32FP Values(szVGA, sz720p, sz1080p), Values(cv::compile_args(IMGPROC_CPU)))); +INSTANTIATE_TEST_CASE_P(FitLine2DMatVectorPerfTestCPU, FitLine2DMatVectorPerfTest, + Combine(Values(RelDiffToleranceVec(0.01).to_compare_obj()), + Values(CV_8U, CV_8S, CV_16U, CV_16S, + CV_32S, CV_32F, CV_64F), + Values(cv::Size(8, 0), cv::Size(1024, 0)), + Values(DIST_L1, DIST_L2, DIST_L12, DIST_FAIR, + DIST_WELSCH, DIST_HUBER), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FitLine2DVector32SPerfTestCPU, FitLine2DVector32SPerfTest, + Combine(Values(RelDiffToleranceVec(0.01).to_compare_obj()), + Values(cv::Size(8, 0), cv::Size(1024, 0)), + Values(DIST_L1, DIST_L2, DIST_L12, DIST_FAIR, + DIST_WELSCH, DIST_HUBER), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FitLine2DVector32FPerfTestCPU, FitLine2DVector32FPerfTest, + Combine(Values(RelDiffToleranceVec(0.01).to_compare_obj()), + Values(cv::Size(8, 0), cv::Size(1024, 0)), + Values(DIST_L1, DIST_L2, DIST_L12, DIST_FAIR, + DIST_WELSCH, DIST_HUBER), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FitLine2DVector64FPerfTestCPU, FitLine2DVector64FPerfTest, + Combine(Values(RelDiffToleranceVec(0.01).to_compare_obj()), + Values(cv::Size(8, 0), cv::Size(1024, 0)), + Values(DIST_L1, DIST_L2, DIST_L12, DIST_FAIR, + DIST_WELSCH, DIST_HUBER), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FitLine3DMatVectorPerfTestCPU, FitLine3DMatVectorPerfTest, + Combine(Values(RelDiffToleranceVec(0.01).to_compare_obj()), + Values(CV_8U, CV_8S, CV_16U, CV_16S, + CV_32S, CV_32F, CV_64F), + Values(cv::Size(8, 0), cv::Size(1024, 0)), + Values(DIST_L1, DIST_L2, DIST_L12, DIST_FAIR, + DIST_WELSCH, DIST_HUBER), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FitLine3DVector32SPerfTestCPU, FitLine3DVector32SPerfTest, + Combine(Values(RelDiffToleranceVec(0.01).to_compare_obj()), + Values(cv::Size(8, 0), cv::Size(1024, 0)), + Values(DIST_L1, DIST_L2, DIST_L12, DIST_FAIR, + DIST_WELSCH, DIST_HUBER), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FitLine3DVector32FPerfTestCPU, FitLine3DVector32FPerfTest, + Combine(Values(RelDiffToleranceVec(0.01).to_compare_obj()), + Values(cv::Size(8, 0), cv::Size(1024, 0)), + Values(DIST_L1, DIST_L2, DIST_L12, DIST_FAIR, + DIST_WELSCH, DIST_HUBER), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(FitLine3DVector64FPerfTestCPU, FitLine3DVector64FPerfTest, + Combine(Values(RelDiffToleranceVec(0.01).to_compare_obj()), + Values(cv::Size(8, 0), cv::Size(1024, 0)), + Values(DIST_L1, DIST_L2, DIST_L12, DIST_FAIR, + DIST_WELSCH, DIST_HUBER), + Values(cv::compile_args(IMGPROC_CPU)))); + INSTANTIATE_TEST_CASE_P(EqHistPerfTestCPU, EqHistPerfTest, Combine(Values(AbsExact().to_compare_f()), Values(szVGA, sz720p, sz1080p), diff --git a/modules/gapi/test/common/gapi_imgproc_tests.hpp b/modules/gapi/test/common/gapi_imgproc_tests.hpp index 892629b35a..97d46943d5 100644 --- a/modules/gapi/test/common/gapi_imgproc_tests.hpp +++ b/modules/gapi/test/common/gapi_imgproc_tests.hpp @@ -68,13 +68,13 @@ GAPI_TEST_FIXTURE_SPEC_PARAMS(GoodFeaturesTest, blockSize, useHarrisDetector) GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursNoOffsetTest, FIXTURE_API(cv::Size,MatType2,cv::RetrievalModes, - cv::ContourApproximationModes), - 4, sz, type, mode, method) + cv::ContourApproximationModes, CompareMats), + 5, sz, type, mode, method, cmpF) GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursOffsetTest, <>, 0) GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursHNoOffsetTest, FIXTURE_API(cv::Size,MatType2,cv::RetrievalModes, - cv::ContourApproximationModes), - 4, sz, type, mode, method) + cv::ContourApproximationModes, CompareMats), + 5, sz, type, mode, method, cmpF) GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursHOffsetTest, <>, 0) GAPI_TEST_FIXTURE(BoundingRectMatTest, initNothing, FIXTURE_API(CompareRects,bool), 2, cmpF, initByVector) diff --git a/modules/gapi/test/common/gapi_imgproc_tests_common.hpp b/modules/gapi/test/common/gapi_imgproc_tests_common.hpp index 796a0e9a44..9d83c37106 100644 --- a/modules/gapi/test/common/gapi_imgproc_tests_common.hpp +++ b/modules/gapi/test/common/gapi_imgproc_tests_common.hpp @@ -14,6 +14,105 @@ namespace opencv_test { +// Draw random ellipses on given cv::Mat of given size and type +static void initMatForFindingContours(cv::Mat& mat, const cv::Size& sz, const int type) +{ + cv::RNG& rng = theRNG(); + mat = cv::Mat(sz, type, cv::Scalar::all(0)); + const size_t numEllipses = rng.uniform(1, 10); + + for( size_t i = 0; i < numEllipses; i++ ) + { + cv::Point center; + cv::Size axes; + center.x = rng.uniform(0, sz.width); + center.y = rng.uniform(0, sz.height); + axes.width = rng.uniform(2, sz.width); + axes.height = rng.uniform(2, sz.height); + const int color = rng.uniform(1, 256); + const double angle = rng.uniform(0., 180.); + cv::ellipse(mat, center, axes, angle, 0., 360., color, 1, FILLED); + } +} + +enum OptionalFindContoursOutput {NONE, HIERARCHY}; + +template +cv::GComputation findContoursTestGAPI(const cv::Mat& in, const cv::RetrievalModes mode, + const cv::ContourApproximationModes method, + cv::GCompileArgs&& args, + std::vector>& out_cnts_gapi, + std::vector& /*out_hier_gapi*/, + const cv::Point& offset = cv::Point()) +{ + cv::GMat g_in; + cv::GOpaque gOffset; + cv::GArray> outCts; + outCts = cv::gapi::findContours(g_in, mode, method, gOffset); + cv::GComputation c(GIn(g_in, gOffset), GOut(outCts)); + c.apply(gin(in, offset), gout(out_cnts_gapi), std::move(args)); + return c; +} + +template<> cv::GComputation findContoursTestGAPI ( + const cv::Mat& in, const cv::RetrievalModes mode, const cv::ContourApproximationModes method, + cv::GCompileArgs&& args, std::vector>& out_cnts_gapi, + std::vector& out_hier_gapi, const cv::Point& offset) +{ + cv::GMat g_in; + cv::GOpaque gOffset; + cv::GArray> outCts; + cv::GArray outHier; + std::tie(outCts, outHier) = cv::gapi::findContoursH(g_in, mode, method, gOffset); + cv::GComputation c(GIn(g_in, gOffset), GOut(outCts, outHier)); + c.apply(gin(in, offset), gout(out_cnts_gapi, out_hier_gapi), std::move(args)); + return c; +} + +template +void findContoursTestOpenCVCompare(const cv::Mat& in, const cv::RetrievalModes mode, + const cv::ContourApproximationModes method, + const std::vector>& out_cnts_gapi, + const std::vector& out_hier_gapi, + const CompareMats& cmpF, const cv::Point& offset = cv::Point()) +{ + // OpenCV code ///////////////////////////////////////////////////////////// + std::vector> out_cnts_ocv; + std::vector out_hier_ocv; + cv::findContours(in, out_cnts_ocv, out_hier_ocv, mode, method, offset); + // Comparison ////////////////////////////////////////////////////////////// + EXPECT_TRUE(out_cnts_gapi.size() == out_cnts_ocv.size()); + + cv::Mat out_mat_ocv = cv::Mat(cv::Size{ in.cols, in.rows }, in.type(), cv::Scalar::all(0)); + cv::Mat out_mat_gapi = cv::Mat(cv::Size{ in.cols, in.rows }, in.type(), cv::Scalar::all(0)); + cv::fillPoly(out_mat_ocv, out_cnts_ocv, cv::Scalar::all(1)); + cv::fillPoly(out_mat_gapi, out_cnts_gapi, cv::Scalar::all(1)); + EXPECT_TRUE(cmpF(out_mat_ocv, out_mat_gapi)); + if (optional == HIERARCHY) + { + EXPECT_TRUE(out_hier_ocv.size() == out_hier_gapi.size()); + EXPECT_TRUE(AbsExactVector().to_compare_f()(out_hier_ocv, out_hier_gapi)); + } +} + +template +void findContoursTestBody(const cv::Size& sz, const MatType2& type, const cv::RetrievalModes mode, + const cv::ContourApproximationModes method, const CompareMats& cmpF, + cv::GCompileArgs&& args, const cv::Point& offset = cv::Point()) +{ + cv::Mat in; + initMatForFindingContours(in, sz, type); + + std::vector> out_cnts_gapi; + std::vector out_hier_gapi; + findContoursTestGAPI(in, mode, method, std::move(args), out_cnts_gapi, out_hier_gapi, + offset); + findContoursTestOpenCVCompare(in, mode, method, out_cnts_gapi, out_hier_gapi, cmpF, + offset); +} + +//------------------------------------------------------------------------------------------------- + template static cv::GComputation boundingRectTestGAPI(const In& in, cv::GCompileArgs&& args, cv::Rect& out_rect_gapi) @@ -40,10 +139,59 @@ static void boundingRectTestBody(const In& in, const CompareRects& cmpF, cv::GCo { cv::Rect out_rect_gapi; boundingRectTestGAPI(in, std::move(args), out_rect_gapi); - boundingRectTestOpenCVCompare(in, out_rect_gapi, cmpF); } +//------------------------------------------------------------------------------------------------- + +template +static cv::GComputation fitLineTestGAPI(const In& in, const cv::DistanceTypes distType, + cv::GCompileArgs&& args, cv::Vec4f& out_vec_gapi) +{ + const double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; + + cv::detail::g_type_of_t g_in; + auto out = cv::gapi::fitLine2D(g_in, distType, paramDefault, repsDefault, aepsDefault); + cv::GComputation c(cv::GIn(g_in), cv::GOut(out)); + c.apply(cv::gin(in), cv::gout(out_vec_gapi), std::move(args)); + return c; +} + +template +static cv::GComputation fitLineTestGAPI(const In& in, const cv::DistanceTypes distType, + cv::GCompileArgs&& args, cv::Vec6f& out_vec_gapi) +{ + const double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; + + cv::detail::g_type_of_t g_in; + auto out = cv::gapi::fitLine3D(g_in, distType, paramDefault, repsDefault, aepsDefault); + cv::GComputation c(cv::GIn(g_in), cv::GOut(out)); + c.apply(cv::gin(in), cv::gout(out_vec_gapi), std::move(args)); + return c; +} + +template +static void fitLineTestOpenCVCompare(const In& in, const cv::DistanceTypes distType, + const cv::Vec& out_vec_gapi, + const CompareVecs& cmpF) +{ + const double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; + + // OpenCV code ///////////////////////////////////////////////////////////// + cv::Vec out_vec_ocv; + cv::fitLine(in, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault); + // Comparison ////////////////////////////////////////////////////////////// + EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv)); +} + +template +static void fitLineTestBody(const In& in, const cv::DistanceTypes distType, + const CompareVecs& cmpF, cv::GCompileArgs&& args) +{ + cv::Vec out_vec_gapi; + fitLineTestGAPI(in, distType, std::move(args), out_vec_gapi); + fitLineTestOpenCVCompare(in, distType, out_vec_gapi, cmpF); +} } // namespace opencv_test #endif // OPENCV_GAPI_VIDEO_TESTS_COMMON_HPP diff --git a/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp b/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp index 9b076f6421..755d09a6e4 100644 --- a/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp +++ b/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp @@ -52,27 +52,6 @@ namespace rgb2yuyv(in_line_p, out_line_p, in.cols); } } - - // Draw random ellipses on given mat of given size and type - void initMatForFindingContours(cv::Mat& mat, const cv::Size& sz, const int type) - { - cv::RNG& rng = theRNG(); - mat = cv::Mat(sz, type, cv::Scalar::all(0)); - size_t numEllipses = rng.uniform(1, 10); - - for( size_t i = 0; i < numEllipses; i++ ) - { - cv::Point center; - cv::Size axes; - center.x = rng.uniform(0, sz.width); - center.y = rng.uniform(0, sz.height); - axes.width = rng.uniform(2, sz.width); - axes.height = rng.uniform(2, sz.height); - int color = rng.uniform(1, 256); - double angle = rng.uniform(0., 180.); - cv::ellipse(mat, center, axes, angle, 0., 360., color, 1, FILLED); - } - } } TEST_P(Filter2DTest, AccuracyTest) @@ -495,29 +474,7 @@ TEST_P(GoodFeaturesTest, AccuracyTest) TEST_P(FindContoursNoOffsetTest, AccuracyTest) { - std::vector> outCtsOCV, outCtsGAPI; - - initMatForFindingContours(in_mat1, sz, type); - out_mat_gapi = cv::Mat(sz, type, cv::Scalar::all(0)); - out_mat_ocv = cv::Mat(sz, type, cv::Scalar::all(0)); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::findContours(in_mat1, outCtsOCV, mode, method); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - cv::GArray> outCts; - outCts = cv::gapi::findContours(in, mode, method); - cv::GComputation c(GIn(in), GOut(outCts)); - c.apply(gin(in_mat1), gout(outCtsGAPI), getCompileArgs()); - - // Comparison ////////////////////////////////////////////////////////////// - EXPECT_TRUE(outCtsGAPI.size() == outCtsOCV.size()); - cv::fillPoly(out_mat_ocv, outCtsOCV, cv::Scalar::all(1)); - cv::fillPoly(out_mat_gapi, outCtsGAPI, cv::Scalar::all(1)); - EXPECT_TRUE(AbsExact().to_compare_f()(out_mat_ocv, out_mat_gapi)); + findContoursTestBody(sz, type, mode, method, cmpF, getCompileArgs()); } TEST_P(FindContoursOffsetTest, AccuracyTest) @@ -526,63 +483,15 @@ TEST_P(FindContoursOffsetTest, AccuracyTest) const MatType2 type = CV_8UC1; const cv::RetrievalModes mode = cv::RETR_EXTERNAL; const cv::ContourApproximationModes method = cv::CHAIN_APPROX_NONE; + const CompareMats cmpF = AbsExact().to_compare_obj(); const cv::Point offset(15, 15); - std::vector> outCtsOCV, outCtsGAPI; - initMatForFindingContours(in_mat1, sz, type); - out_mat_gapi = cv::Mat(sz, type, cv::Scalar::all(0)); - out_mat_ocv = cv::Mat(sz, type, cv::Scalar::all(0)); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::findContours(in_mat1, outCtsOCV, mode, method, offset); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - GOpaque gOffset; - cv::GArray> outCts; - outCts = cv::gapi::findContours(in, mode, method, gOffset); - cv::GComputation c(GIn(in, gOffset), GOut(outCts)); - c.apply(gin(in_mat1, offset), gout(outCtsGAPI), getCompileArgs()); - - // Comparison ////////////////////////////////////////////////////////////// - EXPECT_TRUE(outCtsGAPI.size() == outCtsOCV.size()); - cv::fillPoly(out_mat_ocv, outCtsOCV, cv::Scalar::all(1)); - cv::fillPoly(out_mat_gapi, outCtsGAPI, cv::Scalar::all(1)); - EXPECT_TRUE(AbsExact().to_compare_f()(out_mat_ocv, out_mat_gapi)); + findContoursTestBody(sz, type, mode, method, cmpF, getCompileArgs(), offset); } TEST_P(FindContoursHNoOffsetTest, AccuracyTest) { - std::vector> outCtsOCV, outCtsGAPI; - std::vector outHierOCV, outHierGAPI; - - initMatForFindingContours(in_mat1, sz, type); - out_mat_gapi = cv::Mat(sz, type, cv::Scalar::all(0)); - out_mat_ocv = cv::Mat(sz, type, cv::Scalar::all(0)); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::findContours(in_mat1, outCtsOCV, outHierOCV, mode, method); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - cv::GArray> outCts; - cv::GArray outHier; - std::tie(outCts, outHier) = cv::gapi::findContoursH(in, mode, method); - cv::GComputation c(GIn(in), GOut(outCts, outHier)); - c.apply(gin(in_mat1), gout(outCtsGAPI, outHierGAPI), getCompileArgs()); - - // Comparison ////////////////////////////////////////////////////////////// - EXPECT_TRUE(outCtsGAPI.size() == outCtsOCV.size()); - cv::fillPoly(out_mat_ocv, outCtsOCV, cv::Scalar::all(1)); - cv::fillPoly(out_mat_gapi, outCtsGAPI, cv::Scalar::all(1)); - EXPECT_TRUE(AbsExact().to_compare_f()(out_mat_ocv, out_mat_gapi)); - - EXPECT_TRUE(outCtsGAPI.size() == outCtsOCV.size()); - EXPECT_TRUE(AbsExactVector().to_compare_f()(outHierOCV, outHierGAPI)); + findContoursTestBody(sz, type, mode, method, cmpF, getCompileArgs()); } TEST_P(FindContoursHOffsetTest, AccuracyTest) @@ -591,36 +500,12 @@ TEST_P(FindContoursHOffsetTest, AccuracyTest) const MatType2 type = CV_8UC1; const cv::RetrievalModes mode = cv::RETR_EXTERNAL; const cv::ContourApproximationModes method = cv::CHAIN_APPROX_NONE; + const CompareMats cmpF = AbsExact().to_compare_obj(); const cv::Point offset(15, 15); std::vector> outCtsOCV, outCtsGAPI; std::vector outHierOCV, outHierGAPI; - initMatForFindingContours(in_mat1, sz, type); - out_mat_gapi = cv::Mat(sz, type, cv::Scalar::all(0)); - out_mat_ocv = cv::Mat(sz, type, cv::Scalar::all(0)); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::findContours(in_mat1, outCtsOCV, outHierOCV, mode, method, offset); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - GOpaque gOffset; - cv::GArray> outCts; - cv::GArray outHier; - std::tie(outCts, outHier) = cv::gapi::findContoursH(in, mode, method, gOffset); - cv::GComputation c(GIn(in, gOffset), GOut(outCts, outHier)); - c.apply(gin(in_mat1, offset), gout(outCtsGAPI, outHierGAPI), getCompileArgs()); - - // Comparison ////////////////////////////////////////////////////////////// - EXPECT_TRUE(outCtsGAPI.size() == outCtsOCV.size()); - cv::fillPoly(out_mat_ocv, outCtsOCV, cv::Scalar::all(1)); - cv::fillPoly(out_mat_gapi, outCtsGAPI, cv::Scalar::all(1)); - EXPECT_TRUE(AbsExact().to_compare_f()(out_mat_ocv, out_mat_gapi)); - - EXPECT_TRUE(outCtsGAPI.size() == outCtsOCV.size()); - EXPECT_TRUE(AbsExactVector().to_compare_f()(outHierOCV, outHierGAPI)); + findContoursTestBody(sz, type, mode, method, cmpF, getCompileArgs(), offset); } TEST_P(BoundingRectMatTest, AccuracyTest) @@ -655,188 +540,60 @@ TEST_P(BoundingRectVector32FTest, AccuracyTest) TEST_P(FitLine2DMatVectorTest, AccuracyTest) { - cv::Vec4f out_vec_gapi, out_vec_ocv; - double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::fitLine2D(in, distType, paramDefault, repsDefault, aepsDefault); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_mat1), cv::gout(out_vec_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::fitLine(in_mat1, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault); - } - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv)); - } + fitLineTestBody(in_mat1, distType, cmpF, getCompileArgs()); } TEST_P(FitLine2DVector32STest, AccuracyTest) { - cv::Vec4f out_vec_gapi, out_vec_ocv; - double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; - std::vector in_vec; initPointsVectorRandU(sz.width, in_vec); - // G-API code ////////////////////////////////////////////////////////////// - cv::GArray in; - auto out = cv::gapi::fitLine2D(in, distType, paramDefault, repsDefault, aepsDefault); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_vec), cv::gout(out_vec_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::fitLine(in_vec, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault); - } - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv)); - } + fitLineTestBody(in_vec, distType, cmpF, getCompileArgs()); } TEST_P(FitLine2DVector32FTest, AccuracyTest) { - cv::Vec4f out_vec_gapi, out_vec_ocv; - double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; - std::vector in_vec; initPointsVectorRandU(sz.width, in_vec); - // G-API code ////////////////////////////////////////////////////////////// - cv::GArray in; - auto out = cv::gapi::fitLine2D(in, distType, paramDefault, repsDefault, aepsDefault); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_vec), cv::gout(out_vec_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::fitLine(in_vec, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault); - } - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv)); - } + fitLineTestBody(in_vec, distType, cmpF, getCompileArgs()); } TEST_P(FitLine2DVector64FTest, AccuracyTest) { - cv::Vec4f out_vec_gapi, out_vec_ocv; - double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; - std::vector in_vec; initPointsVectorRandU(sz.width, in_vec); - // G-API code ////////////////////////////////////////////////////////////// - cv::GArray in; - auto out = cv::gapi::fitLine2D(in, distType, paramDefault, repsDefault, aepsDefault); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_vec), cv::gout(out_vec_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::fitLine(in_vec, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault); - } - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv)); - } + fitLineTestBody(in_vec, distType, cmpF, getCompileArgs()); } TEST_P(FitLine3DMatVectorTest, AccuracyTest) { - cv::Vec6f out_vec_gapi, out_vec_ocv; - double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::fitLine3D(in, distType, paramDefault, repsDefault, aepsDefault); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_mat1), cv::gout(out_vec_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::fitLine(in_mat1, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault); - } - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv)); - } + fitLineTestBody(in_mat1, distType, cmpF, getCompileArgs()); } TEST_P(FitLine3DVector32STest, AccuracyTest) { - cv::Vec6f out_vec_gapi, out_vec_ocv; - double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; - std::vector in_vec; initPointsVectorRandU(sz.width, in_vec); - // G-API code ////////////////////////////////////////////////////////////// - cv::GArray in; - auto out = cv::gapi::fitLine3D(in, distType, paramDefault, repsDefault, aepsDefault); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_vec), cv::gout(out_vec_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::fitLine(in_vec, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault); - } - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv)); - } + fitLineTestBody(in_vec, distType, cmpF, getCompileArgs()); } TEST_P(FitLine3DVector32FTest, AccuracyTest) { - cv::Vec6f out_vec_gapi, out_vec_ocv; - double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; - std::vector in_vec; initPointsVectorRandU(sz.width, in_vec); - // G-API code ////////////////////////////////////////////////////////////// - cv::GArray in; - auto out = cv::gapi::fitLine3D(in, distType, paramDefault, repsDefault, aepsDefault); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_vec), cv::gout(out_vec_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::fitLine(in_vec, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault); - } - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv)); - } + fitLineTestBody(in_vec, distType, cmpF, getCompileArgs()); } TEST_P(FitLine3DVector64FTest, AccuracyTest) { - cv::Vec6f out_vec_gapi, out_vec_ocv; - double paramDefault = 0., repsDefault = 0., aepsDefault = 0.; - std::vector in_vec; initPointsVectorRandU(sz.width, in_vec); - // G-API code ////////////////////////////////////////////////////////////// - cv::GArray in; - auto out = cv::gapi::fitLine3D(in, distType, paramDefault, repsDefault, aepsDefault); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_vec), cv::gout(out_vec_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::fitLine(in_vec, out_vec_ocv, distType, paramDefault, repsDefault, aepsDefault); - } - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_vec_gapi, out_vec_ocv)); - } + fitLineTestBody(in_vec, distType, cmpF, getCompileArgs()); } TEST_P(BGR2RGBTest, AccuracyTest) diff --git a/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp b/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp index 3b8e5f3c64..f3e70c0f9a 100644 --- a/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp +++ b/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp @@ -270,7 +270,8 @@ INSTANTIATE_TEST_CASE_P(FindContoursNoOffsetTestCPU, FindContoursNoOffsetTest, Values(cv::Size(1280, 720)), Values(CV_8UC1), Values(RETR_EXTERNAL), - Values(CHAIN_APPROX_NONE))); + Values(CHAIN_APPROX_NONE), + Values(AbsExact().to_compare_obj()))); INSTANTIATE_TEST_CASE_P(FindContoursOffsetTestCPU, FindContoursOffsetTest, Values(IMGPROC_CPU)); @@ -282,7 +283,8 @@ INSTANTIATE_TEST_CASE_P(FindContoursHNoOffsetTestCPU, FindContoursHNoOffsetTest, Values(CV_8UC1), Values(RETR_EXTERNAL, RETR_LIST, RETR_CCOMP, RETR_TREE), Values(CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, - CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS))); + CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS), + Values(AbsExact().to_compare_obj()))); INSTANTIATE_TEST_CASE_P(FindContoursHNoOffset32STestCPU, FindContoursHNoOffsetTest, Combine(Values(IMGPROC_CPU), @@ -291,7 +293,8 @@ INSTANTIATE_TEST_CASE_P(FindContoursHNoOffset32STestCPU, FindContoursHNoOffsetTe Values(CV_32SC1), Values(RETR_CCOMP, RETR_FLOODFILL), Values(CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, - CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS))); + CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS), + Values(AbsExact().to_compare_obj()))); INSTANTIATE_TEST_CASE_P(FindContoursHOffsetTestCPU, FindContoursHOffsetTest, Values(IMGPROC_CPU));