mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #12990 from rgarnov:gapi_fluid_reshape_support
G-API: Introduce new `reshape()` API (#12990) * Moved initFluidUnits, initLineConsumption, calcLatency, calcSkew to separate functions * Added Fluid::View::allocate method (moved allocation logic from constructor) * Changed util::zip to util::indexed, utilized collectInputMeta in GFluidExecutable constructor * Added makeReshape method to FluidExecutable * Removed m_outputRoi from GFluidExecutable * Added reshape feature * Added switch of resize mapper if agent ratio was changed * Added more TODOs and renamed a function * G-API reshape(): add missing `override` specifiers Fix warnings on all platforms
This commit is contained in:
committed by
Alexander Alekhin
parent
08536943ad
commit
443fed796a
@@ -51,7 +51,7 @@ TEST(FluidBuffer, InputTest)
|
||||
cv::Mat in_mat = cv::Mat::eye(buffer_size, CV_8U);
|
||||
|
||||
cv::gapi::fluid::Buffer buffer(to_own(in_mat), true);
|
||||
cv::gapi::fluid::View view = buffer.mkView(1, 0, {}, false);
|
||||
cv::gapi::fluid::View view = buffer.mkView(0, {});
|
||||
view.priv().reset(1);
|
||||
int this_y = 0;
|
||||
|
||||
@@ -74,7 +74,7 @@ TEST(FluidBuffer, CircularTest)
|
||||
|
||||
cv::gapi::fluid::Buffer buffer(cv::GMatDesc{CV_8U,1,buffer_size}, 3, 1, 0, 1,
|
||||
util::make_optional(cv::gapi::fluid::Border{cv::BORDER_CONSTANT, cv::gapi::own::Scalar(255)}));
|
||||
cv::gapi::fluid::View view = buffer.mkView(3, 1, {}, false);
|
||||
cv::gapi::fluid::View view = buffer.mkView(1, {});
|
||||
view.priv().reset(3);
|
||||
buffer.debug(std::cout);
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "test_precomp.hpp"
|
||||
#include "api/gcomputation_priv.hpp"
|
||||
|
||||
#include <backends/fluid/gfluidcore.hpp>
|
||||
#include <backends/fluid/gfluidimgproc.hpp>
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
@@ -68,4 +71,160 @@ TEST(GComputationCompile, RecompileWithDifferentMeta)
|
||||
EXPECT_NE(&comp1.priv(), &comp2.priv());
|
||||
}
|
||||
|
||||
TEST(GComputationCompile, FluidReshapeWithDifferentDims)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GComputation cc(in, in+in);
|
||||
|
||||
cv::Mat in_mat1 = cv::Mat::eye (32, 32, CV_8UC1);
|
||||
cv::Mat in_mat2 = cv::Mat::zeros(64, 64, CV_8UC1);
|
||||
cv::Mat out_mat;
|
||||
|
||||
cc.apply(in_mat1, out_mat, cv::compile_args(cv::gapi::core::fluid::kernels()));
|
||||
auto comp1 = cc.priv().m_lastCompiled;
|
||||
|
||||
cc.apply(in_mat2, out_mat);
|
||||
auto comp2 = cc.priv().m_lastCompiled;
|
||||
|
||||
// Both compiled objects are actually the same unique executable
|
||||
EXPECT_EQ(&comp1.priv(), &comp2.priv());
|
||||
}
|
||||
|
||||
TEST(GComputationCompile, FluidReshapeResizeDownScale)
|
||||
{
|
||||
cv::Size szOut(4, 4);
|
||||
cv::GMat in;
|
||||
cv::GComputation cc(in, cv::gapi::resize(in, szOut));
|
||||
|
||||
cv::Mat in_mat1( 8, 8, CV_8UC3);
|
||||
cv::Mat in_mat2(16, 16, CV_8UC3);
|
||||
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
cv::Mat out_mat1, out_mat2;
|
||||
|
||||
cc.apply(in_mat1, out_mat1, cv::compile_args(cv::gapi::core::fluid::kernels()));
|
||||
auto comp1 = cc.priv().m_lastCompiled;
|
||||
|
||||
cc.apply(in_mat2, out_mat2);
|
||||
auto comp2 = cc.priv().m_lastCompiled;
|
||||
|
||||
// Both compiled objects are actually the same unique executable
|
||||
EXPECT_EQ(&comp1.priv(), &comp2.priv());
|
||||
|
||||
cv::Mat cv_out_mat1, cv_out_mat2;
|
||||
cv::resize(in_mat1, cv_out_mat1, szOut);
|
||||
cv::resize(in_mat2, cv_out_mat2, szOut);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat1 != cv_out_mat1));
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat2 != cv_out_mat2));
|
||||
}
|
||||
|
||||
TEST(GComputationCompile, FluidReshapeSwitchToUpscaleFromDownscale)
|
||||
{
|
||||
cv::Size szOut(4, 4);
|
||||
cv::GMat in;
|
||||
cv::GComputation cc(in, cv::gapi::resize(in, szOut));
|
||||
|
||||
cv::Mat in_mat1( 8, 8, CV_8UC3);
|
||||
cv::Mat in_mat2( 2, 2, CV_8UC3);
|
||||
cv::Mat in_mat3(16, 16, CV_8UC3);
|
||||
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
cv::randu(in_mat3, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
cv::Mat out_mat1, out_mat2, out_mat3;
|
||||
|
||||
cc.apply(in_mat1, out_mat1, cv::compile_args(cv::gapi::core::fluid::kernels()));
|
||||
auto comp1 = cc.priv().m_lastCompiled;
|
||||
|
||||
cc.apply(in_mat2, out_mat2);
|
||||
auto comp2 = cc.priv().m_lastCompiled;
|
||||
|
||||
cc.apply(in_mat3, out_mat3);
|
||||
auto comp3 = cc.priv().m_lastCompiled;
|
||||
|
||||
EXPECT_EQ(&comp1.priv(), &comp2.priv());
|
||||
EXPECT_EQ(&comp1.priv(), &comp3.priv());
|
||||
|
||||
cv::Mat cv_out_mat1, cv_out_mat2, cv_out_mat3;
|
||||
cv::resize(in_mat1, cv_out_mat1, szOut);
|
||||
cv::resize(in_mat2, cv_out_mat2, szOut);
|
||||
cv::resize(in_mat3, cv_out_mat3, szOut);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat1 != cv_out_mat1));
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat2 != cv_out_mat2));
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat3 != cv_out_mat3));
|
||||
}
|
||||
|
||||
TEST(GComputationCompile, ReshapeBlur)
|
||||
{
|
||||
cv::Size kernelSize{3, 3};
|
||||
cv::GMat in;
|
||||
cv::GComputation cc(in, cv::gapi::blur(in, kernelSize));
|
||||
|
||||
cv::Mat in_mat1( 8, 8, CV_8UC1);
|
||||
cv::Mat in_mat2(16, 16, CV_8UC1);
|
||||
cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
cv::Mat out_mat1, out_mat2;
|
||||
|
||||
cc.apply(in_mat1, out_mat1, cv::compile_args(cv::gapi::imgproc::fluid::kernels()));
|
||||
auto comp1 = cc.priv().m_lastCompiled;
|
||||
|
||||
cc.apply(in_mat2, out_mat2);
|
||||
auto comp2 = cc.priv().m_lastCompiled;
|
||||
|
||||
// Both compiled objects are actually the same unique executable
|
||||
EXPECT_EQ(&comp1.priv(), &comp2.priv());
|
||||
|
||||
cv::Mat cv_out_mat1, cv_out_mat2;
|
||||
cv::blur(in_mat1, cv_out_mat1, kernelSize);
|
||||
cv::blur(in_mat2, cv_out_mat2, kernelSize);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat1 != cv_out_mat1));
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat2 != cv_out_mat2));
|
||||
}
|
||||
|
||||
TEST(GComputationCompile, ReshapeRois)
|
||||
{
|
||||
cv::Size kernelSize{3, 3};
|
||||
cv::Size szOut(8, 8);
|
||||
cv::GMat in;
|
||||
auto blurred = cv::gapi::blur(in, kernelSize);
|
||||
cv::GComputation cc(in, cv::gapi::resize(blurred, szOut));
|
||||
|
||||
cv::Mat first_in_mat(8, 8, CV_8UC3);
|
||||
cv::Mat first_out_mat;
|
||||
auto fluidKernels = cv::gapi::combine(gapi::imgproc::fluid::kernels(),
|
||||
gapi::core::fluid::kernels(),
|
||||
cv::unite_policy::REPLACE);
|
||||
cc.apply(first_in_mat, first_out_mat, cv::compile_args(fluidKernels));
|
||||
auto first_comp = cc.priv().m_lastCompiled;
|
||||
|
||||
constexpr int niter = 4;
|
||||
for (int i = 0; i < niter; i++)
|
||||
{
|
||||
int width = 4 + 2*i;
|
||||
int height = width;
|
||||
cv::Mat in_mat(width, height, CV_8UC3);
|
||||
cv::Mat out_mat = cv::Mat::zeros(szOut, CV_8UC3);
|
||||
|
||||
int x = 0;
|
||||
int y = szOut.height * i / niter;
|
||||
int roiW = szOut.width;
|
||||
int roiH = szOut.height / niter;
|
||||
cv::Rect roi{x, y, roiW, roiH};
|
||||
|
||||
cc.apply(in_mat, out_mat, cv::compile_args(cv::GFluidOutputRois{{to_own(roi)}}));
|
||||
auto comp = cc.priv().m_lastCompiled;
|
||||
|
||||
EXPECT_EQ(&first_comp.priv(), &comp.priv());
|
||||
|
||||
cv::Mat blur_mat, cv_out_mat;
|
||||
cv::blur(in_mat, blur_mat, kernelSize);
|
||||
cv::resize(blur_mat, cv_out_mat, szOut);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat(roi) != cv_out_mat(roi)));
|
||||
}
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
|
||||
Reference in New Issue
Block a user