Merge pull request #18261 from OrestChura:oc/fluid_convert_mask

[G-API]: Fluid: add mask, extend convertTo for CV_16S

* Add Fluid `mask` kernel + Acc. and Perf. tests
 - simple cycle implementation with restrictions on mask type and input/output type like in OCV/GPU kernels (mask - CV_8UC1 only, input/output - CV_8UC1, CV_16UC1, CV_16SC1)

* Added convertions from/to 16S

* `convertTo()` perf tests refactoring
 - add testing of `alpha` and `beta` parameters
 - fixed unreliable comparison
 - added instances to OCV, Fluid and GPU tests according to the changes

* Addressing comments
 - fixed multiple-channel mistake - prohibited multiple-channeling

* Reduced perf tests
pull/18365/head
Orest Chura 4 years ago committed by GitHub
parent d1cdef596c
commit 95fd61c9b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/gapi/perf/common/gapi_core_perf_tests.hpp
  2. 17
      modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp
  3. 11
      modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp
  4. 15
      modules/gapi/perf/cpu/gapi_core_perf_tests_fluid.cpp
  5. 5
      modules/gapi/perf/gpu/gapi_core_perf_tests_gpu.cpp
  6. 52
      modules/gapi/src/backends/fluid/gfluidcore.cpp
  7. 15
      modules/gapi/test/cpu/gapi_core_tests_fluid.cpp

@ -71,7 +71,7 @@ namespace opencv_test
class ConcatVertPerfTest : public TestPerfParams<tuple<cv::Size, MatType, cv::GCompileArgs>> {};
class ConcatVertVecPerfTest : public TestPerfParams<tuple<cv::Size, MatType, cv::GCompileArgs>> {};
class LUTPerfTest : public TestPerfParams<tuple<MatType, MatType, cv::Size, cv::GCompileArgs>> {};
class ConvertToPerfTest : public TestPerfParams<tuple<MatType, int, cv::Size, cv::GCompileArgs>> {};
class ConvertToPerfTest : public TestPerfParams<tuple<compare_f, MatType, int, cv::Size, double, double, cv::GCompileArgs>> {};
class ResizePerfTest : public TestPerfParams<tuple<compare_f, MatType, int, cv::Size, cv::Size, cv::GCompileArgs>> {};
class ResizeFxFyPerfTest : public TestPerfParams<tuple<compare_f, MatType, int, cv::Size, double, double, cv::GCompileArgs>> {};
class ParseSSDBLPerfTest : public TestPerfParams<tuple<cv::Size, float, int, cv::GCompileArgs>>, public ParserSSDTest {};

@ -1829,20 +1829,23 @@ PERF_TEST_P_(LUTPerfTest, TestPerformance)
PERF_TEST_P_(ConvertToPerfTest, TestPerformance)
{
MatType type_mat = get<0>(GetParam());
int depth_to = get<1>(GetParam());
cv::Size sz_in = get<2>(GetParam());
cv::GCompileArgs compile_args = get<3>(GetParam());
int depth_to = -1;
MatType type_mat = -1;
double alpha = 0., beta = 0.;
cv::Size sz_in;
compare_f cmpF;
cv::GCompileArgs compile_args;
std::tie(cmpF, type_mat, depth_to, sz_in, alpha, beta, compile_args) = GetParam();
MatType type_out = CV_MAKETYPE(depth_to, CV_MAT_CN(type_mat));
initMatrixRandU(type_mat, sz_in, type_out);
// OpenCV code ///////////////////////////////////////////////////////////
in_mat1.convertTo(out_mat_ocv, depth_to);
in_mat1.convertTo(out_mat_ocv, depth_to, alpha, beta);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::convertTo(in, depth_to);
auto out = cv::gapi::convertTo(in, depth_to, alpha, beta);
cv::GComputation c(in, out);
// Warm-up graph engine:
@ -1856,7 +1859,7 @@ PERF_TEST_P_(ConvertToPerfTest, TestPerformance)
}
// Comparison ////////////////////////////////////////////////////////////
// FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz_in);
SANITY_CHECK_NOTHING();

@ -268,10 +268,13 @@ INSTANTIATE_TEST_CASE_P(LUTPerfTestCustomCPU, LUTPerfTest,
INSTANTIATE_TEST_CASE_P(ConvertToPerfTestCPU, ConvertToPerfTest,
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_32FC1),
Values(CV_8U, CV_16U, CV_16S, CV_32F),
Values(szSmall128, szVGA, sz720p, sz1080p),
Values(cv::compile_args(CORE_CPU))));
Combine(Values(AbsExact().to_compare_f()),
Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1),
Values(CV_8U, CV_16U, CV_16S, CV_32F),
Values(szSmall128, szVGA, sz720p, sz1080p),
Values(2.5, 1.0),
Values(0.0),
Values(cv::compile_args(CORE_CPU))));
INSTANTIATE_TEST_CASE_P(ResizePerfTestCPU, ResizePerfTest,
Combine(Values(AbsExact().to_compare_f()),

@ -80,10 +80,10 @@ INSTANTIATE_TEST_CASE_P(SubPerfTestFluid, SubPerfTest,
// Values(-1, CV_8U, CV_16U, CV_32F),
// Values(cv::compile_args(CORE_FLUID))));
// INSTANTIATE_TEST_CASE_P(MaskPerfTestFluid, MaskPerfTest,
// Combine(Values(szSmall128, szVGA, sz720p, sz1080p),
// Values(CV_8UC1, CV_16UC1, CV_16SC1),
// Values(cv::compile_args(CORE_FLUID))));
INSTANTIATE_TEST_CASE_P(MaskPerfTestFluid, MaskPerfTest,
Combine(Values(szSmall128, szVGA, sz720p, sz1080p),
Values(CV_8UC1, CV_16UC1, CV_16SC1),
Values(cv::compile_args(CORE_FLUID))));
// INSTANTIATE_TEST_CASE_P(MeanPerfTestFluid, MeanPerfTest,
// Combine(Values(szSmall128, szVGA, sz720p, sz1080p),
@ -271,9 +271,12 @@ INSTANTIATE_TEST_CASE_P(Split3PerfTestFluid, Split3PerfTest,
// Values(cv::compile_args(CORE_FLUID))));
INSTANTIATE_TEST_CASE_P(ConvertToPerfTestFluid, ConvertToPerfTest,
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_32FC1),
Values(CV_8U, CV_16U, CV_32F),
Combine(Values(Tolerance_FloatRel_IntAbs(1e-5, 2).to_compare_f()),
Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1),
Values(CV_8U, CV_16U, CV_16S, CV_32F),
Values(szSmall128, szVGA, sz720p, sz1080p),
Values(2.5, 1.0),
Values(0.0),
Values(cv::compile_args(CORE_FLUID))));
INSTANTIATE_TEST_CASE_P(ResizePerfTestFluid, ResizePerfTest,

@ -267,9 +267,12 @@ INSTANTIATE_TEST_CASE_P(LUTPerfTestCustomGPU, LUTPerfTest,
INSTANTIATE_TEST_CASE_P(ConvertToPerfTestGPU, ConvertToPerfTest,
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_32FC1),
Combine(Values(AbsExact().to_compare_f()),
Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_32FC1),
Values(CV_8U, CV_16U, CV_16S, CV_32F),
Values( szSmall128, szVGA, sz720p, sz1080p ),
Values(2.5, 1.0),
Values(0.0),
Values(cv::compile_args(CORE_GPU))));
INSTANTIATE_TEST_CASE_P(ResizePerfTestGPU, ResizePerfTest,

@ -797,6 +797,50 @@ GAPI_FLUID_KERNEL(GFluidDivRC, cv::gapi::core::GDivRC, false)
}
};
//-------------------
//
// Fluid kernels: mask
//
//-------------------
template<typename DST, typename SRC>
static void run_mask(Buffer &dst, const View &src, const View &mask)
{
static_assert(std::is_same<DST, SRC>::value,
"Input and output types must match");
int length = dst.length(); // dst, src and mask have the same size and are single-channel
const auto *in = src.InLine<SRC>(0);
const auto *in_mask = mask.InLine<uchar>(0);
auto *out = dst.OutLine<DST>();
for (int l=0; l < length; l++)
{
out[l] = in_mask[l] ? in[l] : 0;
}
}
GAPI_FLUID_KERNEL(GFluidMask, cv::gapi::core::GMask, false)
{
static const int Window = 1;
static void run(const View &src, const View &mask, Buffer &dst)
{
if (src.meta().chan != 1 || dst.meta().chan != 1)
CV_Error(cv::Error::StsBadArg, "input and output must be single-channel");
if (mask.meta().chan != 1 || mask.meta().depth != CV_8U)
CV_Error(cv::Error::StsBadArg, "unsupported mask type");
// DST SRC OP __VA_ARGS__
UNARY_(uchar , uchar , run_mask, dst, src, mask);
UNARY_( short, short, run_mask, dst, src, mask);
UNARY_(ushort, ushort, run_mask, dst, src, mask);
CV_Error(cv::Error::StsBadArg, "unsupported combination of types");
}
};
//----------------------------
//
// Fluid math kernels: bitwise
@ -1186,12 +1230,19 @@ GAPI_FLUID_KERNEL(GFluidConvertTo, cv::gapi::core::GConvertTo, false)
// DST SRC OP __VA_ARGS__
UNARY_(uchar , uchar , run_convertto, dst, src, alpha, beta);
UNARY_(uchar , ushort, run_convertto, dst, src, alpha, beta);
UNARY_(uchar , short, run_convertto, dst, src, alpha, beta);
UNARY_(uchar , float, run_convertto, dst, src, alpha, beta);
UNARY_(ushort, uchar , run_convertto, dst, src, alpha, beta);
UNARY_(ushort, ushort, run_convertto, dst, src, alpha, beta);
UNARY_(ushort, short, run_convertto, dst, src, alpha, beta);
UNARY_(ushort, float, run_convertto, dst, src, alpha, beta);
UNARY_( short, uchar , run_convertto, dst, src, alpha, beta);
UNARY_( short, ushort, run_convertto, dst, src, alpha, beta);
UNARY_( short, short, run_convertto, dst, src, alpha, beta);
UNARY_( short, float, run_convertto, dst, src, alpha, beta);
UNARY_( float, uchar , run_convertto, dst, src, alpha, beta);
UNARY_( float, ushort, run_convertto, dst, src, alpha, beta);
UNARY_( float, short, run_convertto, dst, src, alpha, beta);
UNARY_( float, float, run_convertto, dst, src, alpha, beta);
CV_Error(cv::Error::StsBadArg, "unsupported combination of types");
@ -2332,6 +2383,7 @@ cv::gapi::GKernelPackage cv::gapi::core::fluid::kernels()
,GFluidMulCOld
,GFluidDivC
,GFluidDivRC
,GFluidMask
,GFluidAbsDiffC
,GFluidCmpGTScalar
,GFluidCmpGEScalar

@ -65,6 +65,14 @@ INSTANTIATE_TEST_CASE_P(DISABLED_MeanTestFluid, MeanTest,
Values(-1),
Values(CORE_FLUID)));
INSTANTIATE_TEST_CASE_P(MaskTestFluid, MaskTest,
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128)),
Values(-1),
Values(CORE_FLUID)));
INSTANTIATE_TEST_CASE_P(AbsDiffTestFluid, AbsDiffTest,
Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1),
Values(cv::Size(1280, 720),
@ -190,12 +198,11 @@ INSTANTIATE_TEST_CASE_P(LUTTestFluid, LUTTest,
Values(CORE_FLUID)));
INSTANTIATE_TEST_CASE_P(ConvertToFluid, ConvertToTest,
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_32FC1),
Values(cv::Size(1920, 1080),
cv::Size(1280, 720),
Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128)),
Values(CV_8U, CV_16U, CV_32F),
Values(CV_8U, CV_16U, CV_16S, CV_32F),
Values(CORE_FLUID),
Values(Tolerance_FloatRel_IntAbs(1e-5, 2).to_compare_obj()),
Values(2.5, 1.0, -1.0),

Loading…
Cancel
Save