1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #19112 from rgarnov:rg/generic_copy_kernel

Generic copy kernel

* Moved RMat wrapping of cv::Mats to StreamingInput

* Generalized GCopy kernel

* Generic GCopy kernel: applied review comments
This commit is contained in:
Ruslan Garnov
2020-12-16 14:18:08 +03:00
committed by GitHub
parent 50baf76cc2
commit f7cab121fe
19 changed files with 161 additions and 180 deletions
@@ -1645,37 +1645,20 @@ TEST(GAPI_Streaming_Desync, StartStop_Stress) {
}
}
GAPI_FLUID_KERNEL(FluidCopy, cv::gapi::core::GCopy, false) {
static const int Window = 1;
static void run(const cv::gapi::fluid::View &in,
cv::gapi::fluid::Buffer &out) {
const uint8_t *in_ptr = in.InLineB(0);
uint8_t *out_ptr = out.OutLineB(0);
const auto in_type = CV_MAKETYPE(in.meta().depth, in.meta().chan);
const auto out_type = CV_MAKETYPE(out.meta().depth, out.meta().chan);
GAPI_Assert(in_type == out_type);
std::copy_n(in_ptr, in.length()*CV_ELEM_SIZE(in_type), out_ptr);
}
};
TEST(GAPI_Streaming_Desync, DesyncObjectConsumedByTwoIslandsViaSeparateDesync) {
// See comment in the implementation of cv::gapi::streaming::desync (.cpp)
cv::GMat in;
cv::GMat tmp = cv::gapi::boxFilter(in, -1, cv::Size(3,3));
cv::GMat tmp1 = cv::gapi::streaming::desync(tmp);
cv::GMat out1 = cv::gapi::copy(tmp1); // ran via Fluid backend
cv::GMat out1 = cv::gapi::copy(tmp1); // ran via Streaming backend
cv::GMat tmp2 = cv::gapi::streaming::desync(tmp);
cv::GMat out2 = tmp2 * 0.5; // ran via OCV backend
auto c = cv::GComputation(cv::GIn(in), cv::GOut(out1, out2));
auto p = cv::gapi::kernels<FluidCopy>();
EXPECT_NO_THROW(c.compileStreaming(cv::compile_args(p)));
EXPECT_NO_THROW(c.compileStreaming());
}
TEST(GAPI_Streaming_Desync, DesyncObjectConsumedByTwoIslandsViaSameDesync) {
@@ -1684,13 +1667,12 @@ TEST(GAPI_Streaming_Desync, DesyncObjectConsumedByTwoIslandsViaSameDesync) {
cv::GMat tmp = cv::gapi::boxFilter(in, -1, cv::Size(3,3));
cv::GMat tmp1 = cv::gapi::streaming::desync(tmp);
cv::GMat out1 = cv::gapi::copy(tmp1); // ran via Fluid backend
cv::GMat out1 = cv::gapi::copy(tmp1); // ran via Streaming backend
cv::GMat out2 = out1 - 0.5*tmp1; // ran via OCV backend
auto c = cv::GComputation(cv::GIn(in), cv::GOut(out1, out2));
auto p = cv::gapi::kernels<FluidCopy>();
EXPECT_NO_THROW(c.compileStreaming(cv::compile_args(p)));
EXPECT_NO_THROW(c.compileStreaming());
}
TEST(GAPI_Streaming, CopyFrame)
@@ -1699,7 +1681,7 @@ TEST(GAPI_Streaming, CopyFrame)
std::string filepath = findDataFile("cv/video/768x576.avi");
cv::GFrame in;
auto out = cv::gapi::streaming::copy(in);
auto out = cv::gapi::copy(in);
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
@@ -1732,13 +1714,50 @@ TEST(GAPI_Streaming, CopyFrame)
}
}
TEST(GAPI_Streaming, CopyMat)
{
initTestDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
cv::GMat in;
auto out = cv::gapi::copy(in);
cv::GComputation comp(cv::GIn(in), cv::GOut(out));
auto cc = comp.compileStreaming();
try {
cc.setSource<cv::gapi::wip::GCaptureSource>(filepath);
} catch(...) {
throw SkipTestException("Video file can not be opened");
}
cv::VideoCapture cap;
cap.open(filepath);
if (!cap.isOpened())
throw SkipTestException("Video file can not be opened");
cv::Mat out_mat;
cv::Mat ocv_mat;
std::size_t num_frames = 0u;
std::size_t max_frames = 10u;
cc.start();
while (cc.pull(cv::gout(out_mat)) && num_frames < max_frames)
{
num_frames++;
cap >> ocv_mat;
EXPECT_EQ(0, cvtest::norm(ocv_mat, out_mat, NORM_INF));
}
}
TEST(GAPI_Streaming, Reshape)
{
initTestDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
cv::GFrame in;
auto out = cv::gapi::streaming::copy(in);
auto out = cv::gapi::copy(in);
cv::GComputation comp(cv::GIn(in), cv::GOut(out));