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
This commit is contained in:
Orest Chura
2020-09-18 17:24:34 +03:00
committed by GitHub
parent d1cdef596c
commit 95fd61c9b4
7 changed files with 94 additions and 23 deletions
@@ -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