Merge pull request #18196 from mpashchenkov:mp/garray-initialization
[G-API]: Add GArray initialization support * Added GArray initialization (CONST_VALUE, GScalar analog) and test for this * Whitespaces * And one more space * Trailing whitespace * Test name changed. Build with magic commands. * GArray works with rvalue initialization * Code cleanup * Ternary operator in the initialization list.
This commit is contained in:
committed by
GitHub
parent
a07f064e50
commit
830d8d6b75
@@ -28,6 +28,10 @@ G_TYPED_KERNEL(CountCorners, <GScalar(GPointArray)>, "test.array.in")
|
||||
{
|
||||
static GScalarDesc outMeta(const GArrayDesc &) { return empty_scalar_desc(); }
|
||||
};
|
||||
G_TYPED_KERNEL(PointIncrement, <GPointArray(GMat, GPointArray)>, "test.point_increment")
|
||||
{
|
||||
static GArrayDesc outMeta(const GMatDesc&, const GArrayDesc&) { return empty_array_desc(); }
|
||||
};
|
||||
} // namespace ThisTest
|
||||
|
||||
namespace
|
||||
@@ -57,6 +61,15 @@ GAPI_OCV_KERNEL(OCVCountCorners, ThisTest::CountCorners)
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(OCVPointIncrement, ThisTest::PointIncrement)
|
||||
{
|
||||
static void run(const cv::Mat&, const std::vector<cv::Point>& in, std::vector<cv::Point>& out)
|
||||
{
|
||||
for (const auto& el : in)
|
||||
out.emplace_back(el + Point(1,1));
|
||||
}
|
||||
};
|
||||
|
||||
cv::Mat cross(int w, int h)
|
||||
{
|
||||
cv::Mat mat = cv::Mat::eye(h, w, CV_8UC1)*255;
|
||||
@@ -164,6 +177,45 @@ TEST(GArray, TestIntermediateOutput)
|
||||
EXPECT_EQ(10, out_count[0]);
|
||||
}
|
||||
|
||||
TEST(GArray, GArrayConstValInitialization)
|
||||
{
|
||||
std::vector<cv::Point> initial_vec {Point(0,0), Point(1,1), Point(2,2)};
|
||||
std::vector<cv::Point> ref_vec {Point(1,1), Point(2,2), Point(3,3)};
|
||||
std::vector<cv::Point> out_vec;
|
||||
cv::Mat in_mat;
|
||||
|
||||
cv::GComputationT<ThisTest::GPointArray(cv::GMat)> c([&](cv::GMat in)
|
||||
{
|
||||
// Initialization
|
||||
ThisTest::GPointArray test_garray(initial_vec);
|
||||
return ThisTest::PointIncrement::on(in, test_garray);
|
||||
});
|
||||
auto cc = c.compile(cv::descr_of(in_mat),
|
||||
cv::compile_args(cv::gapi::kernels<OCVPointIncrement>()));
|
||||
cc(in_mat, out_vec);
|
||||
|
||||
EXPECT_EQ(ref_vec, out_vec);
|
||||
}
|
||||
|
||||
TEST(GArray, GArrayRValInitialization)
|
||||
{
|
||||
std::vector<cv::Point> ref_vec {Point(1,1), Point(2,2), Point(3,3)};
|
||||
std::vector<cv::Point> out_vec;
|
||||
cv::Mat in_mat;
|
||||
|
||||
cv::GComputationT<ThisTest::GPointArray(cv::GMat)> c([&](cv::GMat in)
|
||||
{
|
||||
// Rvalue initialization
|
||||
ThisTest::GPointArray test_garray({Point(0,0), Point(1,1), Point(2,2)});
|
||||
return ThisTest::PointIncrement::on(in, test_garray);
|
||||
});
|
||||
auto cc = c.compile(cv::descr_of(in_mat),
|
||||
cv::compile_args(cv::gapi::kernels<OCVPointIncrement>()));
|
||||
cc(in_mat, out_vec);
|
||||
|
||||
EXPECT_EQ(ref_vec, out_vec);
|
||||
}
|
||||
|
||||
TEST(GArray_VectorRef, TestMov)
|
||||
{
|
||||
// Warning: this test is testing some not-very-public APIs
|
||||
|
||||
Reference in New Issue
Block a user