Commit 576644a1 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #15236 from dbudniko:dbudniko/g_api_copy_kernels

parents ccecd340 64277440
......@@ -442,6 +442,12 @@ namespace core {
}
};
G_TYPED_KERNEL(GCopy, <GMat(GMat)>, "org.opencv.core.transform.copy") {
static GMatDesc outMeta(GMatDesc in) {
return in;
}
};
G_TYPED_KERNEL(GConcatHor, <GMat(GMat, GMat)>, "org.opencv.imgproc.transform.concatHor") {
static GMatDesc outMeta(GMatDesc l, GMatDesc r) {
return l.withSizeDelta(+r.size.width, 0);
......@@ -1499,6 +1505,19 @@ Output matrix must be of the same depth as input one, size is specified by given
*/
GAPI_EXPORTS GMat crop(const GMat& src, const Rect& rect);
/** @brief Copies a 2D matrix.
The function copies the matrix.
Output matrix must be of the same size and depth as input one.
@note Function textual ID is "org.opencv.core.transform.copy"
@param src input matrix.
@sa crop
*/
GAPI_EXPORTS GMat copy(const GMat& src);
/** @brief Applies horizontal concatenation to given matrices.
The function horizontally concatenates two GMat matrices (with the same number of rows).
......
......@@ -64,6 +64,7 @@ namespace opencv_test
class RemapPerfTest : public TestPerfParams<tuple<cv::Size, MatType, cv::GCompileArgs>> {};
class FlipPerfTest : public TestPerfParams<tuple<cv::Size, MatType, int, cv::GCompileArgs>> {};
class CropPerfTest : public TestPerfParams<tuple<cv::Size, MatType, cv::Rect, cv::GCompileArgs>> {};
class CopyPerfTest : public TestPerfParams<tuple<cv::Size, MatType, cv::GCompileArgs>> {};
class ConcatHorPerfTest : public TestPerfParams<tuple<cv::Size, MatType, cv::GCompileArgs>> {};
class ConcatHorVecPerfTest : public TestPerfParams<tuple<cv::Size, MatType, cv::GCompileArgs>> {};
class ConcatVertPerfTest : public TestPerfParams<tuple<cv::Size, MatType, cv::GCompileArgs>> {};
......
......@@ -1440,6 +1440,40 @@ PERF_TEST_P_(CropPerfTest, TestPerformance)
//------------------------------------------------------------------------------
PERF_TEST_P_(CopyPerfTest, TestPerformance)
{
cv::Size sz_in = get<0>(GetParam());
MatType type = get<1>(GetParam());
cv::GCompileArgs compile_args = get<2>(GetParam());
initMatrixRandU(type, sz_in, type, false);
cv::Size sz_out = sz_in;
// OpenCV code ///////////////////////////////////////////////////////////
cv::Mat(in_mat1).copyTo(out_mat_ocv);
// G-API code ////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::copy(in);
cv::GComputation c(in, out);
// Warm-up graph engine:
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
TEST_CYCLE()
{
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
}
// Comparison ////////////////////////////////////////////////////////////
EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
EXPECT_EQ(out_mat_gapi.size(), sz_out);
SANITY_CHECK_NOTHING();
}
//------------------------------------------------------------------------------
PERF_TEST_P_(ConcatHorPerfTest, TestPerformance)
{
cv::Size sz_out = get<0>(GetParam());
......
......@@ -227,6 +227,11 @@ INSTANTIATE_TEST_CASE_P(CropPerfTestCPU, CropPerfTest,
Values(cv::Rect(10, 8, 20, 35), cv::Rect(4, 10, 37, 50)),
Values(cv::compile_args(CORE_CPU))));
INSTANTIATE_TEST_CASE_P(CopyPerfTestCPU, CopyPerfTest,
Combine(Values(szSmall128, szVGA, sz720p, sz1080p),
Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
Values(cv::compile_args(CORE_CPU))));
INSTANTIATE_TEST_CASE_P(ConcatHorPerfTestCPU, ConcatHorPerfTest,
Combine(Values(szSmall128, szVGA, sz720p, sz1080p),
Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
......
......@@ -226,6 +226,11 @@ INSTANTIATE_TEST_CASE_P(CropPerfTestGPU, CropPerfTest,
Values(cv::Rect(10, 8, 20, 35), cv::Rect(4, 10, 37, 50)),
Values(cv::compile_args(CORE_GPU))));
INSTANTIATE_TEST_CASE_P(CopyPerfTestGPU, CopyPerfTest,
Combine(Values( szSmall128, szVGA, sz720p, sz1080p ),
Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
Values(cv::compile_args(CORE_GPU))));
INSTANTIATE_TEST_CASE_P(ConcatHorPerfTestGPU, ConcatHorPerfTest,
Combine(Values( szSmall128, szVGA, sz720p, sz1080p ),
Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
......
......@@ -323,6 +323,11 @@ GMat crop(const GMat& src, const Rect& rect)
return core::GCrop::on(src, rect);
}
GMat copy(const GMat& src)
{
return core::GCopy::on(src);
}
GMat concatHor(const GMat& src1, const GMat& src2)
{
return core::GConcatHor::on(src1, src2);
......
......@@ -501,6 +501,14 @@ GAPI_OCV_KERNEL(GCPUCrop, cv::gapi::core::GCrop)
}
};
GAPI_OCV_KERNEL(GCPUCopy, cv::gapi::core::GCopy)
{
static void run(const cv::Mat& in, cv::Mat& out)
{
cv::Mat(in).copyTo(out);
}
};
GAPI_OCV_KERNEL(GCPUConcatHor, cv::gapi::core::GConcatHor)
{
static void run(const cv::Mat& in1, const cv::Mat& in2, cv::Mat& out)
......@@ -611,6 +619,7 @@ cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()
, GCPURemap
, GCPUFlip
, GCPUCrop
, GCPUCopy
, GCPUConcatHor
, GCPUConcatVert
, GCPULUT
......
......@@ -2118,6 +2118,40 @@ GAPI_FLUID_KERNEL(GFluidSqrt, cv::gapi::core::GSqrt, false)
}
};
GAPI_FLUID_KERNEL(GFluidCopy, cv::gapi::core::GCopy, false)
{
static const int Window = 1;
static void run(const View &src, Buffer &dst)
{
const auto *in = src.InLine<uchar>(0);
auto *out = dst.OutLine<uchar>();
GAPI_DbgAssert(dst.length() == src.length());
GAPI_DbgAssert(dst.meta().chan == src.meta().chan);
GAPI_DbgAssert(dst.meta().depth == src.meta().depth);
int width = src.length();
int elem_size = CV_ELEM_SIZE(CV_MAKETYPE(src.meta().depth, src.meta().chan));
int w = 0; // cycle counter
#if CV_SIMD128
for (; w <= width*elem_size-16; w+=16)
{
v_uint8x16 a;
a = v_load(&in[w]);
v_store(&out[w], a);
}
#endif
for (; w < width*elem_size; w++)
{
out[w] = in[w];
}
}
};
} // namespace fliud
} // namespace gapi
} // namespace cv
......@@ -2173,6 +2207,7 @@ cv::gapi::GKernelPackage cv::gapi::core::fluid::kernels()
,GFluidInRange
,GFluidResize
,GFluidSqrt
,GFluidCopy
#if 0
,GFluidMean -- not fluid
,GFluidSum -- not fluid
......
......@@ -482,6 +482,14 @@ GAPI_OCL_KERNEL(GOCLCrop, cv::gapi::core::GCrop)
}
};
GAPI_OCL_KERNEL(GOCLCopy, cv::gapi::core::GCopy)
{
static void run(const cv::UMat& in, cv::UMat& out)
{
cv::UMat(in).copyTo(out);
}
};
GAPI_OCL_KERNEL(GOCLConcatHor, cv::gapi::core::GConcatHor)
{
static void run(const cv::UMat& in1, const cv::UMat& in2, cv::UMat& out)
......@@ -573,6 +581,7 @@ cv::gapi::GKernelPackage cv::gapi::core::ocl::kernels()
, GOCLRemap
, GOCLFlip
, GOCLCrop
, GOCLCopy
, GOCLConcatHor
, GOCLConcatVert
, GOCLLUT
......
......@@ -100,6 +100,7 @@ GAPI_TEST_FIXTURE(Merge4Test, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(RemapTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(FlipTest, initMatrixRandU, FIXTURE_API(int), 1, flipCode)
GAPI_TEST_FIXTURE(CropTest, initMatrixRandU, FIXTURE_API(cv::Rect), 1, rect_to)
GAPI_TEST_FIXTURE(CopyTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(ConcatHorTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConcatVertTest, initNothing, <>, 0)
GAPI_TEST_FIXTURE(ConcatVertVecTest, initNothing, <>, 0)
......
......@@ -1002,6 +1002,32 @@ TEST_P(CropTest, AccuracyTest)
}
}
TEST_P(CopyTest, AccuracyTest)
{
cv::Size sz_out = sz;
if (dtype != -1)
{
out_mat_gapi = cv::Mat(sz_out, dtype);
out_mat_ocv = cv::Mat(sz_out, dtype);
}
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::copy(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::Mat(in_mat1).copyTo(out_mat_ocv);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));
EXPECT_EQ(out_mat_gapi.size(), sz_out);
}
}
TEST_P(ConcatHorTest, AccuracyTest)
{
cv::Size sz_out = sz;
......
......@@ -365,6 +365,14 @@ INSTANTIATE_TEST_CASE_P(CropTestCPU, CropTest,
Values(CORE_CPU),
Values(cv::Rect(10, 8, 20, 35), cv::Rect(4, 10, 37, 50))));
INSTANTIATE_TEST_CASE_P(CopyTestCPU, CopyTest,
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128)),
Values(-1),
Values(CORE_CPU)));
INSTANTIATE_TEST_CASE_P(LUTTestCPU, LUTTest,
Combine(Values(CV_8UC1, CV_8UC3),
Values(cv::Size(1280, 720),
......
......@@ -275,6 +275,14 @@ INSTANTIATE_TEST_CASE_P(ReInitOutTestFluid, ReInitOutTest,
Values(cv::Size(640, 400),
cv::Size(10, 480))));
INSTANTIATE_TEST_CASE_P(CopyTestFluid, CopyTest,
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128)),
Values(-1),
Values(CORE_FLUID)));
//----------------------------------------------------------------------
// FIXME: Clean-up test configurations which are enabled already
#if 0
......
......@@ -336,6 +336,14 @@ INSTANTIATE_TEST_CASE_P(CropTestGPU, CropTest,
Values(CORE_GPU),
Values(cv::Rect(10, 8, 20, 35), cv::Rect(4, 10, 37, 50))));
INSTANTIATE_TEST_CASE_P(CopyTestGPU, CopyTest,
Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128)),
Values(-1),
Values(CORE_GPU)));
INSTANTIATE_TEST_CASE_P(LUTTestGPU, LUTTest,
Combine(Values(CV_8UC1, CV_8UC3),
Values(cv::Size(1280, 720),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment