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

Merge branch 4.x

This commit is contained in:
Alexander Alekhin
2021-12-30 16:23:27 +00:00
951 changed files with 158314 additions and 152668 deletions
@@ -107,12 +107,6 @@ GAPI_TEST_FIXTURE(ThresholdOTTest, initMatrixRandU, FIXTURE_API(int), 1, tt)
GAPI_TEST_FIXTURE(InRangeTest, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(Split3Test, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(Split4Test, initMatrixRandU, <>, 0)
GAPI_TEST_FIXTURE(ResizeTest, initNothing, FIXTURE_API(CompareMats,int,cv::Size), 3,
cmpF, interp, sz_out)
GAPI_TEST_FIXTURE(ResizePTest, initNothing, FIXTURE_API(CompareMats,int,cv::Size), 3,
cmpF, interp, sz_out)
GAPI_TEST_FIXTURE(ResizeTestFxFy, initNothing, FIXTURE_API(CompareMats,int,double,double), 4,
cmpF, interp, fx, fy)
GAPI_TEST_FIXTURE(Merge3Test, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(Merge4Test, initMatsRandU, <>, 0)
GAPI_TEST_FIXTURE(RemapTest, initMatrixRandU, <>, 0)
+28 -100
View File
@@ -138,7 +138,7 @@ TEST_P(MathOpTest, MatricesAccuracyTest)
#else
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
#endif
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -173,7 +173,7 @@ TEST_P(MulDoubleTest, AccuracyTest)
#else
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
#endif
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
TEST_P(DivTest, DISABLED_DivByZeroTest) // https://github.com/opencv/opencv/pull/12826
@@ -195,7 +195,7 @@ TEST_P(DivTest, DISABLED_DivByZeroTest) // https://github.com/opencv/opencv/pul
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -304,7 +304,7 @@ TEST_P(Polar2CartTest, AccuracyTest)
//
// TODO: Make threshold a configurable parameter of this test (ADE-221)
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
cv::Mat &outx = out_mat_gapi,
&outy = out_mat2;
@@ -347,7 +347,7 @@ TEST_P(Cart2PolarTest, AccuracyTest)
//
// TODO: Make threshold a configurable parameter of this test (ADE-221)
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
cv::Mat &outm = out_mat_gapi,
&outa = out_mat2;
@@ -406,7 +406,7 @@ TEST_P(CmpTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
}
}
@@ -464,7 +464,7 @@ TEST_P(BitwiseTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
}
}
@@ -484,7 +484,7 @@ TEST_P(NotTest, AccuracyTest)
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
}
}
@@ -508,7 +508,7 @@ TEST_P(SelectTest, AccuracyTest)
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
}
}
@@ -528,7 +528,7 @@ TEST_P(MinTest, AccuracyTest)
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
}
}
@@ -548,7 +548,7 @@ TEST_P(MaxTest, AccuracyTest)
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
}
}
@@ -568,7 +568,7 @@ TEST_P(AbsDiffTest, AccuracyTest)
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
}
}
@@ -589,7 +589,7 @@ TEST_P(AbsDiffCTest, AccuracyTest)
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
}
}
@@ -659,7 +659,7 @@ TEST_P(AddWeightedTest, AccuracyTest)
}
// Comparison //////////////////////////////////////////////////////////////
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
TEST_P(NormTest, AccuracyTest)
@@ -738,7 +738,7 @@ TEST_P(ThresholdTest, AccuracyTestBinary)
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_L1));
}
}
@@ -764,7 +764,7 @@ TEST_P(ThresholdOTTest, AccuracyTestOtsu)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(ocv_res, out_gapi_scalar.val[0]);
}
}
@@ -788,7 +788,7 @@ TEST_P(InRangeTest, AccuracyTest)
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
}
}
@@ -847,78 +847,6 @@ TEST_P(Split4Test, AccuracyTest)
}
}
static void ResizeAccuracyTest(const CompareMats& cmpF, int type, int interp, cv::Size sz_in,
cv::Size sz_out, double fx, double fy, cv::GCompileArgs&& compile_args)
{
cv::Mat in_mat1 (sz_in, type );
cv::Scalar mean = cv::Scalar::all(127);
cv::Scalar stddev = cv::Scalar::all(40.f);
cv::randn(in_mat1, mean, stddev);
auto out_mat_sz = sz_out.area() == 0 ? cv::Size(saturate_cast<int>(sz_in.width *fx),
saturate_cast<int>(sz_in.height*fy))
: sz_out;
cv::Mat out_mat(out_mat_sz, type);
cv::Mat out_mat_ocv(out_mat_sz, type);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::resize(in, sz_out, fx, fy, interp);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::resize(in_mat1, out_mat_ocv, sz_out, fx, fy, interp);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat, out_mat_ocv));
}
}
TEST_P(ResizeTest, AccuracyTest)
{
ResizeAccuracyTest(cmpF, type, interp, sz, sz_out, 0.0, 0.0, getCompileArgs());
}
TEST_P(ResizeTestFxFy, AccuracyTest)
{
ResizeAccuracyTest(cmpF, type, interp, sz, cv::Size{0, 0}, fx, fy, getCompileArgs());
}
TEST_P(ResizePTest, AccuracyTest)
{
constexpr int planeNum = 3;
cv::Size sz_in_p {sz.width, sz.height*planeNum};
cv::Size sz_out_p{sz_out.width, sz_out.height*planeNum};
cv::Mat in_mat(sz_in_p, CV_8UC1);
cv::randn(in_mat, cv::Scalar::all(127.0f), cv::Scalar::all(40.f));
cv::Mat out_mat (sz_out_p, CV_8UC1);
cv::Mat out_mat_ocv_p(sz_out_p, CV_8UC1);
cv::GMatP in;
auto out = cv::gapi::resizeP(in, sz_out, interp);
cv::GComputation c(cv::GIn(in), cv::GOut(out));
c.compile(cv::descr_of(in_mat).asPlanar(planeNum), getCompileArgs())
(cv::gin(in_mat), cv::gout(out_mat));
for (int i = 0; i < planeNum; i++) {
const cv::Mat in_mat_roi = in_mat(cv::Rect(0, i*sz.height, sz.width, sz.height));
cv::Mat out_mat_roi = out_mat_ocv_p(cv::Rect(0, i*sz_out.height, sz_out.width, sz_out.height));
cv::resize(in_mat_roi, out_mat_roi, sz_out, 0, 0, interp);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat, out_mat_ocv_p));
}
}
TEST_P(Merge3Test, AccuracyTest)
{
cv::Mat in_mat3(sz, type);
@@ -992,7 +920,7 @@ TEST_P(RemapTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -1011,7 +939,7 @@ TEST_P(FlipTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -1037,7 +965,7 @@ TEST_P(CropTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
EXPECT_EQ(out_mat_gapi.size(), sz_out);
EXPECT_EQ(sz_out, out_mat_gapi.size());
}
}
@@ -1063,7 +991,7 @@ TEST_P(CopyTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
EXPECT_EQ(out_mat_gapi.size(), sz_out);
EXPECT_EQ(sz_out, out_mat_gapi.size());
}
}
@@ -1245,7 +1173,7 @@ TEST_P(LUTTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -1269,7 +1197,7 @@ TEST_P(ConvertToTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -1378,7 +1306,7 @@ TEST_P(NormalizeTest, Test)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -1654,7 +1582,7 @@ TEST_P(ReInitOutTest, TestWithAdd)
// Comparison //////////////////////////////////////////////////////////////
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
};
// run for uninitialized output
@@ -1738,7 +1666,7 @@ TEST_P(SizeTest, ParseTest)
cv::GComputation c(cv::GIn(in), cv::GOut(out));
c.apply(cv::gin(in_mat1), cv::gout(out_sz), getCompileArgs());
EXPECT_EQ(out_sz, sz);
EXPECT_EQ(sz, out_sz);
}
TEST_P(SizeRTest, ParseTest)
@@ -1751,7 +1679,7 @@ TEST_P(SizeRTest, ParseTest)
cv::GComputation c(cv::GIn(op_rect), cv::GOut(out));
c.apply(cv::gin(rect), cv::gout(out_sz), getCompileArgs());
EXPECT_EQ(out_sz, sz);
EXPECT_EQ(sz, out_sz);
}
namespace {
@@ -1784,7 +1712,7 @@ TEST_P(SizeMFTest, ParseTest)
cv::GComputation c(cv::GIn(in), cv::GOut(out));
c.apply(cv::gin(frame), cv::gout(out_sz), getCompileArgs());
EXPECT_EQ(out_sz, sz);
EXPECT_EQ(sz, out_sz);
}
} // opencv_test
@@ -119,6 +119,12 @@ GAPI_TEST_FIXTURE(YUV2BGRTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmp
GAPI_TEST_FIXTURE(RGB2HSVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(BayerGR2RGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(RGB2YUV422Test, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)
GAPI_TEST_FIXTURE(ResizeTest, initNothing, FIXTURE_API(CompareMats,int,cv::Size), 3,
cmpF, interp, sz_out)
GAPI_TEST_FIXTURE(ResizePTest, initNothing, FIXTURE_API(CompareMats,int,cv::Size), 3,
cmpF, interp, sz_out)
GAPI_TEST_FIXTURE(ResizeTestFxFy, initNothing, FIXTURE_API(CompareMats,int,double,double), 4,
cmpF, interp, fx, fy)
} // opencv_test
#endif //OPENCV_GAPI_IMGPROC_TESTS_HPP
@@ -92,7 +92,7 @@ TEST_P(Filter2DTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -116,7 +116,7 @@ TEST_P(BoxFilterTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -142,7 +142,7 @@ TEST_P(SepFilterTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -163,7 +163,7 @@ TEST_P(BlurTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -185,7 +185,7 @@ TEST_P(GaussianBlurTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -204,7 +204,7 @@ TEST_P(MedianBlurTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -225,7 +225,7 @@ TEST_P(ErodeTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -246,7 +246,7 @@ TEST_P(Erode3x3Test, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -267,7 +267,7 @@ TEST_P(DilateTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -288,7 +288,7 @@ TEST_P(Dilate3x3Test, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -311,7 +311,7 @@ TEST_P(MorphologyExTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -330,7 +330,7 @@ TEST_P(SobelTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -362,8 +362,8 @@ TEST_P(SobelXYTest, AccuracyTest)
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_TRUE(cmpF(out_mat_gapi2, out_mat_ocv2));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(out_mat_gapi2.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(sz, out_mat_gapi2.size());
}
}
@@ -383,7 +383,7 @@ TEST_P(LaplacianTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -402,7 +402,7 @@ TEST_P(BilateralFilterTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -421,7 +421,7 @@ TEST_P(EqHistTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -440,7 +440,7 @@ TEST_P(CannyTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -611,7 +611,7 @@ TEST_P(BGR2RGBTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -630,7 +630,7 @@ TEST_P(RGB2GrayTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -649,7 +649,7 @@ TEST_P(BGR2GrayTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -668,7 +668,7 @@ TEST_P(RGB2YUVTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -687,7 +687,7 @@ TEST_P(YUV2RGBTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -706,7 +706,7 @@ TEST_P(BGR2I420Test, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 3 / 2));
EXPECT_EQ(Size(sz.width, sz.height * 3 / 2), out_mat_gapi.size());
}
}
@@ -725,7 +725,7 @@ TEST_P(RGB2I420Test, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 3 / 2));
EXPECT_EQ(Size(sz.width, sz.height * 3 / 2), out_mat_gapi.size());
}
}
@@ -744,7 +744,7 @@ TEST_P(I4202BGRTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 2 / 3));
EXPECT_EQ(Size(sz.width, sz.height * 2 / 3), out_mat_gapi.size());
}
}
@@ -763,7 +763,7 @@ TEST_P(I4202RGBTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 2 / 3));
EXPECT_EQ(Size(sz.width, sz.height * 2 / 3), out_mat_gapi.size());
}
}
@@ -787,7 +787,7 @@ TEST_P(NV12toRGBTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -811,7 +811,7 @@ TEST_P(NV12toBGRTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -839,7 +839,7 @@ TEST_P(NV12toGrayTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -882,7 +882,7 @@ TEST_P(NV12toRGBpTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi_planar, out_mat_ocv_planar));
EXPECT_EQ(out_mat_gapi_planar.size(), sz_p);
EXPECT_EQ(sz_p, out_mat_gapi_planar.size());
}
}
@@ -912,7 +912,7 @@ TEST_P(NV12toBGRpTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi_planar, out_mat_ocv_planar));
EXPECT_EQ(out_mat_gapi_planar.size(), sz_p);
EXPECT_EQ(sz_p, out_mat_gapi_planar.size());
}
}
@@ -931,7 +931,7 @@ TEST_P(RGB2LabTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -950,7 +950,7 @@ TEST_P(BGR2LUVTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -969,7 +969,7 @@ TEST_P(LUV2BGRTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -988,7 +988,7 @@ TEST_P(BGR2YUVTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -1007,7 +1007,7 @@ TEST_P(YUV2BGRTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -1026,7 +1026,7 @@ TEST_P(RGB2HSVTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -1045,7 +1045,7 @@ TEST_P(BayerGR2RGBTest, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
@@ -1064,9 +1064,82 @@ TEST_P(RGB2YUV422Test, AccuracyTest)
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
EXPECT_EQ(sz, out_mat_gapi.size());
}
}
static void ResizeAccuracyTest(const CompareMats& cmpF, int type, int interp, cv::Size sz_in,
cv::Size sz_out, double fx, double fy, cv::GCompileArgs&& compile_args)
{
cv::Mat in_mat1 (sz_in, type );
cv::Scalar mean = cv::Scalar::all(127);
cv::Scalar stddev = cv::Scalar::all(40.f);
cv::randn(in_mat1, mean, stddev);
auto out_mat_sz = sz_out.area() == 0 ? cv::Size(saturate_cast<int>(sz_in.width *fx),
saturate_cast<int>(sz_in.height*fy))
: sz_out;
cv::Mat out_mat(out_mat_sz, type);
cv::Mat out_mat_ocv(out_mat_sz, type);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::resize(in, sz_out, fx, fy, interp);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::resize(in_mat1, out_mat_ocv, sz_out, fx, fy, interp);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat, out_mat_ocv));
}
}
TEST_P(ResizeTest, AccuracyTest)
{
ResizeAccuracyTest(cmpF, type, interp, sz, sz_out, 0.0, 0.0, getCompileArgs());
}
TEST_P(ResizeTestFxFy, AccuracyTest)
{
ResizeAccuracyTest(cmpF, type, interp, sz, cv::Size{0, 0}, fx, fy, getCompileArgs());
}
TEST_P(ResizePTest, AccuracyTest)
{
constexpr int planeNum = 3;
cv::Size sz_in_p {sz.width, sz.height*planeNum};
cv::Size sz_out_p{sz_out.width, sz_out.height*planeNum};
cv::Mat in_mat(sz_in_p, CV_8UC1);
cv::randn(in_mat, cv::Scalar::all(127.0f), cv::Scalar::all(40.f));
cv::Mat out_mat (sz_out_p, CV_8UC1);
cv::Mat out_mat_ocv_p(sz_out_p, CV_8UC1);
cv::GMatP in;
auto out = cv::gapi::resizeP(in, sz_out, interp);
cv::GComputation c(cv::GIn(in), cv::GOut(out));
c.compile(cv::descr_of(in_mat).asPlanar(planeNum), getCompileArgs())
(cv::gin(in_mat), cv::gout(out_mat));
for (int i = 0; i < planeNum; i++) {
const cv::Mat in_mat_roi = in_mat(cv::Rect(0, i*sz.height, sz.width, sz.height));
cv::Mat out_mat_roi = out_mat_ocv_p(cv::Rect(0, i*sz_out.height, sz_out.width, sz_out.height));
cv::resize(in_mat_roi, out_mat_roi, sz_out, 0, 0, interp);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat, out_mat_ocv_p));
}
}
} // opencv_test
#endif //OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
@@ -36,7 +36,7 @@ TEST_P(MathOperatorMatScalarTest, OperatorAccuracyTest )
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
}
}
@@ -63,7 +63,7 @@ TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest )
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
}
}
@@ -83,7 +83,7 @@ TEST_P(NotOperatorTest, OperatorAccuracyTest)
}
// Comparison //////////////////////////////////////////////////////////////
{
ASSERT_EQ(out_mat_gapi.size(), sz);
ASSERT_EQ(sz, out_mat_gapi.size());
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
}
}
@@ -0,0 +1,86 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation
#ifndef OPENCV_GAPI_STREAMING_TESTS_COMMON_HPP
#define OPENCV_GAPI_STREAMING_TESTS_COMMON_HPP
#include "gapi_tests_common.hpp"
#include <opencv2/gapi/streaming/onevpl/source.hpp>
#include <opencv2/gapi/streaming/onevpl/data_provider_interface.hpp>
#include "streaming/onevpl/data_provider_defines.hpp"
#ifdef HAVE_ONEVPL
#include "streaming/onevpl/onevpl_export.hpp"
namespace opencv_test {
namespace streaming {
namespace onevpl {
struct StreamDataProvider : public cv::gapi::wip::onevpl::IDataProvider {
StreamDataProvider(std::istream& in) : data_stream (in) {
EXPECT_TRUE(in);
}
mfx_codec_id_type get_mfx_codec_id() const override {
return MFX_CODEC_HEVC;
}
bool fetch_bitstream_data(std::shared_ptr<mfx_bitstream> &out_bitstream) override {
if (empty()) {
return false;
}
if (!out_bitstream) {
out_bitstream = std::make_shared<mfx_bitstream>();
out_bitstream->MaxLength = 2000000;
out_bitstream->Data = (mfxU8 *)calloc(out_bitstream->MaxLength, sizeof(mfxU8));
if(!out_bitstream->Data) {
throw std::runtime_error("Cannot allocate bitstream.Data bytes: " +
std::to_string(out_bitstream->MaxLength * sizeof(mfxU8)));
}
out_bitstream->CodecId = get_mfx_codec_id();
}
mfxU8 *p0 = out_bitstream->Data;
mfxU8 *p1 = out_bitstream->Data + out_bitstream->DataOffset;
EXPECT_FALSE(out_bitstream->DataOffset > out_bitstream->MaxLength - 1);
EXPECT_FALSE(out_bitstream->DataLength + out_bitstream->DataOffset > out_bitstream->MaxLength);
std::copy_n(p1, out_bitstream->DataLength, p0);
out_bitstream->DataOffset = 0;
out_bitstream->DataLength += static_cast<mfxU32>(fetch_data(out_bitstream->MaxLength - out_bitstream->DataLength,
out_bitstream->Data + out_bitstream->DataLength));
return out_bitstream->DataLength != 0;
}
size_t fetch_data(size_t out_data_size, void* out_data_buf) {
data_stream.read(reinterpret_cast<char*>(out_data_buf), out_data_size);
return data_stream.gcount();
}
bool empty() const override {
return data_stream.eof() || data_stream.bad();
}
private:
std::istream& data_stream;
};
static const unsigned char hevc_header[] = {
0x00, 0x00, 0x00, 0x01, 0x40, 0x01, 0x0C, 0x06, 0xFF, 0xFF, 0x01, 0x40, 0x00,
0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x78, 0x00,
0x00, 0x04, 0x02, 0x10, 0x30, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03,
0x01, 0xE5, 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x06, 0x01, 0x40, 0x00, 0x00,
0x03, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x78, 0x00, 0x00,
0xA0, 0x10, 0x20, 0x61, 0x63, 0x41, 0x00, 0x86, 0x49, 0x1B, 0x2B, 0x20, 0x00,
0x00, 0x00, 0x01, 0x44, 0x01, 0xC0, 0x71, 0xC0, 0xD9, 0x20, 0x00, 0x00, 0x00,
0x01, 0x26, 0x01, 0xAF, 0x0C
};
} // namespace onevpl
} // namespace streaming
} // namespace opencv_test
#endif // HAVE_ONEVPL
#endif // OPENCV_GAPI_STREAMING_TESTS_HPP
@@ -58,40 +58,6 @@ namespace
return o;
}
inline bool initTestDataPathSilent()
{
#ifndef WINRT
static bool initialized = false;
if (!initialized)
{
// Since G-API has no own test data (yet), it is taken from the common space
const char* testDataPath = getenv("OPENCV_TEST_DATA_PATH");
if (testDataPath != nullptr) {
cvtest::addDataSearchPath(testDataPath);
initialized = true;
}
}
return initialized;
#endif // WINRT
}
inline void initTestDataPath()
{
bool initialized = initTestDataPathSilent();
GAPI_Assert(initialized &&
"OPENCV_TEST_DATA_PATH environment variable is either not set or set incorrectly.");
}
inline void initTestDataPathOrSkip()
{
bool initialized = initTestDataPathSilent();
if (!initialized)
{
throw cvtest::SkipTestException("Can't find test data");
}
}
template <typename T> inline void initPointRandU(cv::RNG &rng, cv::Point_<T>& pt)
{
GAPI_Assert(std::is_integral<T>::value);
@@ -299,7 +265,6 @@ public:
void initMatFromImage(int type, const std::string& fileName)
{
initTestDataPath();
int channels = (type >> CV_CN_SHIFT) + 1;
GAPI_Assert(channels == 1 || channels == 3 || channels == 4);
@@ -323,7 +288,6 @@ public:
void initMatsFromImages(int channels, const std::string& pattern, int imgNum)
{
initTestDataPath();
GAPI_Assert(channels == 1 || channels == 3 || channels == 4);
const int flags = (channels == 1) ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR;
@@ -78,7 +78,7 @@ TEST_P(BuildPyr_CalcOptFlow_PipelineTest, AccuracyTest)
auto customKernel = gapi::kernels<GCPUMinScalar>();
auto kernels = gapi::combine(customKernel,
params.compileArgs[0].get<gapi::GKernelPackage>());
params.compileArgs[0].get<GKernelPackage>());
params.compileArgs = compile_args(kernels);
OptFlowLKTestOutput outOCV { outPtsOCV, outStatusOCV, outErrOCV };
@@ -92,8 +92,6 @@ TEST_P(BuildPyr_CalcOptFlow_PipelineTest, AccuracyTest)
#ifdef HAVE_OPENCV_VIDEO
TEST_P(BackgroundSubtractorTest, AccuracyTest)
{
initTestDataPath();
cv::gapi::video::BackgroundSubtractorType opType;
double thr = -1;
std::tie(opType, thr) = typeAndThreshold;
@@ -301,42 +301,6 @@ INSTANTIATE_TEST_CASE_P(Split4TestCPU, Split4Test,
Values(CV_8UC1),
Values(CORE_CPU)));
INSTANTIATE_TEST_CASE_P(ResizeTestCPU, ResizeTest,
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),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
Values(cv::Size(64,64),
cv::Size(30,30))));
INSTANTIATE_TEST_CASE_P(ResizePTestCPU, ResizePTest,
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),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_LINEAR),
Values(cv::Size(64,64),
cv::Size(30,30))));
INSTANTIATE_TEST_CASE_P(ResizeTestCPU, ResizeTestFxFy,
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),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
Values(0.5, 0.1),
Values(0.5, 0.1)));
INSTANTIATE_TEST_CASE_P(Merge3TestCPU, Merge3Test,
Combine(Values(CV_8UC1),
Values(cv::Size(1280, 720),
@@ -384,37 +384,6 @@ INSTANTIATE_TEST_CASE_P(InRangeTestFluid, InRangeTest,
Values(-1),
Values(CORE_FLUID)));
INSTANTIATE_TEST_CASE_P(ResizeTestFluid, ResizeTest,
Combine(Values(CV_8UC3/*CV_8UC1, CV_16UC1, CV_16SC1*/),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128),
cv::Size(64, 64),
cv::Size(30, 30)),
Values(-1),
Values(CORE_FLUID),
Values(AbsExact().to_compare_obj()),
Values(/*cv::INTER_NEAREST,*/ cv::INTER_LINEAR/*, cv::INTER_AREA*/),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128),
cv::Size(64, 64),
cv::Size(30, 30))));
INSTANTIATE_TEST_CASE_P(ResizeTestFxFyFluid, ResizeTestFxFy,
Combine(Values(CV_8UC3/*CV_8UC1, CV_16UC1, CV_16SC1*/),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128),
cv::Size(64, 64),
cv::Size(30, 30)),
Values(-1),
Values(CORE_FLUID),
Values(AbsExact().to_compare_obj()),
Values(/*cv::INTER_NEAREST,*/ cv::INTER_LINEAR/*, cv::INTER_AREA*/),
Values(0.5, 1, 2),
Values(0.5, 1, 2)));
INSTANTIATE_TEST_CASE_P(BackendOutputAllocationTestFluid, BackendOutputAllocationTest,
Combine(Values(CV_8UC3, CV_16SC2, CV_32FC1),
Values(cv::Size(50, 50)),
@@ -18,6 +18,42 @@ namespace
namespace opencv_test
{
INSTANTIATE_TEST_CASE_P(ResizeTestCPU, ResizeTest,
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(IMGPROC_CPU),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
Values(cv::Size(64,64),
cv::Size(30,30))));
INSTANTIATE_TEST_CASE_P(ResizePTestCPU, ResizePTest,
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(IMGPROC_CPU),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_LINEAR),
Values(cv::Size(64,64),
cv::Size(30,30))));
INSTANTIATE_TEST_CASE_P(ResizeTestCPU, ResizeTestFxFy,
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(IMGPROC_CPU),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
Values(0.5, 0.1),
Values(0.5, 0.1)));
INSTANTIATE_TEST_CASE_P(Filter2DTestCPU, Filter2DTest,
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
Values(cv::Size(1280, 720),
@@ -16,6 +16,37 @@ namespace
namespace opencv_test
{
INSTANTIATE_TEST_CASE_P(ResizeTestFluid, ResizeTest,
Combine(Values(CV_8UC3/*CV_8UC1, CV_16UC1, CV_16SC1*/),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128),
cv::Size(64, 64),
cv::Size(30, 30)),
Values(-1),
Values(IMGPROC_FLUID),
Values(Tolerance_FloatRel_IntAbs(1e-5, 1).to_compare_obj()),
Values(/*cv::INTER_NEAREST,*/ cv::INTER_LINEAR/*, cv::INTER_AREA*/),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128),
cv::Size(64, 64),
cv::Size(30, 30))));
INSTANTIATE_TEST_CASE_P(ResizeTestFxFyFluid, ResizeTestFxFy,
Combine(Values(CV_8UC3/*CV_8UC1, CV_16UC1, CV_16SC1*/),
Values(cv::Size(1280, 720),
cv::Size(640, 480),
cv::Size(128, 128),
cv::Size(64, 64),
cv::Size(30, 30)),
Values(-1),
Values(IMGPROC_FLUID),
Values(Tolerance_FloatRel_IntAbs(1e-5, 1).to_compare_obj()),
Values(/*cv::INTER_NEAREST,*/ cv::INTER_LINEAR/*, cv::INTER_AREA*/),
Values(0.5, 1, 2),
Values(0.5, 1, 2)));
INSTANTIATE_TEST_CASE_P(RGB2GrayTestFluid, RGB2GrayTest,
Combine(Values(CV_8UC3),
Values(cv::Size(1280, 720),
@@ -43,22 +43,6 @@ namespace opencv_test
//----------------------------------------------- Simple tests ------------------------------------------------
namespace
{
inline void initTestDataPath()
{
#ifndef WINRT
static bool initialized = false;
if (!initialized)
{
// Since G-API has no own test data (yet), it is taken from the common space
const char* testDataPath = getenv("OPENCV_TEST_DATA_PATH");
if (testDataPath) {
cvtest::addDataSearchPath(testDataPath);
}
initialized = true;
}
#endif // WINRT
}
G_TYPED_KERNEL(GCountCalls, <cv::GOpaque<int>(GMat)>, "org.opencv.test.count_calls")
{
static GOpaqueDesc outMeta(GMatDesc /* in */) { return empty_gopaque_desc(); }
@@ -181,8 +165,6 @@ TEST(StatefulKernel, StateIsMutableInRuntime)
TEST(StatefulKernel, StateIsAutoResetForNewStream)
{
initTestDataPath();
cv::GMat in;
cv::GOpaque<bool> out = GIsStateUpToDate::on(in);
cv::GComputation c(cv::GIn(in), cv::GOut(out));
@@ -329,8 +311,6 @@ namespace
TEST(StatefulKernel, StateIsInitViaCompArgsInStreaming)
{
initTestDataPath();
// G-API graph declaration
cv::GMat in;
cv::GMat out = GBackSub::on(in);
@@ -153,9 +153,9 @@ namespace
struct GAPIHeteroTest: public ::testing::Test
{
cv::GComputation m_comp;
cv::gapi::GKernelPackage m_ocv_kernels;
cv::gapi::GKernelPackage m_fluid_kernels;
cv::gapi::GKernelPackage m_hetero_kernels;
cv::GKernelPackage m_ocv_kernels;
cv::GKernelPackage m_fluid_kernels;
cv::GKernelPackage m_hetero_kernels;
cv::Mat m_in_mat;
cv::Mat m_out_mat;
@@ -210,7 +210,7 @@ TEST_F(GAPIHeteroTest, TestBoth)
struct GAPIBigHeteroTest : public ::testing::TestWithParam<std::array<int, 9>>
{
cv::GComputation m_comp;
cv::gapi::GKernelPackage m_kernels;
cv::GKernelPackage m_kernels;
cv::Mat m_in_mat;
cv::Mat m_out_mat1;
@@ -44,14 +44,14 @@ GAPI_OCV_KERNEL(GOCVTestOp, GTestOp)
TEST(GetCompileArgTest, PredefinedArgs)
{
cv::gapi::GKernelPackage pkg = cv::gapi::kernels<GOCVTestOp>();
cv::GKernelPackage pkg = cv::gapi::kernels<GOCVTestOp>();
cv::GCompileArg arg0 { pkg },
arg1 { cv::gapi::use_only { pkg } },
arg2 { cv::graph_dump_path { "fake_path" } };
GCompileArgs compArgs { arg0, arg1, arg2 };
auto kernelPkgOpt = cv::gapi::getCompileArg<cv::gapi::GKernelPackage>(compArgs);
auto kernelPkgOpt = cv::gapi::getCompileArg<cv::GKernelPackage>(compArgs);
GAPI_Assert(kernelPkgOpt.has_value());
EXPECT_NO_THROW(kernelPkgOpt.value().lookup("org.opencv.test.test_op"));
+9 -9
View File
@@ -8,6 +8,7 @@
#include "test_precomp.hpp"
#include "gapi_fluid_test_kernels.hpp"
#include "common/gapi_tests_common.hpp"
namespace opencv_test
{
@@ -40,7 +41,7 @@ GAPI_FLUID_KERNEL(FCopy, TCopy, false)
}
};
GAPI_FLUID_KERNEL(FResizeNN1Lpi, cv::gapi::core::GResize, false)
GAPI_FLUID_KERNEL(FResizeNN1Lpi, cv::gapi::imgproc::GResize, false)
{
static const int Window = 1;
static const auto Kind = GFluidKernel::Kind::Resize;
@@ -202,7 +203,7 @@ struct Mapper
} // namespace areaUpscale
} // anonymous namespace
GAPI_FLUID_KERNEL(FResizeLinear1Lpi, cv::gapi::core::GResize, true)
GAPI_FLUID_KERNEL(FResizeLinear1Lpi, cv::gapi::imgproc::GResize, true)
{
static const int Window = 1;
static const auto Kind = GFluidKernel::Kind::Resize;
@@ -237,7 +238,7 @@ auto endInCoord = [](int outCoord, double ratio) {
};
} // namespace
GAPI_FLUID_KERNEL(FResizeArea1Lpi, cv::gapi::core::GResize, false)
GAPI_FLUID_KERNEL(FResizeArea1Lpi, cv::gapi::imgproc::GResize, false)
{
static const int Window = 1;
static const auto Kind = GFluidKernel::Kind::Resize;
@@ -301,7 +302,7 @@ GAPI_FLUID_KERNEL(FResizeArea1Lpi, cv::gapi::core::GResize, false)
}
};
GAPI_FLUID_KERNEL(FResizeAreaUpscale1Lpi, cv::gapi::core::GResize, true)
GAPI_FLUID_KERNEL(FResizeAreaUpscale1Lpi, cv::gapi::imgproc::GResize, true)
{
static const int Window = 1;
static const auto Kind = GFluidKernel::Kind::Resize;
@@ -325,7 +326,7 @@ GAPI_FLUID_KERNEL(FResizeAreaUpscale1Lpi, cv::gapi::core::GResize, true)
#define ADD_RESIZE_KERNEL_WITH_LPI(interp, lpi, scratch) \
struct Resize##interp##lpi##LpiHelper : public FResize##interp##1Lpi { static const int LPI = lpi; }; \
struct FResize##interp##lpi##Lpi : public cv::GFluidKernelImpl<Resize##interp##lpi##LpiHelper, cv::gapi::core::GResize, scratch>{};
struct FResize##interp##lpi##Lpi : public cv::GFluidKernelImpl<Resize##interp##lpi##LpiHelper, cv::gapi::imgproc::GResize, scratch>{};
ADD_RESIZE_KERNEL_WITH_LPI(NN, 2, false)
ADD_RESIZE_KERNEL_WITH_LPI(NN, 3, false)
@@ -363,7 +364,7 @@ static auto fluidResizeTestPackage = [](int interpolation, cv::Size szIn, cv::Si
default: CV_Assert(false); \
}
GKernelPackage pkg;
cv::GKernelPackage pkg;
switch (interpolation)
{
case INTER_NEAREST: RESIZE_SWITCH(NN); break;
@@ -741,7 +742,7 @@ TEST_P(NV12PlusResizeTest, Test)
auto out = cv::gapi::resize(rgb, out_sz, 0, 0, interp);
cv::GComputation c(cv::GIn(y, uv), cv::GOut(out));
auto pkg = cv::gapi::combine(fluidTestPackage, cv::gapi::core::fluid::kernels());
auto pkg = cv::gapi::combine(fluidTestPackage, cv::gapi::imgproc::fluid::kernels());
c.apply(cv::gin(y_mat, uv_mat), cv::gout(out_mat)
,cv::compile_args(pkg, cv::GFluidOutputRois{{roi}}));
@@ -749,8 +750,7 @@ TEST_P(NV12PlusResizeTest, Test)
cv::Mat rgb_mat;
cv::cvtColor(in_mat, rgb_mat, cv::COLOR_YUV2RGB_NV12);
cv::resize(rgb_mat, out_mat_ocv, out_sz, 0, 0, interp);
EXPECT_EQ(0, cvtest::norm(out_mat(roi), out_mat_ocv(roi), NORM_INF));
EXPECT_TRUE(Tolerance_FloatRel_IntAbs(1e-5, 1).to_compare_f()(out_mat(roi), out_mat_ocv(roi)));
}
INSTANTIATE_TEST_CASE_P(Fluid, NV12PlusResizeTest,
+9 -2
View File
@@ -791,8 +791,15 @@ TEST(Fluid, UnusedNodeOutputCompileTest)
TEST(Fluid, UnusedNodeOutputReshapeTest)
{
const auto test_size = cv::Size(8, 8);
const auto get_compile_args =
[] () { return cv::compile_args(cv::gapi::core::fluid::kernels()); };
const auto get_compile_args = [] () {
return cv::compile_args(
cv::gapi::combine(
cv::gapi::core::fluid::kernels(),
cv::gapi::imgproc::fluid::kernels()
)
);
};
cv::GMat in;
cv::GMat a, b, c, d;
@@ -602,7 +602,7 @@ GMat merge3_4lpi(const GMat& src1, const GMat& src2, const GMat& src3)
return TMerge3_4lpi::on(src1, src2, src3);
}
cv::gapi::GKernelPackage fluidTestPackage = cv::gapi::kernels
cv::GKernelPackage fluidTestPackage = cv::gapi::kernels
<FAddSimple
,FAddCSimple
,FAddScalar
@@ -130,7 +130,7 @@ G_TYPED_KERNEL(TCalcHist, <GArray<int>(GMat)>, "test.ocv.calc_hist")
GMat merge3_4lpi(const GMat& src1, const GMat& src2, const GMat& src3);
std::tuple<GMat, GMat, GMat> split3_4lpi(const GMat& src);
extern cv::gapi::GKernelPackage fluidTestPackage;
extern cv::GKernelPackage fluidTestPackage;
} // namespace gapi_test_kernels
} // namespace cv
+1 -1
View File
@@ -146,7 +146,7 @@ namespace cv
}
};
cv::gapi::GKernelPackage gpuTestPackage = cv::gapi::kernels
cv::GKernelPackage gpuTestPackage = cv::gapi::kernels
<GGPUSymm7x7_test
>();
@@ -13,23 +13,6 @@
namespace opencv_test {
namespace {
void initTestDataPath() {
#ifndef WINRT
static bool initialized = false;
if (!initialized)
{
// Since G-API has no own test data (yet), it is taken from the common space
const char* testDataPath = getenv("OPENCV_TEST_DATA_PATH");
if (testDataPath != nullptr) {
cvtest::addDataSearchPath(testDataPath);
initialized = true;
}
}
#endif // WINRT
}
} // anonymous namespace
TEST(GraphMeta, Trad_AccessInput) {
cv::GMat in;
cv::GMat out1 = cv::gapi::blur(in, cv::Size(3,3));
@@ -91,8 +74,6 @@ TEST(GraphMeta, Trad_AccessOutput) {
}
TEST(GraphMeta, Streaming_AccessInput) {
initTestDataPath();
cv::GMat in;
cv::GMat out1 = cv::gapi::blur(in, cv::Size(3,3));
cv::GOpaque<int64_t> out2 = cv::gapi::streaming::seq_id(in);
@@ -118,8 +99,6 @@ TEST(GraphMeta, Streaming_AccessInput) {
}
TEST(GraphMeta, Streaming_AccessOutput) {
initTestDataPath();
cv::GMat in;
cv::GMat out1 = cv::gapi::blur(in, cv::Size(3,3));
cv::GOpaque<int64_t> out2 = cv::gapi::streaming::seq_id(out1);
@@ -151,8 +130,6 @@ TEST(GraphMeta, Streaming_AccessOutput) {
}
TEST(GraphMeta, Streaming_AccessDesync) {
initTestDataPath();
cv::GMat in;
cv::GOpaque<int64_t> out1 = cv::gapi::streaming::seq_id(in);
cv::GOpaque<int64_t> out2 = cv::gapi::streaming::timestamp(in);
+8 -8
View File
@@ -161,7 +161,7 @@ TEST(GOpaque, TestOpaqueBetween)
c.apply(cv::gin(mat_in), cv::gout(mat_out), cv::compile_args(cv::gapi::kernels<OCVGeneratePoint, OCVPaintPoint>()));
int painted = mat_out.at<uint8_t>(42, 42);
EXPECT_EQ(painted, 77);
EXPECT_EQ(77, painted);
}
TEST(GOpaque, TestOpaqueBetweenIslands)
@@ -181,7 +181,7 @@ TEST(GOpaque, TestOpaqueBetweenIslands)
c.apply(cv::gin(mat_in), cv::gout(mat_out), cv::compile_args(cv::gapi::kernels<OCVGeneratePoint, OCVPaintPoint>()));
int painted = mat_out.at<uint8_t>(42, 42);
EXPECT_EQ(painted, 77);
EXPECT_EQ(77, painted);
}
TEST(GOpaque, TestOpaqueCustomOut2)
@@ -200,11 +200,11 @@ TEST(GOpaque, TestOpaqueCustomOut2)
cv::GComputation c(cv::GIn(in1, in2), cv::GOut(std::get<0>(out), std::get<1>(out)));
c.apply(cv::gin(input1, input2), cv::gout(out1, out2), cv::compile_args(cv::gapi::kernels<OCVGenerateOpaque>()));
EXPECT_EQ(out1.num, input1.size().width * input1.size().height);
EXPECT_EQ(out1.s, str);
EXPECT_EQ(input1.size().width * input1.size().height, out1.num);
EXPECT_EQ(str, out1.s);
EXPECT_EQ(out2.num, input2.size().width * input2.size().height);
EXPECT_EQ(out2.s, str2);
EXPECT_EQ(input2.size().width * input2.size().height, out2.num);
EXPECT_EQ(str2, out2.s);
}
TEST(GOpaque, TestOpaqueOCLBackendIn)
@@ -220,7 +220,7 @@ TEST(GOpaque, TestOpaqueOCLBackendIn)
cv::compile_args(cv::gapi::kernels<OCLPaintPoint>()));
int painted = mat_out.at<uint8_t>(42, 42);
EXPECT_EQ(painted, 77);
EXPECT_EQ(77, painted);
}
TEST(GOpaque, TestOpaqueOCLBackendBetween)
@@ -240,7 +240,7 @@ TEST(GOpaque, TestOpaqueOCLBackendBetween)
cv::compile_args(cv::gapi::kernels<OCLGeneratePoint, OCLPaintPoint>()));
int painted = mat_out.at<uint8_t>(42, 42);
EXPECT_EQ(painted, 77);
EXPECT_EQ(77, painted);
}
TEST(GOpaque, TestOpaqueOCLBackendOut)
+1 -1
View File
@@ -168,7 +168,7 @@ TEST(KernelPackageTransform, CreatePackage)
TEST(KernelPackageTransform, Include)
{
cv::gapi::GKernelPackage pkg;
cv::GKernelPackage pkg;
pkg.include<gmat_in_gmat_out>();
pkg.include<gmat2_in_gmat_out>();
pkg.include<gmat2_in_gmat3_out>();
+36 -4
View File
@@ -4,13 +4,32 @@
//
// Copyright (C) 2018 Intel Corporation
#include "test_precomp.hpp"
#include <type_traits>
#include "test_precomp.hpp"
#include <opencv2/gapi/gtype_traits.hpp>
#include <opencv2/gapi/util/util.hpp>
namespace cv
{
struct Own {};
namespace gapi
{
namespace own
{
struct ConvertibleToOwn{};
struct NotConvertibleToOwn{};
} // own
} // gapi
} // cv
struct NoGhape {};
struct HasGShape {
static constexpr cv::GShape shape = cv::GShape::GFRAME;
};
struct MimicGShape {
static constexpr int shape = 0;
};
#define DISALLOWED_LIST cv::gapi::own::NotConvertibleToOwn
namespace opencv_test
{
@@ -40,4 +59,17 @@ TEST(GAPIUtil, AllButLast)
"[int, float] are NOT all integral types");
}
TEST(GAPIUtil, GShaped)
{
static_assert(!cv::detail::has_gshape<NoGhape>::value, "NoGhape hasn't got any shape");
static_assert(cv::detail::has_gshape<HasGShape>::value, "HasGShape has got GShape shape");
static_assert(!cv::detail::has_gshape<MimicGShape>::value, "MimicGShape hasn't got right shape");
}
TEST(GAPIUtil, GTypeList)
{
static_assert(cv::detail::contains<cv::gapi::own::NotConvertibleToOwn, GAPI_OWN_TYPES_LIST, DISALLOWED_LIST>::value, "NotConvertibleToOwn is in denial list");
static_assert(!cv::detail::contains<cv::gapi::own::ConvertibleToOwn>::value, "ConvertibleToOwn is not in empty denial list");
static_assert(!cv::detail::contains<cv::gapi::own::ConvertibleToOwn, GAPI_OWN_TYPES_LIST, DISALLOWED_LIST>::value, "ConvertibleToOwn is not in denial list");
}
} // namespace opencv_test
@@ -293,30 +293,6 @@ INSTANTIATE_TEST_CASE_P(Split4TestGPU, Split4Test,
Values(CV_8UC1),
Values(CORE_GPU)));
INSTANTIATE_TEST_CASE_P(ResizeTestGPU, ResizeTest,
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),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
Values(cv::Size(64,64),
cv::Size(30,30))));
INSTANTIATE_TEST_CASE_P(ResizeTestGPU, ResizeTestFxFy,
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),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
Values(0.5, 0.1),
Values(0.5, 0.1)));
INSTANTIATE_TEST_CASE_P(Merge3TestGPU, Merge3Test,
Combine(Values(CV_8UC1),
Values(cv::Size(1280, 720),
@@ -17,6 +17,30 @@ namespace
namespace opencv_test
{
INSTANTIATE_TEST_CASE_P(ResizeTestGPU, ResizeTest,
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(IMGPROC_GPU),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
Values(cv::Size(64,64),
cv::Size(30,30))));
INSTANTIATE_TEST_CASE_P(ResizeTestGPU, ResizeTestFxFy,
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(IMGPROC_GPU),
Values(AbsSimilarPoints(2, 0.05).to_compare_obj()),
Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA),
Values(0.5, 0.1),
Values(0.5, 0.1)));
INSTANTIATE_TEST_CASE_P(Filter2DTestGPU, Filter2DTest,
Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1),
Values(cv::Size(1280, 720),
+773 -49
View File
@@ -2,7 +2,7 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2019-2020 Intel Corporation
// Copyright (C) 2019-2021 Intel Corporation
#include "../test_precomp.hpp"
@@ -22,24 +22,23 @@
#include "backends/ie/util.hpp"
#include "backends/ie/giebackend/giewrapper.hpp"
#ifdef HAVE_NGRAPH
#if defined(__clang__) // clang or MSVC clang
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4100)
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#include <ngraph/ngraph.hpp>
#endif
namespace opencv_test
{
namespace {
void initTestDataPath()
{
#ifndef WINRT
static bool initialized = false;
if (!initialized)
{
// Since G-API has no own test data (yet), it is taken from the common space
const char* testDataPath = getenv("OPENCV_TEST_DATA_PATH");
if (testDataPath) {
cvtest::addDataSearchPath(testDataPath);
}
initialized = true;
}
#endif // WINRT
}
class TestMediaBGR final: public cv::MediaFrame::IAdapter {
cv::Mat m_mat;
@@ -139,6 +138,48 @@ void setNetParameters(IE::CNNNetwork& net, bool is_nv12 = false) {
}
}
bool checkDeviceIsAvailable(const std::string& device) {
const static auto available_devices = [&](){
auto devices = cv::gimpl::ie::wrap::getCore().GetAvailableDevices();
return std::unordered_set<std::string>{devices.begin(), devices.end()};
}();
return available_devices.find(device) != available_devices.end();
}
void skipIfDeviceNotAvailable(const std::string& device) {
if (!checkDeviceIsAvailable(device)) {
throw SkipTestException("Device: " + device + " isn't available!");
}
}
void compileBlob(const cv::gapi::ie::detail::ParamDesc& params,
const std::string& output,
const IE::Precision& ip) {
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto net = cv::gimpl::ie::wrap::readNetwork(params);
for (auto&& ii : net.getInputsInfo()) {
ii.second->setPrecision(ip);
}
auto this_network = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
std::ofstream out_file{output, std::ios::out | std::ios::binary};
GAPI_Assert(out_file.is_open());
this_network.Export(out_file);
}
std::string compileAgeGenderBlob(const std::string& device) {
const static std::string blob_path = [&](){
cv::gapi::ie::detail::ParamDesc params;
const std::string model_name = "age-gender-recognition-retail-0013";
const std::string output = model_name + ".blob";
params.model_path = findDataFile(SUBDIR + model_name + ".xml");
params.weights_path = findDataFile(SUBDIR + model_name + ".bin");
params.device_id = device;
compileBlob(params, output, IE::Precision::U8);
return output;
}();
return blob_path;
}
} // anonymous namespace
// TODO: Probably DNN/IE part can be further parametrized with a template
@@ -471,10 +512,10 @@ struct ROIListNV12: public ::testing::Test {
for (auto &&rc : m_roi_list) {
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(rc.x)
, static_cast<std::size_t>(rc.y)
, static_cast<std::size_t>(rc.width)
, static_cast<std::size_t>(rc.height)
, static_cast<std::size_t>(rc.x)
, static_cast<std::size_t>(rc.y)
, static_cast<std::size_t>(rc.width)
, static_cast<std::size_t>(rc.height)
};
infer_request.SetBlob("data", IE::make_shared_blob(frame_blob, ie_rc));
infer_request.Infer();
@@ -534,11 +575,11 @@ struct SingleROI: public ::testing::Test {
auto infer_request = this_network.CreateInferRequest();
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(m_roi.x)
, static_cast<std::size_t>(m_roi.y)
, static_cast<std::size_t>(m_roi.width)
, static_cast<std::size_t>(m_roi.height)
0u
, static_cast<std::size_t>(m_roi.x)
, static_cast<std::size_t>(m_roi.y)
, static_cast<std::size_t>(m_roi.width)
, static_cast<std::size_t>(m_roi.height)
};
IE::Blob::Ptr roi_blob = IE::make_shared_blob(cv::gapi::ie::util::to_ie(m_in_mat), ie_rc);
@@ -596,11 +637,11 @@ struct SingleROINV12: public ::testing::Test {
auto blob = cv::gapi::ie::util::to_ie(m_in_y, m_in_uv);
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(m_roi.x)
, static_cast<std::size_t>(m_roi.y)
, static_cast<std::size_t>(m_roi.width)
, static_cast<std::size_t>(m_roi.height)
0u
, static_cast<std::size_t>(m_roi.x)
, static_cast<std::size_t>(m_roi.y)
, static_cast<std::size_t>(m_roi.width)
, static_cast<std::size_t>(m_roi.height)
};
IE::Blob::Ptr roi_blob = IE::make_shared_blob(blob, ie_rc);
@@ -1433,7 +1474,6 @@ TEST(Infer, SetInvalidNumberOfRequests)
TEST(Infer, TestStreamingInfer)
{
initTestDataPath();
initDLDTDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
@@ -1501,7 +1541,6 @@ TEST(Infer, TestStreamingInfer)
TEST(InferROI, TestStreamingInfer)
{
initTestDataPath();
initDLDTDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
@@ -1580,7 +1619,6 @@ TEST(InferROI, TestStreamingInfer)
TEST(InferList, TestStreamingInfer)
{
initTestDataPath();
initDLDTDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
@@ -1670,7 +1708,6 @@ TEST(InferList, TestStreamingInfer)
TEST(Infer2, TestStreamingInfer)
{
initTestDataPath();
initDLDTDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
@@ -1761,7 +1798,6 @@ TEST(Infer2, TestStreamingInfer)
TEST(InferEmptyList, TestStreamingInfer)
{
initTestDataPath();
initDLDTDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
@@ -1816,7 +1852,6 @@ TEST(InferEmptyList, TestStreamingInfer)
TEST(Infer2EmptyList, TestStreamingInfer)
{
initTestDataPath();
initDLDTDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
@@ -2065,7 +2100,7 @@ struct Sync {
class GMockMediaAdapter final: public cv::MediaFrame::IAdapter {
public:
explicit GMockMediaAdapter(cv::Mat m, Sync& sync)
explicit GMockMediaAdapter(cv::Mat m, std::shared_ptr<Sync> sync)
: m_mat(m), m_sync(sync) {
}
@@ -2081,15 +2116,15 @@ public:
~GMockMediaAdapter() {
{
std::lock_guard<std::mutex> lk{m_sync.m};
m_sync.counter--;
std::lock_guard<std::mutex> lk{m_sync->m};
m_sync->counter--;
}
m_sync.cv.notify_one();
m_sync->cv.notify_one();
}
private:
cv::Mat m_mat;
Sync& m_sync;
cv::Mat m_mat;
std::shared_ptr<Sync> m_sync;
};
// NB: This source is needed to simulate real
@@ -2099,15 +2134,16 @@ private:
class GMockSource : public cv::gapi::wip::IStreamSource {
public:
explicit GMockSource(int limit)
: m_limit(limit), m_mat(cv::Size(1920, 1080), CV_8UC3) {
: m_limit(limit), m_mat(cv::Size(1920, 1080), CV_8UC3),
m_sync(new Sync{}) {
cv::randu(m_mat, cv::Scalar::all(0), cv::Scalar::all(255));
}
bool pull(cv::gapi::wip::Data& data) {
std::unique_lock<std::mutex> lk(m_sync.m);
m_sync.counter++;
std::unique_lock<std::mutex> lk(m_sync->m);
m_sync->counter++;
// NB: Can't produce new frames until old ones are released.
m_sync.cv.wait(lk, [this]{return m_sync.counter <= m_limit;});
m_sync->cv.wait(lk, [this]{return m_sync->counter <= m_limit;});
data = cv::MediaFrame::Create<GMockMediaAdapter>(m_mat, m_sync);
return true;
@@ -2118,9 +2154,9 @@ public:
}
private:
int m_limit;
cv::Mat m_mat;
Sync m_sync;
int m_limit;
cv::Mat m_mat;
std::shared_ptr<Sync> m_sync;
};
struct LimitedSourceInfer: public ::testing::Test {
@@ -2187,6 +2223,694 @@ TEST_F(LimitedSourceInfer, ReleaseFrameAsync)
run(max_frames, resources_limit, nireq);
}
TEST(TestAgeGenderIE, InferWithBatch)
{
initDLDTDataPath();
constexpr int batch_size = 4;
cv::gapi::ie::detail::ParamDesc params;
params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
params.device_id = "CPU";
cv::Mat in_mat({batch_size, 3, 320, 240}, CV_8U);
cv::randu(in_mat, 0, 255);
cv::Mat gapi_age, gapi_gender;
// Load & run IE network
IE::Blob::Ptr ie_age, ie_gender;
{
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto net = cv::gimpl::ie::wrap::readNetwork(params);
setNetParameters(net);
net.setBatchSize(batch_size);
auto this_network = cv::gimpl::ie::wrap::loadNetwork(plugin, net, params);
auto infer_request = this_network.CreateInferRequest();
infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
infer_request.Infer();
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GMat in;
cv::GMat age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.weights_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" })
.cfgBatchSize(batch_size);
comp.apply(cv::gin(in_mat), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}
TEST(ImportNetwork, Infer)
{
const std::string device = "MYRIAD";
skipIfDeviceNotAvailable(device);
initDLDTDataPath();
cv::gapi::ie::detail::ParamDesc params;
params.model_path = compileAgeGenderBlob(device);
params.device_id = device;
cv::Mat in_mat(320, 240, CV_8UC3);
cv::randu(in_mat, 0, 255);
cv::Mat gapi_age, gapi_gender;
// Load & run IE network
IE::Blob::Ptr ie_age, ie_gender;
{
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto this_network = cv::gimpl::ie::wrap::importNetwork(plugin, params);
auto infer_request = this_network.CreateInferRequest();
IE::PreProcessInfo info;
info.setResizeAlgorithm(IE::RESIZE_BILINEAR);
infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat), info);
infer_request.Infer();
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GMat in;
cv::GMat age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
comp.apply(cv::gin(in_mat), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}
TEST(ImportNetwork, InferNV12)
{
const std::string device = "MYRIAD";
skipIfDeviceNotAvailable(device);
initDLDTDataPath();
cv::gapi::ie::detail::ParamDesc params;
params.model_path= compileAgeGenderBlob(device);
params.device_id = device;
cv::Size sz{320, 240};
cv::Mat in_y_mat(sz, CV_8UC1);
cv::randu(in_y_mat, 0, 255);
cv::Mat in_uv_mat(sz / 2, CV_8UC2);
cv::randu(in_uv_mat, 0, 255);
cv::Mat gapi_age, gapi_gender;
// Load & run IE network
IE::Blob::Ptr ie_age, ie_gender;
{
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto this_network = cv::gimpl::ie::wrap::importNetwork(plugin, params);
auto infer_request = this_network.CreateInferRequest();
IE::PreProcessInfo info;
info.setResizeAlgorithm(IE::RESIZE_BILINEAR);
info.setColorFormat(IE::ColorFormat::NV12);
infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_y_mat, in_uv_mat), info);
infer_request.Infer();
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GFrame in;
cv::GMat age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
auto frame = MediaFrame::Create<TestMediaNV12>(in_y_mat, in_uv_mat);
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
comp.apply(cv::gin(frame), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}
TEST(ImportNetwork, InferROI)
{
const std::string device = "MYRIAD";
skipIfDeviceNotAvailable(device);
initDLDTDataPath();
cv::gapi::ie::detail::ParamDesc params;
params.model_path = compileAgeGenderBlob(device);
params.device_id = device;
cv::Mat in_mat(320, 240, CV_8UC3);
cv::randu(in_mat, 0, 255);
cv::Mat gapi_age, gapi_gender;
cv::Rect rect(cv::Point{64, 60}, cv::Size{96, 96});
// Load & run IE network
IE::Blob::Ptr ie_age, ie_gender;
{
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto this_network = cv::gimpl::ie::wrap::importNetwork(plugin, params);
auto infer_request = this_network.CreateInferRequest();
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(rect.x)
, static_cast<std::size_t>(rect.y)
, static_cast<std::size_t>(rect.width)
, static_cast<std::size_t>(rect.height)
};
IE::Blob::Ptr roi_blob = IE::make_shared_blob(cv::gapi::ie::util::to_ie(in_mat), ie_rc);
IE::PreProcessInfo info;
info.setResizeAlgorithm(IE::RESIZE_BILINEAR);
infer_request.SetBlob("data", roi_blob, info);
infer_request.Infer();
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GMat in;
cv::GOpaque<cv::Rect> roi;
cv::GMat age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(roi, in);
cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
comp.apply(cv::gin(in_mat, rect), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}
TEST(ImportNetwork, InferROINV12)
{
const std::string device = "MYRIAD";
skipIfDeviceNotAvailable(device);
initDLDTDataPath();
cv::gapi::ie::detail::ParamDesc params;
params.model_path = compileAgeGenderBlob(device);
params.device_id = device;
cv::Size sz{320, 240};
cv::Mat in_y_mat(sz, CV_8UC1);
cv::randu(in_y_mat, 0, 255);
cv::Mat in_uv_mat(sz / 2, CV_8UC2);
cv::randu(in_uv_mat, 0, 255);
cv::Rect rect(cv::Point{64, 60}, cv::Size{96, 96});
cv::Mat gapi_age, gapi_gender;
// Load & run IE network
IE::Blob::Ptr ie_age, ie_gender;
{
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto this_network = cv::gimpl::ie::wrap::importNetwork(plugin, params);
auto infer_request = this_network.CreateInferRequest();
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(rect.x)
, static_cast<std::size_t>(rect.y)
, static_cast<std::size_t>(rect.width)
, static_cast<std::size_t>(rect.height)
};
IE::Blob::Ptr roi_blob =
IE::make_shared_blob(cv::gapi::ie::util::to_ie(in_y_mat, in_uv_mat), ie_rc);
IE::PreProcessInfo info;
info.setResizeAlgorithm(IE::RESIZE_BILINEAR);
info.setColorFormat(IE::ColorFormat::NV12);
infer_request.SetBlob("data", roi_blob, info);
infer_request.Infer();
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GFrame in;
cv::GOpaque<cv::Rect> roi;
cv::GMat age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(roi, in);
cv::GComputation comp(cv::GIn(in, roi), cv::GOut(age, gender));
auto frame = MediaFrame::Create<TestMediaNV12>(in_y_mat, in_uv_mat);
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
comp.apply(cv::gin(frame, rect), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}
TEST(ImportNetwork, InferList)
{
const std::string device = "MYRIAD";
skipIfDeviceNotAvailable(device);
initDLDTDataPath();
cv::gapi::ie::detail::ParamDesc params;
params.model_path = compileAgeGenderBlob(device);
params.device_id = device;
cv::Mat in_mat(320, 240, CV_8UC3);
cv::randu(in_mat, 0, 255);
std::vector<cv::Rect> roi_list = {
cv::Rect(cv::Point{64, 60}, cv::Size{ 96, 96}),
cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
};
std::vector<cv::Mat> out_ie_ages, out_ie_genders, out_gapi_ages, out_gapi_genders;
// Load & run IE network
{
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto this_network = cv::gimpl::ie::wrap::importNetwork(plugin, params);
auto infer_request = this_network.CreateInferRequest();
for (auto &&rc : roi_list) {
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(rc.x)
, static_cast<std::size_t>(rc.y)
, static_cast<std::size_t>(rc.width)
, static_cast<std::size_t>(rc.height)
};
IE::Blob::Ptr roi_blob =
IE::make_shared_blob(cv::gapi::ie::util::to_ie(in_mat), ie_rc);
IE::PreProcessInfo info;
info.setResizeAlgorithm(IE::RESIZE_BILINEAR);
infer_request.SetBlob("data", roi_blob, info);
infer_request.Infer();
using namespace cv::gapi::ie::util;
out_ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
out_ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
}
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GArray<cv::Rect> rr;
cv::GMat in;
cv::GArray<cv::GMat> age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
comp.apply(cv::gin(in_mat, roi_list), cv::gout(out_gapi_ages, out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
GAPI_Assert(!out_gapi_ages.empty());
ASSERT_EQ(out_gapi_genders.size(), out_gapi_ages.size());
ASSERT_EQ(out_gapi_ages.size(), out_ie_ages.size());
ASSERT_EQ(out_gapi_genders.size(), out_ie_genders.size());
const size_t size = out_gapi_ages.size();
for (size_t i = 0; i < size; ++i) {
normAssert(out_ie_ages [i], out_gapi_ages [i], "Test age output");
normAssert(out_ie_genders[i], out_gapi_genders[i], "Test gender output");
}
}
TEST(ImportNetwork, InferListNV12)
{
const std::string device = "MYRIAD";
skipIfDeviceNotAvailable(device);
initDLDTDataPath();
cv::gapi::ie::detail::ParamDesc params;
params.model_path = compileAgeGenderBlob(device);
params.device_id = device;
cv::Size sz{320, 240};
cv::Mat in_y_mat(sz, CV_8UC1);
cv::randu(in_y_mat, 0, 255);
cv::Mat in_uv_mat(sz / 2, CV_8UC2);
cv::randu(in_uv_mat, 0, 255);
std::vector<cv::Rect> roi_list = {
cv::Rect(cv::Point{64, 60}, cv::Size{ 96, 96}),
cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
};
std::vector<cv::Mat> out_ie_ages, out_ie_genders, out_gapi_ages, out_gapi_genders;
// Load & run IE network
{
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto this_network = cv::gimpl::ie::wrap::importNetwork(plugin, params);
auto infer_request = this_network.CreateInferRequest();
for (auto &&rc : roi_list) {
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(rc.x)
, static_cast<std::size_t>(rc.y)
, static_cast<std::size_t>(rc.width)
, static_cast<std::size_t>(rc.height)
};
IE::Blob::Ptr roi_blob =
IE::make_shared_blob(cv::gapi::ie::util::to_ie(in_y_mat, in_uv_mat), ie_rc);
IE::PreProcessInfo info;
info.setResizeAlgorithm(IE::RESIZE_BILINEAR);
info.setColorFormat(IE::ColorFormat::NV12);
infer_request.SetBlob("data", roi_blob, info);
infer_request.Infer();
using namespace cv::gapi::ie::util;
out_ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
out_ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
}
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GArray<cv::Rect> rr;
cv::GFrame in;
cv::GArray<cv::GMat> age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
auto frame = MediaFrame::Create<TestMediaNV12>(in_y_mat, in_uv_mat);
comp.apply(cv::gin(frame, roi_list), cv::gout(out_gapi_ages, out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
GAPI_Assert(!out_gapi_ages.empty());
ASSERT_EQ(out_gapi_genders.size(), out_gapi_ages.size());
ASSERT_EQ(out_gapi_ages.size(), out_ie_ages.size());
ASSERT_EQ(out_gapi_genders.size(), out_ie_genders.size());
const size_t size = out_gapi_ages.size();
for (size_t i = 0; i < size; ++i) {
normAssert(out_ie_ages [i], out_gapi_ages [i], "Test age output");
normAssert(out_ie_genders[i], out_gapi_genders[i], "Test gender output");
}
}
TEST(ImportNetwork, InferList2)
{
const std::string device = "MYRIAD";
skipIfDeviceNotAvailable(device);
initDLDTDataPath();
cv::gapi::ie::detail::ParamDesc params;
params.model_path = compileAgeGenderBlob(device);
params.device_id = device;
cv::Mat in_mat(320, 240, CV_8UC3);
cv::randu(in_mat, 0, 255);
std::vector<cv::Rect> roi_list = {
cv::Rect(cv::Point{64, 60}, cv::Size{ 96, 96}),
cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
};
std::vector<cv::Mat> out_ie_ages, out_ie_genders, out_gapi_ages, out_gapi_genders;
// Load & run IE network
{
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto this_network = cv::gimpl::ie::wrap::importNetwork(plugin, params);
auto infer_request = this_network.CreateInferRequest();
for (auto &&rc : roi_list) {
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(rc.x)
, static_cast<std::size_t>(rc.y)
, static_cast<std::size_t>(rc.width)
, static_cast<std::size_t>(rc.height)
};
IE::Blob::Ptr roi_blob =
IE::make_shared_blob(cv::gapi::ie::util::to_ie(in_mat), ie_rc);
IE::PreProcessInfo info;
info.setResizeAlgorithm(IE::RESIZE_BILINEAR);
infer_request.SetBlob("data", roi_blob, info);
infer_request.Infer();
using namespace cv::gapi::ie::util;
out_ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
out_ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
}
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GArray<cv::Rect> rr;
cv::GMat in;
cv::GArray<cv::GMat> age, gender;
std::tie(age, gender) = cv::gapi::infer2<AgeGender>(in, rr);
cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
comp.apply(cv::gin(in_mat, roi_list), cv::gout(out_gapi_ages, out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
GAPI_Assert(!out_gapi_ages.empty());
ASSERT_EQ(out_gapi_genders.size(), out_gapi_ages.size());
ASSERT_EQ(out_gapi_ages.size(), out_ie_ages.size());
ASSERT_EQ(out_gapi_genders.size(), out_ie_genders.size());
const size_t size = out_gapi_ages.size();
for (size_t i = 0; i < size; ++i) {
normAssert(out_ie_ages [i], out_gapi_ages [i], "Test age output");
normAssert(out_ie_genders[i], out_gapi_genders[i], "Test gender output");
}
}
TEST(ImportNetwork, InferList2NV12)
{
const std::string device = "MYRIAD";
skipIfDeviceNotAvailable(device);
initDLDTDataPath();
cv::gapi::ie::detail::ParamDesc params;
params.model_path = compileAgeGenderBlob(device);
params.device_id = device;
cv::Size sz{320, 240};
cv::Mat in_y_mat(sz, CV_8UC1);
cv::randu(in_y_mat, 0, 255);
cv::Mat in_uv_mat(sz / 2, CV_8UC2);
cv::randu(in_uv_mat, 0, 255);
std::vector<cv::Rect> roi_list = {
cv::Rect(cv::Point{64, 60}, cv::Size{ 96, 96}),
cv::Rect(cv::Point{50, 32}, cv::Size{128, 160}),
};
std::vector<cv::Mat> out_ie_ages, out_ie_genders, out_gapi_ages, out_gapi_genders;
// Load & run IE network
{
auto plugin = cv::gimpl::ie::wrap::getPlugin(params);
auto this_network = cv::gimpl::ie::wrap::importNetwork(plugin, params);
auto infer_request = this_network.CreateInferRequest();
for (auto &&rc : roi_list) {
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(rc.x)
, static_cast<std::size_t>(rc.y)
, static_cast<std::size_t>(rc.width)
, static_cast<std::size_t>(rc.height)
};
IE::Blob::Ptr roi_blob =
IE::make_shared_blob(cv::gapi::ie::util::to_ie(in_y_mat, in_uv_mat), ie_rc);
IE::PreProcessInfo info;
info.setResizeAlgorithm(IE::RESIZE_BILINEAR);
info.setColorFormat(IE::ColorFormat::NV12);
infer_request.SetBlob("data", roi_blob, info);
infer_request.Infer();
using namespace cv::gapi::ie::util;
out_ie_ages.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
out_ie_genders.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
}
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GArray<cv::Rect> rr;
cv::GFrame in;
cv::GArray<cv::GMat> age, gender;
std::tie(age, gender) = cv::gapi::infer2<AgeGender>(in, rr);
cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
auto frame = MediaFrame::Create<TestMediaNV12>(in_y_mat, in_uv_mat);
comp.apply(cv::gin(frame, roi_list), cv::gout(out_gapi_ages, out_gapi_genders),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
GAPI_Assert(!out_gapi_ages.empty());
ASSERT_EQ(out_gapi_genders.size(), out_gapi_ages.size());
ASSERT_EQ(out_gapi_ages.size(), out_ie_ages.size());
ASSERT_EQ(out_gapi_genders.size(), out_ie_genders.size());
const size_t size = out_gapi_ages.size();
for (size_t i = 0; i < size; ++i) {
normAssert(out_ie_ages [i], out_gapi_ages [i], "Test age output");
normAssert(out_ie_genders[i], out_gapi_genders[i], "Test gender output");
}
}
TEST(TestAgeGender, ThrowBlobAndInputPrecisionMismatch)
{
const std::string device = "MYRIAD";
skipIfDeviceNotAvailable(device);
initDLDTDataPath();
cv::gapi::ie::detail::ParamDesc params;
// NB: Precision for inputs is U8.
params.model_path = compileAgeGenderBlob(device);
params.device_id = device;
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GMat in, age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
params.model_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
cv::Mat in_mat(320, 240, CV_32FC3);
cv::randu(in_mat, 0, 1);
cv::Mat gapi_age, gapi_gender;
// NB: Blob precision is U8, but user pass FP32 data, so exception will be thrown.
// Now exception comes directly from IE, but since G-API has information
// about data precision at the compile stage, consider the possibility of
// throwing exception from there.
EXPECT_ANY_THROW(comp.apply(cv::gin(in_mat), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp))));
}
#ifdef HAVE_NGRAPH
TEST(Infer, ModelWith2DInputs)
{
const std::string model_name = "ModelWith2DInputs";
const std::string model_path = model_name + ".xml";
const std::string weights_path = model_name + ".bin";
const std::string device_id = "CPU";
const int W = 10;
const int H = 5;
// NB: Define model with 2D inputs.
auto in1 = std::make_shared<ngraph::op::Parameter>(
ngraph::element::Type_t::u8,
ngraph::Shape(std::vector<size_t>{(size_t)H, (size_t)W})
);
auto in2 = std::make_shared<ngraph::op::Parameter>(
ngraph::element::Type_t::u8,
ngraph::Shape(std::vector<size_t>{(size_t)H, (size_t)W})
);
auto result = std::make_shared<ngraph::op::v1::Add>(in1, in2);
auto func = std::make_shared<ngraph::Function>(
ngraph::OutputVector{result},
ngraph::ParameterVector{in1, in2}
);
cv::Mat in_mat1(std::vector<int>{H, W}, CV_8U),
in_mat2(std::vector<int>{H, W}, CV_8U),
gapi_mat, ref_mat;
cv::randu(in_mat1, 0, 100);
cv::randu(in_mat2, 0, 100);
cv::add(in_mat1, in_mat2, ref_mat, cv::noArray(), CV_32F);
// Compile xml file
IE::CNNNetwork(func).serialize(model_path);
// Configure & run G-API
cv::GMat g_in1, g_in2;
cv::GInferInputs inputs;
inputs[in1->get_name()] = g_in1;
inputs[in2->get_name()] = g_in2;
auto outputs = cv::gapi::infer<cv::gapi::Generic>(model_name, inputs);
auto out = outputs.at(result->get_name());
cv::GComputation comp(cv::GIn(g_in1, g_in2), cv::GOut(out));
auto pp = cv::gapi::ie::Params<cv::gapi::Generic>(model_name,
model_path,
weights_path,
device_id);
comp.apply(cv::gin(in_mat1, in_mat2), cv::gout(gapi_mat),
cv::compile_args(cv::gapi::networks(pp)));
normAssert(ref_mat, gapi_mat, "Test model output");
}
#endif // HAVE_NGRAPH
} // namespace opencv_test
#endif // HAVE_INF_ENGINE
@@ -83,21 +83,6 @@ cv::Mat initMatrixRandU(const int type, const cv::Size& sz_in) {
namespace opencv_test
{
namespace {
void initTestDataPath()
{
#ifndef WINRT
static bool initialized = false;
if (!initialized)
{
// Since G-API has no own test data (yet), it is taken from the common space
const char* testDataPath = getenv("OPENCV_TEST_DATA_PATH");
if (testDataPath) {
cvtest::addDataSearchPath(testDataPath);
}
initialized = true;
}
#endif // WINRT
}
// FIXME: taken from the DNN module
void normAssert(cv::InputArray& ref, cv::InputArray& test,
@@ -231,7 +216,7 @@ void remapToIESSDOut(const std::vector<cv::Mat> &detections,
}
// SSD-MobilenetV1 structure check
ASSERT_EQ(detections[0].total(), 1u);
ASSERT_EQ(1u, detections[0].total());
ASSERT_EQ(detections[2].total(), detections[0].total() * 100);
ASSERT_EQ(detections[2].total(), detections[3].total());
ASSERT_EQ((detections[2].total() * 4), detections[1].total());
@@ -322,7 +307,6 @@ public:
cv::Mat in_mat;
ONNXtest() {
initTestDataPath();
env = Ort::Env(ORT_LOGGING_LEVEL_WARNING, "test");
memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);
out_gapi.resize(1);
@@ -152,7 +152,7 @@ struct GExecutorReshapeTest: public ::testing::Test
GMockExecutable island2;
std::shared_ptr<GMockBackendImpl> backend_impl2;
cv::gapi::GBackend backend2;
cv::gapi::GKernelPackage pkg;
cv::GKernelPackage pkg;
cv::Mat in_mat1, in_mat2, out_mat;;
};
@@ -102,7 +102,7 @@ TEST(GMetaArg, Can_Get_Metas_From_Input_Run_Args)
GMatDesc m_desc;
GMetaArgs meta_args = descr_of(cv::gin(m, s, v));
EXPECT_EQ(meta_args.size(), 3u);
EXPECT_EQ(3u, meta_args.size());
EXPECT_NO_THROW(m_desc = util::get<cv::GMatDesc>(meta_args[0]));
EXPECT_NO_THROW(util::get<cv::GScalarDesc>(meta_args[1]));
EXPECT_NO_THROW(util::get<cv::GArrayDesc>(meta_args[2]));
@@ -138,22 +138,18 @@ TEST(GMetaArg, Can_Describe_RunArg)
cv::Mat m(3, 3, CV_8UC3);
cv::UMat um(3, 3, CV_8UC3);
cv::Scalar s;
constexpr int w = 3, h = 3, c = 3;
uchar data[w*h*c];
cv::gapi::own::Mat om(h, w, CV_8UC3, data);
cv::Scalar os;
std::vector<int> v;
GMetaArgs metas = {GMetaArg(descr_of(m)),
GMetaArg(descr_of(um)),
GMetaArg(descr_of(s)),
GMetaArg(descr_of(om)),
GMetaArg(descr_of(os)),
GMetaArg(descr_of(v))};
auto in_run_args = cv::gin(m, um, s, om, os, v);
auto in_run_args = cv::gin(m, um, s, os, v);
for (int i = 0; i < 3; i++) {
for (size_t i = 0; i < metas.size(); i++) {
EXPECT_TRUE(can_describe(metas[i], in_run_args[i]));
}
}
@@ -178,22 +174,18 @@ TEST(GMetaArg, Can_Describe_RunArgP)
cv::Mat m(3, 3, CV_8UC3);
cv::UMat um(3, 3, CV_8UC3);
cv::Scalar s;
constexpr int w = 3, h = 3, c = 3;
uchar data[w*h*c];
cv::gapi::own::Mat om(h, w, CV_8UC3, data);
cv::Scalar os;
std::vector<int> v;
GMetaArgs metas = {GMetaArg(descr_of(m)),
GMetaArg(descr_of(um)),
GMetaArg(descr_of(s)),
GMetaArg(descr_of(om)),
GMetaArg(descr_of(os)),
GMetaArg(descr_of(v))};
auto out_run_args = cv::gout(m, um, s, om, os, v);
auto out_run_args = cv::gout(m, um, s, os, v);
for (int i = 0; i < 3; i++) {
for (size_t i = 0; i < metas.size(); i++) {
EXPECT_TRUE(can_describe(metas[i], out_run_args[i]));
}
}
@@ -318,7 +318,7 @@ TEST(PatternMatching, TestPrepResizeSplit3)
r_nh, op1_nh, op2_nh}),
nodes);
EXPECT_EQ(cv::gapi::core::GResize::id(), matching_test::opName(tgm, op1_nh));
EXPECT_EQ(cv::gapi::imgproc::GResize::id(), matching_test::opName(tgm, op1_nh));
EXPECT_EQ(cv::gapi::core::GSplit3::id(), matching_test::opName(tgm, op2_nh));
EXPECT_EQ(1u, tmp_nh->outEdges().size());
@@ -385,7 +385,7 @@ TEST(PatternMatching, TestPrepResizeToNCHW)
EXPECT_EQ(matching_test::S({bgr_nh, tmp_nh, plr_nh, op1_nh, op2_nh}),
nodes);
EXPECT_EQ(cv::gapi::core::GResize::id(), matching_test::opName(tgm, op1_nh));
EXPECT_EQ(cv::gapi::imgproc::GResize::id(), matching_test::opName(tgm, op1_nh));
EXPECT_EQ(GToNCHW::id(), matching_test::opName(tgm, op2_nh));
EXPECT_EQ(1u, tmp_nh->outEdges().size());
@@ -63,7 +63,7 @@ GAPI_OCV_KERNEL(MyNV12toBGRImpl, MyNV12toBGR)
};
G_TYPED_KERNEL(MyPlanarResize, <GMatP(GMatP, Size, int)>, "test.my_planar_resize") {
static GMatDesc outMeta(GMatDesc in, Size sz, int interp) {
return cv::gapi::core::GResizeP::outMeta(in, sz, interp);
return cv::gapi::imgproc::GResizeP::outMeta(in, sz, interp);
}
};
GAPI_OCV_KERNEL(MyPlanarResizeImpl, MyPlanarResize) {
@@ -83,7 +83,7 @@ GAPI_OCV_KERNEL(MyPlanarResizeImpl, MyPlanarResize) {
};
G_TYPED_KERNEL(MyInterleavedResize, <GMat(GMat, Size, int)>, "test.my_interleaved_resize") {
static GMatDesc outMeta(GMatDesc in, Size sz, int interp) {
return cv::gapi::core::GResize::outMeta(in, sz, 0.0, 0.0, interp);
return cv::gapi::imgproc::GResize::outMeta(in, sz, 0.0, 0.0, interp);
}
};
GAPI_OCV_KERNEL(MyInterleavedResizeImpl, MyInterleavedResize) {
@@ -15,7 +15,6 @@ struct ProtoPtrTest : public ::testing::Test { using Type = T; };
using ProtoPtrTestTypes = ::testing::Types< cv::Mat
, cv::UMat
, cv::gapi::own::Mat
, cv::RMat
, cv::Scalar
, std::vector<int>
@@ -6,6 +6,7 @@
#include "../test_precomp.hpp"
#include "../common/gapi_tests_common.hpp"
#include "api/gcomputation_priv.hpp"
#include <opencv2/gapi/fluid/gfluidkernel.hpp>
@@ -103,7 +104,7 @@ TEST(GComputationCompile, FluidReshapeResizeDownScale)
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()));
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);
@@ -115,9 +116,10 @@ TEST(GComputationCompile, FluidReshapeResizeDownScale)
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, cvtest::norm(out_mat1, cv_out_mat1, NORM_INF));
EXPECT_EQ(0, cvtest::norm(out_mat2, cv_out_mat2, NORM_INF));
// Fluid's and OpenCV's resizes aren't bit exact.
// So 1 is here because it is max difference between them.
EXPECT_TRUE(Tolerance_FloatRel_IntAbs(1e-5, 1).to_compare_f()(out_mat1, cv_out_mat1));
EXPECT_TRUE(Tolerance_FloatRel_IntAbs(1e-5, 1).to_compare_f()(out_mat2, cv_out_mat2));
}
TEST(GComputationCompile, FluidReshapeSwitchToUpscaleFromDownscale)
@@ -134,7 +136,7 @@ TEST(GComputationCompile, FluidReshapeSwitchToUpscaleFromDownscale)
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()));
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);
@@ -150,10 +152,11 @@ TEST(GComputationCompile, FluidReshapeSwitchToUpscaleFromDownscale)
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, cvtest::norm(out_mat1, cv_out_mat1, NORM_INF));
EXPECT_EQ(0, cvtest::norm(out_mat2, cv_out_mat2, NORM_INF));
EXPECT_EQ(0, cvtest::norm(out_mat3, cv_out_mat3, NORM_INF));
// Fluid's and OpenCV's Resizes aren't bit exact.
// So 1 is here because it is max difference between them.
EXPECT_TRUE(Tolerance_FloatRel_IntAbs(1e-5, 1).to_compare_f()(out_mat1, cv_out_mat1));
EXPECT_TRUE(Tolerance_FloatRel_IntAbs(1e-5, 1).to_compare_f()(out_mat2, cv_out_mat2));
EXPECT_TRUE(Tolerance_FloatRel_IntAbs(1e-5, 1).to_compare_f()(out_mat3, cv_out_mat3));
}
TEST(GComputationCompile, ReshapeBlur)
@@ -224,8 +227,9 @@ TEST(GComputationCompile, ReshapeRois)
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, cvtest::norm(out_mat(roi), cv_out_mat(roi), NORM_INF));
// Fluid's and OpenCV's resizes aren't bit exact.
// So 1 is here because it is max difference between them.
EXPECT_TRUE(Tolerance_FloatRel_IntAbs(1e-5, 1).to_compare_f()(out_mat(roi), cv_out_mat(roi)));
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ TEST(ConcQueue, PushPop)
{
int x;
q.pop(x);
EXPECT_EQ(x, i);
EXPECT_EQ(i, x);
}
}
@@ -21,7 +21,7 @@ TEST(LastValue, PushPop) {
int x = 1;
v.pop(x);
EXPECT_EQ(x, i);
EXPECT_EQ(i, x);
}
}
+39 -39
View File
@@ -24,12 +24,12 @@ inline std::size_t multiply_dims(Dims const& dims){
TEST(OwnMat, DefaultConstruction)
{
Mat m;
ASSERT_EQ(m.data, nullptr);
ASSERT_EQ(m.cols, 0);
ASSERT_EQ(m.rows, 0);
ASSERT_EQ(m.cols, 0);
ASSERT_EQ(m.type(), 0);
ASSERT_EQ(m.depth(), 0);
ASSERT_EQ(nullptr, m.data);
ASSERT_EQ(0, m.cols);
ASSERT_EQ(0, m.rows);
ASSERT_EQ(0, m.cols);
ASSERT_EQ(0, m.type());
ASSERT_EQ(0, m.depth());
ASSERT_TRUE(m.dims.empty());
ASSERT_TRUE(m.empty());
}
@@ -40,15 +40,15 @@ TEST(OwnMat, Create)
Mat m;
m.create(size, CV_8UC1);
ASSERT_NE(m.data, nullptr);
ASSERT_EQ((cv::gapi::own::Size{m.cols, m.rows}), size);
ASSERT_NE(nullptr, m.data);
ASSERT_EQ(size, (cv::gapi::own::Size{m.cols, m.rows}));
ASSERT_EQ(m.total(), static_cast<size_t>(size.height) * size.width);
ASSERT_EQ(m.type(), CV_8UC1);
ASSERT_EQ(m.depth(), CV_8U);
ASSERT_EQ(m.channels(), 1);
ASSERT_EQ(m.elemSize(), sizeof(uint8_t));
ASSERT_EQ(m.step, sizeof(uint8_t) * m.cols);
ASSERT_EQ(static_cast<size_t>(size.height) * size.width, m.total());
ASSERT_EQ(CV_8UC1, m.type());
ASSERT_EQ(CV_8U, m.depth());
ASSERT_EQ(1, m.channels());
ASSERT_EQ(sizeof(uint8_t), m.elemSize());
ASSERT_EQ(sizeof(uint8_t) * m.cols, m.step);
ASSERT_TRUE(m.dims.empty());
ASSERT_FALSE(m.empty());
}
@@ -59,16 +59,16 @@ TEST(OwnMat, CreateND)
Mat m;
m.create(dims, CV_32F);
ASSERT_NE(nullptr , m.data );
ASSERT_NE(nullptr , m.data);
ASSERT_EQ((cv::gapi::own::Size{0,0}), (cv::gapi::own::Size{m.cols, m.rows}));
ASSERT_EQ(multiply_dims(dims), m.total());
ASSERT_EQ(CV_32F , m.type() );
ASSERT_EQ(CV_32F , m.depth() );
ASSERT_EQ(-1 , m.channels());
ASSERT_EQ(sizeof(float) , m.elemSize());
ASSERT_EQ(0u , m.step );
ASSERT_EQ(dims , m.dims );
ASSERT_EQ(CV_32F, m.type());
ASSERT_EQ(CV_32F, m.depth());
ASSERT_EQ(-1, m.channels());
ASSERT_EQ(sizeof(float), m.elemSize());
ASSERT_EQ(0u, m.step);
ASSERT_EQ(dims, m.dims);
ASSERT_FALSE(m.empty());
}
@@ -78,15 +78,15 @@ TEST(OwnMat, CreateOverload)
Mat m;
m.create(size.height,size.width, CV_8UC1);
ASSERT_NE(m.data, nullptr);
ASSERT_EQ((cv::Size{m.cols, m.rows}), size);
ASSERT_NE(nullptr, m.data);
ASSERT_EQ(size, (cv::Size{m.cols, m.rows}));
ASSERT_EQ(m.total(), static_cast<size_t>(size.height) * size.width);
ASSERT_EQ(m.type(), CV_8UC1);
ASSERT_EQ(m.depth(), CV_8U);
ASSERT_EQ(m.channels(), 1);
ASSERT_EQ(m.elemSize(), sizeof(uint8_t));
ASSERT_EQ(m.step, sizeof(uint8_t) * m.cols);
ASSERT_EQ(static_cast<size_t>(size.height) * size.width, m.total());
ASSERT_EQ(CV_8UC1, m.type());
ASSERT_EQ(CV_8U, m.depth());
ASSERT_EQ(1, m.channels());
ASSERT_EQ(sizeof(uint8_t), m.elemSize());
ASSERT_EQ(sizeof(uint8_t) * m.cols, m.step);
ASSERT_TRUE(m.dims.empty());
ASSERT_FALSE(m.empty());
}
@@ -97,14 +97,14 @@ TEST(OwnMat, Create3chan)
Mat m;
m.create(size, CV_8UC3);
ASSERT_NE(m.data, nullptr);
ASSERT_EQ((cv::Size{m.cols, m.rows}), size);
ASSERT_NE(nullptr, m.data);
ASSERT_EQ(size, (cv::Size{m.cols, m.rows}));
ASSERT_EQ(m.type(), CV_8UC3);
ASSERT_EQ(m.depth(), CV_8U);
ASSERT_EQ(m.channels(), 3);
ASSERT_EQ(m.elemSize(), 3 * sizeof(uint8_t));
ASSERT_EQ(m.step, 3* sizeof(uint8_t) * m.cols);
ASSERT_EQ(CV_8UC3, m.type());
ASSERT_EQ(CV_8U, m.depth());
ASSERT_EQ(3, m.channels());
ASSERT_EQ(3 * sizeof(uint8_t), m.elemSize());
ASSERT_EQ(3 * sizeof(uint8_t) * m.cols, m.step);
ASSERT_TRUE(m.dims.empty());
ASSERT_FALSE(m.empty());
}
@@ -134,7 +134,7 @@ namespace {
};
void ensure_mats_are_same(Mat const& copy, Mat const& m){
EXPECT_NE(copy.data, nullptr);
EXPECT_NE(nullptr, copy.data);
EXPECT_EQ(state_of(copy), state_of(m));
}
}
@@ -157,8 +157,8 @@ struct OwnMatMoveSemantics : NonEmptyMat, ::testing::Test {
void ensure_state_moved_to(Mat const& moved_to)
{
EXPECT_EQ(state_of(moved_to), initial_state);
EXPECT_EQ(state_of(moved_from), state_of(Mat{}));
EXPECT_EQ(state_of(moved_to), initial_state);
EXPECT_EQ(state_of(moved_from), state_of(Mat{}));
}
};
+9 -9
View File
@@ -17,7 +17,7 @@ TEST(Scalar, CreateEmpty)
for (int i = 0; i < 4; ++i)
{
EXPECT_EQ(s[i], 0.0);
EXPECT_EQ(0.0, s[i]);
}
}
@@ -25,20 +25,20 @@ TEST(Scalar, CreateFromVal)
{
cv::gapi::own::Scalar s(5.0);
EXPECT_EQ(s[0], 5.0);
EXPECT_EQ(s[1], 0.0);
EXPECT_EQ(s[2], 0.0);
EXPECT_EQ(s[3], 0.0);
EXPECT_EQ(5.0, s[0]);
EXPECT_EQ(0.0, s[1]);
EXPECT_EQ(0.0, s[2]);
EXPECT_EQ(0.0, s[3]);
}
TEST(Scalar, CreateFromVals)
{
cv::gapi::own::Scalar s(5.3, 3.3, 4.1, -2.0);
EXPECT_EQ(s[0], 5.3);
EXPECT_EQ(s[1], 3.3);
EXPECT_EQ(s[2], 4.1);
EXPECT_EQ(s[3], -2.0);
EXPECT_EQ(5.3, s[0]);
EXPECT_EQ(3.3, s[1]);
EXPECT_EQ(4.1, s[2]);
EXPECT_EQ(-2.0, s[3]);
}
} // namespace opencv_test
@@ -113,10 +113,10 @@ struct RMatIntTestStreaming : public RMatIntTestBase<RMatAdapterT>
};
struct OcvKernels {
cv::gapi::GKernelPackage kernels() { return cv::gapi::imgproc::cpu::kernels(); }
cv::GKernelPackage kernels() { return cv::gapi::imgproc::cpu::kernels(); }
};
struct FluidKernels {
cv::gapi::GKernelPackage kernels() { return cv::gapi::imgproc::fluid::kernels(); }
cv::GKernelPackage kernels() { return cv::gapi::imgproc::fluid::kernels(); }
};
struct RMatIntTestCpuRef : public
+2 -2
View File
@@ -11,7 +11,7 @@
#include <opencv2/gapi/rmat.hpp>
namespace opencv_test {
class RMatAdapterRef : public RMat::Adapter {
class RMatAdapterRef : public RMat::IAdapter {
cv::Mat& m_mat;
bool& m_callbackCalled;
public:
@@ -36,7 +36,7 @@ public:
virtual cv::GMatDesc desc() const override { return cv::descr_of(m_mat); }
};
class RMatAdapterCopy : public RMat::Adapter {
class RMatAdapterCopy : public RMat::IAdapter {
cv::Mat& m_deviceMat;
cv::Mat m_hostMat;
bool& m_callbackCalled;
+2 -2
View File
@@ -94,7 +94,7 @@ TYPED_TEST(RMatTypedTest, CorrectAdapterCast) {
EXPECT_NE(nullptr, this->rmat().template get<T>());
}
class DummyAdapter : public RMat::Adapter {
class DummyAdapter : public RMat::IAdapter {
virtual RMat::View access(RMat::Access) override { return {}; }
virtual cv::GMatDesc desc() const override { return {}; }
};
@@ -103,7 +103,7 @@ TYPED_TEST(RMatTypedTest, IncorrectAdapterCast) {
EXPECT_EQ(nullptr, this->rmat().template get<DummyAdapter>());
}
class RMatAdapterForBackend : public RMat::Adapter {
class RMatAdapterForBackend : public RMat::IAdapter {
int m_i;
public:
RMatAdapterForBackend(int i) : m_i(i) {}
@@ -268,4 +268,13 @@ TEST_F(RMatViewCallbackTest, MagazineInteraction) {
mag.slot<View>().erase(rc);
EXPECT_EQ(1, callbackCalls);
}
TEST(RMatView, Access1DMat) {
cv::Mat m({1}, CV_32FC1);
m.dims = 1;
auto rmat = cv::make_rmat<cv::gimpl::RMatOnMat>(m);
auto view = rmat.access(cv::RMat::Access::R);
auto out = cv::gimpl::asMat(view);
EXPECT_EQ(1, out.dims);
}
} // namespace opencv_test
+1 -1
View File
@@ -127,7 +127,7 @@ template<> struct CompileArgTag<MyCustomTypeNoS11N> {
} // namespace cv
namespace {
class MyRMatAdapter : public cv::RMat::Adapter {
class MyRMatAdapter : public cv::RMat::IAdapter {
cv::Mat m_mat;
int m_value;
std::string m_str;
@@ -0,0 +1,188 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation
#include "../test/common/gapi_tests_common.hpp"
#include "../src/streaming/gstreamer/gstreamer_pipeline_facade.hpp"
#include "../src/streaming/gstreamer/gstreamerptr.hpp"
#include <opencv2/ts.hpp>
#include <thread>
#ifdef HAVE_GSTREAMER
#include <gst/app/gstappsink.h>
namespace opencv_test
{
TEST(GStreamerPipelineFacadeTest, GetElsByFactoryNameUnitTest)
{
auto comparator = [](GstElement* element, const std::string& factoryName) {
cv::gapi::wip::gst::GStreamerPtr<gchar> name(
gst_object_get_name(GST_OBJECT(gst_element_get_factory(element))));
return name && (0 == strcmp(name, factoryName.c_str()));
};
cv::gapi::wip::gst::GStreamerPipelineFacade
pipelineFacade("videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink1 "
"videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink2");
auto videotestsrcs = pipelineFacade.getElementsByFactoryName("videotestsrc");
EXPECT_EQ(2u, videotestsrcs.size());
for (auto&& src : videotestsrcs) {
EXPECT_TRUE(comparator(src, "videotestsrc"));
}
auto appsinks = pipelineFacade.getElementsByFactoryName("appsink");
EXPECT_EQ(2u, appsinks.size());
for (auto&& sink : appsinks) {
EXPECT_TRUE(comparator(sink, "appsink"));
}
}
TEST(GStreamerPipelineFacadeTest, GetElByNameUnitTest)
{
auto comparator = [](GstElement* element, const std::string& elementName) {
cv::gapi::wip::gst::GStreamerPtr<gchar> name(gst_element_get_name(element));
return name && (0 == strcmp(name, elementName.c_str()));
};
cv::gapi::wip::gst::GStreamerPipelineFacade
pipelineFacade("videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink1 "
"videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink2");
auto appsink1 = pipelineFacade.getElementByName("sink1");
GAPI_Assert(appsink1 != nullptr);
EXPECT_TRUE(comparator(appsink1, "sink1"));
auto appsink2 = pipelineFacade.getElementByName("sink2");
GAPI_Assert(appsink2 != nullptr);
EXPECT_TRUE(comparator(appsink2, "sink2"));
}
TEST(GStreamerPipelineFacadeTest, CompletePrerollUnitTest)
{
cv::gapi::wip::gst::GStreamerPipelineFacade
pipelineFacade("videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink1 "
"videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink2");
auto appsink = pipelineFacade.getElementByName("sink1");
pipelineFacade.completePreroll();
cv::gapi::wip::gst::GStreamerPtr<GstSample> prerollSample(
#if GST_VERSION_MINOR >= 10
gst_app_sink_try_pull_preroll(GST_APP_SINK(appsink), 5 * GST_SECOND)
#else // GST_VERSION_MINOR < 10
// TODO: This function may cause hang with some pipelines, need to check whether these
// pipelines are really wrong or not?
gst_app_sink_pull_preroll(GST_APP_SINK(appsink))
#endif // GST_VERSION_MINOR >= 10
);
GAPI_Assert(prerollSample != nullptr);
}
TEST(GStreamerPipelineFacadeTest, PlayUnitTest)
{
cv::gapi::wip::gst::GStreamerPipelineFacade
pipelineFacade("videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink1 "
"videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink2");
auto appsink = pipelineFacade.getElementByName("sink2");
pipelineFacade.play();
cv::gapi::wip::gst::PipelineState state;
GstStateChangeReturn status =
gst_element_get_state(appsink, &state.current, &state.pending, 5 * GST_SECOND);
EXPECT_EQ(GST_STATE_CHANGE_SUCCESS, status);
EXPECT_EQ(GST_STATE_PLAYING, state.current);
EXPECT_EQ(GST_STATE_VOID_PENDING, state.pending);
}
TEST(GStreamerPipelineFacadeTest, IsPlayingUnitTest)
{
cv::gapi::wip::gst::GStreamerPipelineFacade
pipelineFacade("videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink1 "
"videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink2");
EXPECT_EQ(false, pipelineFacade.isPlaying());
pipelineFacade.play();
EXPECT_EQ(true, pipelineFacade.isPlaying());
}
TEST(GStreamerPipelineFacadeTest, MTSafetyUnitTest)
{
cv::gapi::wip::gst::GStreamerPipelineFacade
pipelineFacade("videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink1 "
"videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink2");
auto prerollRoutine = [&pipelineFacade](){ pipelineFacade.completePreroll(); };
auto playRoutine = [&pipelineFacade](){ pipelineFacade.play(); };
auto isPlayingRoutine = [&pipelineFacade](){ pipelineFacade.isPlaying(); };
using f = std::function<void()>;
auto routinesLauncher = [](const f& r1, const f& r2, const f& r3) {
std::vector<f> routines { r1, r2, r3 };
std::vector<std::thread> threads { };
for (auto&& r : routines) {
threads.emplace_back(r);
}
for (auto&& t : threads) {
t.join();
}
};
routinesLauncher(prerollRoutine, playRoutine, isPlayingRoutine);
routinesLauncher(prerollRoutine, isPlayingRoutine, playRoutine);
routinesLauncher(isPlayingRoutine, prerollRoutine, playRoutine);
routinesLauncher(playRoutine, prerollRoutine, isPlayingRoutine);
routinesLauncher(playRoutine, isPlayingRoutine, prerollRoutine);
routinesLauncher(isPlayingRoutine, playRoutine, prerollRoutine);
EXPECT_TRUE(true);
}
} // namespace opencv_test
#endif // HAVE_GSTREAMER
@@ -0,0 +1,401 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation
#include "../test/common/gapi_tests_common.hpp"
#include <opencv2/gapi/streaming/gstreamer/gstreamerpipeline.hpp>
#include <opencv2/gapi/streaming/gstreamer/gstreamersource.hpp>
#include <opencv2/gapi/core.hpp>
#include <opencv2/gapi/cpu/core.hpp>
#include <opencv2/gapi/streaming/meta.hpp>
#include <opencv2/gapi/streaming/format.hpp>
#include <opencv2/gapi/gkernel.hpp>
#include <opencv2/gapi/cpu/gcpukernel.hpp>
#include <opencv2/gapi/gcomputation.hpp>
#include <opencv2/ts.hpp>
#include <regex>
#ifdef HAVE_GSTREAMER
namespace opencv_test
{
struct GStreamerSourceTest : public TestWithParam<std::tuple<std::string, cv::Size, std::size_t>>
{ };
TEST_P(GStreamerSourceTest, AccuracyTest)
{
std::string pipeline;
cv::Size expectedFrameSize;
std::size_t streamLength { };
std::tie(pipeline, expectedFrameSize, streamLength) = GetParam();
// Graph declaration:
cv::GMat in;
auto out = cv::gapi::copy(in);
cv::GComputation c(cv::GIn(in), cv::GOut(out));
// Graph compilation for streaming mode:
auto ccomp = c.compileStreaming();
EXPECT_TRUE(ccomp);
EXPECT_FALSE(ccomp.running());
// GStreamer streaming source configuration:
ccomp.setSource<cv::gapi::wip::GStreamerSource>(pipeline);
// Start of streaming:
ccomp.start();
EXPECT_TRUE(ccomp.running());
// Streaming - pulling of frames until the end:
cv::Mat in_mat_gapi;
EXPECT_TRUE(ccomp.pull(cv::gout(in_mat_gapi)));
EXPECT_TRUE(!in_mat_gapi.empty());
EXPECT_EQ(expectedFrameSize, in_mat_gapi.size());
EXPECT_EQ(CV_8UC3, in_mat_gapi.type());
std::size_t framesCount = 1UL;
while (ccomp.pull(cv::gout(in_mat_gapi))) {
EXPECT_TRUE(!in_mat_gapi.empty());
EXPECT_EQ(expectedFrameSize, in_mat_gapi.size());
EXPECT_EQ(CV_8UC3, in_mat_gapi.type());
framesCount++;
}
EXPECT_FALSE(ccomp.running());
ccomp.stop();
EXPECT_FALSE(ccomp.running());
EXPECT_EQ(streamLength, framesCount);
}
TEST_P(GStreamerSourceTest, TimestampsTest)
{
std::string pipeline;
std::size_t streamLength { };
std::tie(pipeline, std::ignore, streamLength) = GetParam();
// Graph declaration:
cv::GMat in;
cv::GMat copied = cv::gapi::copy(in);
cv::GOpaque<int64_t> outId = cv::gapi::streaming::seq_id(copied);
cv::GOpaque<int64_t> outTs = cv::gapi::streaming::timestamp(copied);
cv::GComputation c(cv::GIn(in), cv::GOut(outId, outTs));
// Graph compilation for streaming mode:
auto ccomp = c.compileStreaming();
EXPECT_TRUE(ccomp);
EXPECT_FALSE(ccomp.running());
// GStreamer streaming source configuration:
ccomp.setSource<cv::gapi::wip::GStreamerSource>(pipeline);
// Start of streaming:
ccomp.start();
EXPECT_TRUE(ccomp.running());
// Streaming - pulling of frames until the end:
int64_t seqId;
int64_t timestamp;
std::vector<int64_t> allSeqIds;
std::vector<int64_t> allTimestamps;
while (ccomp.pull(cv::gout(seqId, timestamp))) {
allSeqIds.push_back(seqId);
allTimestamps.push_back(timestamp);
}
EXPECT_FALSE(ccomp.running());
ccomp.stop();
EXPECT_FALSE(ccomp.running());
EXPECT_EQ(0L, allSeqIds.front());
EXPECT_EQ(int64_t(streamLength) - 1, allSeqIds.back());
EXPECT_EQ(streamLength, allSeqIds.size());
EXPECT_TRUE(std::is_sorted(allSeqIds.begin(), allSeqIds.end()));
EXPECT_EQ(allSeqIds.size(), std::set<int64_t>(allSeqIds.begin(), allSeqIds.end()).size());
EXPECT_EQ(streamLength, allTimestamps.size());
EXPECT_TRUE(std::is_sorted(allTimestamps.begin(), allTimestamps.end()));
}
G_TYPED_KERNEL(GGstFrameCopyToNV12, <std::tuple<cv::GMat,cv::GMat>(GFrame)>,
"org.opencv.test.gstframe_copy_to_nv12")
{
static std::tuple<GMatDesc, GMatDesc> outMeta(GFrameDesc desc) {
GMatDesc y { CV_8U, 1, desc.size, false };
GMatDesc uv { CV_8U, 2, desc.size / 2, false };
return std::make_tuple(y, uv);
}
};
GAPI_OCV_KERNEL(GOCVGstFrameCopyToNV12, GGstFrameCopyToNV12)
{
static void run(const cv::MediaFrame& in, cv::Mat& y, cv::Mat& uv)
{
auto view = in.access(cv::MediaFrame::Access::R);
cv::Mat ly(y.size(), y.type(), view.ptr[0], view.stride[0]);
cv::Mat luv(uv.size(), uv.type(), view.ptr[1], view.stride[1]);
ly.copyTo(y);
luv.copyTo(uv);
}
};
TEST_P(GStreamerSourceTest, GFrameTest)
{
std::string pipeline;
cv::Size expectedFrameSize;
std::size_t streamLength { };
std::tie(pipeline, expectedFrameSize, streamLength) = GetParam();
// Graph declaration:
cv::GFrame in;
cv::GMat copiedY, copiedUV;
std::tie(copiedY, copiedUV) = GGstFrameCopyToNV12::on(in);
cv::GComputation c(cv::GIn(in), cv::GOut(copiedY, copiedUV));
// Graph compilation for streaming mode:
auto ccomp = c.compileStreaming(cv::compile_args(cv::gapi::kernels<GOCVGstFrameCopyToNV12>()));
EXPECT_TRUE(ccomp);
EXPECT_FALSE(ccomp.running());
// GStreamer streaming source configuration:
ccomp.setSource<cv::gapi::wip::GStreamerSource>
(pipeline, cv::gapi::wip::GStreamerSource::OutputType::FRAME);
// Start of streaming:
ccomp.start();
EXPECT_TRUE(ccomp.running());
// Streaming - pulling of frames until the end:
cv::Mat y_mat, uv_mat;
EXPECT_TRUE(ccomp.pull(cv::gout(y_mat, uv_mat)));
EXPECT_TRUE(!y_mat.empty());
EXPECT_TRUE(!uv_mat.empty());
cv::Size expectedYSize = expectedFrameSize;
cv::Size expectedUVSize = expectedFrameSize / 2;
EXPECT_EQ(expectedYSize, y_mat.size());
EXPECT_EQ(expectedUVSize, uv_mat.size());
EXPECT_EQ(CV_8UC1, y_mat.type());
EXPECT_EQ(CV_8UC2, uv_mat.type());
std::size_t framesCount = 1UL;
while (ccomp.pull(cv::gout(y_mat, uv_mat))) {
EXPECT_TRUE(!y_mat.empty());
EXPECT_TRUE(!uv_mat.empty());
EXPECT_EQ(expectedYSize, y_mat.size());
EXPECT_EQ(expectedUVSize, uv_mat.size());
EXPECT_EQ(CV_8UC1, y_mat.type());
EXPECT_EQ(CV_8UC2, uv_mat.type());
framesCount++;
}
EXPECT_FALSE(ccomp.running());
ccomp.stop();
EXPECT_FALSE(ccomp.running());
EXPECT_EQ(streamLength, framesCount);
}
// FIXME: Need to launch with sudo. May be infrastructure problems.
// TODO: It is needed to add tests for streaming from native KMB camera: kmbcamsrc
// GStreamer element.
INSTANTIATE_TEST_CASE_P(CameraEmulatingPipeline, GStreamerSourceTest,
Combine(Values("videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink"),
Values(cv::Size(1920, 1080)),
Values(10UL)));
INSTANTIATE_TEST_CASE_P(FileEmulatingPipeline, GStreamerSourceTest,
Combine(Values("videotestsrc pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=640,height=420,framerate=3/1 ! "
"appsink"),
Values(cv::Size(640, 420)),
Values(10UL)));
INSTANTIATE_TEST_CASE_P(MultipleLiveSources, GStreamerSourceTest,
Combine(Values("videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videoscale ! video/x-raw,width=1280,height=720 ! appsink "
"videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"fakesink"),
Values(cv::Size(1280, 720)),
Values(10UL)));
INSTANTIATE_TEST_CASE_P(MultipleNotLiveSources, GStreamerSourceTest,
Combine(Values("videotestsrc pattern=colors num-buffers=10 ! "
"videoscale ! video/x-raw,width=1280,height=720 ! appsink "
"videotestsrc pattern=colors num-buffers=10 ! "
"fakesink"),
Values(cv::Size(1280, 720)),
Values(10UL)));
TEST(GStreamerMultiSourceSmokeTest, Test)
{
// Graph declaration:
cv::GMat in1, in2;
auto out = cv::gapi::add(in1, in2);
cv::GComputation c(cv::GIn(in1, in2), cv::GOut(out));
// Graph compilation for streaming mode:
auto ccomp = c.compileStreaming();
EXPECT_TRUE(ccomp);
EXPECT_FALSE(ccomp.running());
cv::gapi::wip::GStreamerPipeline
pipeline("videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink1 "
"videotestsrc is-live=true pattern=colors num-buffers=10 ! "
"videorate ! videoscale ! "
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink2");
// GStreamer streaming sources configuration:
auto src1 = pipeline.getStreamingSource("sink1");
auto src2 = pipeline.getStreamingSource("sink2");
ccomp.setSource(cv::gin(src1, src2));
// Start of streaming:
ccomp.start();
EXPECT_TRUE(ccomp.running());
// Streaming - pulling of frames until the end:
cv::Mat in_mat_gapi;
EXPECT_TRUE(ccomp.pull(cv::gout(in_mat_gapi)));
EXPECT_TRUE(!in_mat_gapi.empty());
EXPECT_EQ(CV_8UC3, in_mat_gapi.type());
while (ccomp.pull(cv::gout(in_mat_gapi))) {
EXPECT_TRUE(!in_mat_gapi.empty());
EXPECT_EQ(CV_8UC3, in_mat_gapi.type());
}
EXPECT_FALSE(ccomp.running());
ccomp.stop();
EXPECT_FALSE(ccomp.running());
}
struct GStreamerMultiSourceTest :
public TestWithParam<std::tuple<cv::GComputation, cv::gapi::wip::GStreamerSource::OutputType>>
{ };
TEST_P(GStreamerMultiSourceTest, ImageDataTest)
{
std::string pathToLeftIm = findDataFile("cv/stereomatching/datasets/tsukuba/im6.png");
std::string pathToRightIm = findDataFile("cv/stereomatching/datasets/tsukuba/im2.png");
std::string pipelineToReadImage("filesrc location=LOC ! pngdec ! videoconvert ! "
"videoscale ! video/x-raw,format=NV12 ! appsink");
cv::gapi::wip::GStreamerSource leftImageProvider(
std::regex_replace(pipelineToReadImage, std::regex("LOC"), pathToLeftIm));
cv::gapi::wip::GStreamerSource rightImageProvider(
std::regex_replace(pipelineToReadImage, std::regex("LOC"), pathToRightIm));
cv::gapi::wip::Data leftImData, rightImData;
leftImageProvider.pull(leftImData);
rightImageProvider.pull(rightImData);
cv::Mat leftRefMat = cv::util::get<cv::Mat>(leftImData);
cv::Mat rightRefMat = cv::util::get<cv::Mat>(rightImData);
// Retrieve test parameters:
std::tuple<cv::GComputation, cv::gapi::wip::GStreamerSource::OutputType> params = GetParam();
cv::GComputation extractImage = std::move(std::get<0>(params));
cv::gapi::wip::GStreamerSource::OutputType outputType = std::get<1>(params);
// Graph compilation for streaming mode:
auto compiled =
extractImage.compileStreaming();
EXPECT_TRUE(compiled);
EXPECT_FALSE(compiled.running());
cv::gapi::wip::GStreamerPipeline
pipeline(std::string("multifilesrc location=" + pathToLeftIm + " index=0 loop=true ! "
"pngdec ! videoconvert ! videoscale ! video/x-raw,format=NV12 ! "
"appsink name=sink1 ") +
std::string("multifilesrc location=" + pathToRightIm + " index=0 loop=true ! "
"pngdec ! videoconvert ! videoscale ! video/x-raw,format=NV12 ! "
"appsink name=sink2"));
// GStreamer streaming sources configuration:
auto src1 = pipeline.getStreamingSource("sink1", outputType);
auto src2 = pipeline.getStreamingSource("sink2", outputType);
compiled.setSource(cv::gin(src1, src2));
// Start of streaming:
compiled.start();
EXPECT_TRUE(compiled.running());
// Streaming - pulling of frames:
cv::Mat in_mat1, in_mat2;
std::size_t counter { }, limit { 10 };
while(compiled.pull(cv::gout(in_mat1, in_mat2)) && (counter < limit)) {
EXPECT_EQ(0, cv::norm(in_mat1, leftRefMat, cv::NORM_INF));
EXPECT_EQ(0, cv::norm(in_mat2, rightRefMat, cv::NORM_INF));
++counter;
}
compiled.stop();
EXPECT_FALSE(compiled.running());
}
INSTANTIATE_TEST_CASE_P(GStreamerMultiSourceViaGMatsTest, GStreamerMultiSourceTest,
Combine(Values(cv::GComputation([]()
{
cv::GMat in1, in2;
return cv::GComputation(cv::GIn(in1, in2),
cv::GOut(cv::gapi::copy(in1),
cv::gapi::copy(in2)));
})),
Values(cv::gapi::wip::GStreamerSource::OutputType::MAT)));
INSTANTIATE_TEST_CASE_P(GStreamerMultiSourceViaGFramesTest, GStreamerMultiSourceTest,
Combine(Values(cv::GComputation([]()
{
cv::GFrame in1, in2;
return cv::GComputation(cv::GIn(in1, in2),
cv::GOut(cv::gapi::streaming::BGR(in1),
cv::gapi::streaming::BGR(in2)));
})),
Values(cv::gapi::wip::GStreamerSource::OutputType::FRAME)));
} // namespace opencv_test
#endif // HAVE_GSTREAMER
@@ -7,7 +7,7 @@
#include "../test_precomp.hpp"
#include "../common/gapi_tests_common.hpp"
#include "../common/gapi_streaming_tests_common.hpp"
#include <thread> // sleep_for (Delay)
@@ -24,37 +24,13 @@
#include <opencv2/gapi/streaming/cap.hpp>
#include <opencv2/gapi/streaming/desync.hpp>
#include <opencv2/gapi/streaming/format.hpp>
#include <opencv2/gapi/gstreaming.hpp>
#include <opencv2/gapi/streaming/onevpl/source.hpp>
#ifdef HAVE_ONEVPL
#if (MFX_VERSION >= 2000)
#include <vpl/mfxdispatcher.h>
#endif
#include <vpl/mfx.h>
#endif // HAVE_ONEVPL
namespace opencv_test
{
namespace
{
void initTestDataPath()
{
#ifndef WINRT
static bool initialized = false;
if (!initialized)
{
// Since G-API has no own test data (yet), it is taken from the common space
const char* testDataPath = getenv("OPENCV_TEST_DATA_PATH");
if (testDataPath) {
cvtest::addDataSearchPath(testDataPath);
}
initialized = true;
}
#endif // WINRT
}
enum class KernelPackage: int
{
@@ -81,7 +57,6 @@ std::ostream& operator<< (std::ostream &os, const KernelPackage &e)
struct GAPI_Streaming: public ::testing::TestWithParam<std::tuple<KernelPackage,
cv::optional<size_t>>> {
GAPI_Streaming() {
initTestDataPath();
KernelPackage pkg_kind;
std::tie(pkg_kind, cap) = GetParam();
pkg = getKernelPackage(pkg_kind);
@@ -92,7 +67,7 @@ struct GAPI_Streaming: public ::testing::TestWithParam<std::tuple<KernelPackage,
return cap;
}
cv::gapi::GKernelPackage getKernelPackage(KernelPackage pkg_kind)
cv::GKernelPackage getKernelPackage(KernelPackage pkg_kind)
{
using namespace cv::gapi;
switch (pkg_kind)
@@ -131,12 +106,12 @@ struct GAPI_Streaming: public ::testing::TestWithParam<std::tuple<KernelPackage,
using namespace cv::gapi;
auto args = cv::compile_args(use_only{pkg});
if (cap) {
args += cv::compile_args(streaming::queue_capacity{cap.value()});
args += cv::compile_args(cv::gapi::streaming::queue_capacity{cap.value()});
}
return args;
}
cv::gapi::GKernelPackage pkg;
cv::GKernelPackage pkg;
cv::optional<size_t> cap;
};
@@ -284,22 +259,6 @@ void checkPullOverload(const cv::Mat& ref,
EXPECT_EQ(0., cv::norm(ref, out_mat, cv::NORM_INF));
}
struct StreamDataProvider : public cv::gapi::wip::onevpl::IDataProvider {
StreamDataProvider(std::istream& in) : data_stream (in) {
EXPECT_TRUE(in);
}
size_t fetch_data(size_t out_data_size, void* out_data_buf) override {
data_stream.read(reinterpret_cast<char*>(out_data_buf), out_data_size);
return (size_t)data_stream.gcount();
}
bool empty() const override {
return data_stream.eof() || data_stream.bad();
}
private:
std::istream& data_stream;
};
} // anonymous namespace
TEST_P(GAPI_Streaming, SmokeTest_ConstInput_GMat)
@@ -353,7 +312,9 @@ TEST_P(GAPI_Streaming, SmokeTest_ConstInput_GMat)
// With constant inputs, the stream is endless so
// the blocking pull() should never return `false`.
EXPECT_TRUE(ccomp.pull(cv::gout(out_mat_gapi)));
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
// Fluid's and OpenCV's Resizes aren't bit exact.
// So 1% is here because it is max difference between them.
EXPECT_TRUE(AbsSimilarPoints(0, 1).to_compare_f()(out_mat_gapi, out_mat_ocv));
}
EXPECT_TRUE(ccomp.running());
@@ -405,7 +366,9 @@ TEST_P(GAPI_Streaming, SmokeTest_VideoInput_GMat)
frames++;
cv::Mat out_mat_ocv;
opencv_ref(in_mat_gapi, out_mat_ocv);
EXPECT_EQ(0, cvtest::norm(out_mat_gapi, out_mat_ocv, NORM_INF));
// Fluid's and OpenCV's Resizes aren't bit exact.
// So 1% is here because it is max difference between them.
EXPECT_TRUE(AbsSimilarPoints(0, 1).to_compare_f()(out_mat_gapi, out_mat_ocv));
}
EXPECT_LT(0u, frames);
EXPECT_FALSE(ccomp.running());
@@ -842,8 +805,6 @@ TEST(GAPI_Streaming_Types, XChangeScalar)
// This test verifies if Streaming works when pipeline steps
// (islands) exchange Scalar data.
initTestDataPath();
cv::GMat in;
cv::GScalar m = cv::gapi::mean(in);
cv::GMat tmp = cv::gapi::convertTo(in, CV_32F) - m;
@@ -910,8 +871,6 @@ TEST(GAPI_Streaming_Types, XChangeVector)
// This test verifies if Streaming works when pipeline steps
// (islands) exchange Vector data.
initTestDataPath();
cv::GMat in1, in2;
cv::GMat in = cv::gapi::crop(in1, cv::Rect{0,0,576,576});
cv::GScalar m = cv::gapi::mean(in);
@@ -976,8 +935,6 @@ TEST(GAPI_Streaming_Types, OutputScalar)
// This test verifies if Streaming works when pipeline
// produces scalar data only
initTestDataPath();
cv::GMat in;
cv::GScalar out = cv::gapi::mean(in);
auto sc = cv::GComputation(cv::GIn(in), cv::GOut(out))
@@ -1015,7 +972,6 @@ TEST(GAPI_Streaming_Types, OutputVector)
// This test verifies if Streaming works when pipeline
// produces vector data only
initTestDataPath();
auto pkg = cv::gapi::kernels<TypesTest::OCVSumV>();
cv::GMat in1, in2;
@@ -1106,7 +1062,7 @@ struct GAPI_Streaming_TemplateTypes: ::testing::Test {
cv::GMat blur;
cv::GArray<int> vec;
cv::GOpaque<int> opq;
cv::gapi::GKernelPackage pkg;
cv::GKernelPackage pkg;
cv::Mat in_mat;
};
@@ -1130,7 +1086,7 @@ TEST_F(GAPI_Streaming_TemplateTypes, UnusedVectorIsOK)
}
GAPI_Assert(out_mat || out_int);
if (out_int) {
EXPECT_EQ( 3, out_int.value());
EXPECT_EQ(3, out_int.value());
}
}
}
@@ -1177,7 +1133,6 @@ struct GAPI_Streaming_Unit: public ::testing::Test {
return cv::GComputation(cv::GIn(a, b), cv::GOut(c));
})
{
initTestDataPath();
const auto a_desc = cv::descr_of(m);
const auto b_desc = cv::descr_of(m);
@@ -1192,7 +1147,6 @@ struct GAPI_Streaming_Unit: public ::testing::Test {
TEST(GAPI_Streaming, TestTwoVideosDifferentLength)
{
initTestDataPath();
auto desc = cv::GMatDesc{CV_8U,3,{768,576}};
auto path1 = findDataFile("cv/video/768x576.avi");
auto path2 = findDataFile("highgui/video/big_buck_bunny.avi");
@@ -1454,8 +1408,6 @@ TEST(GAPI_Streaming_Desync, SmokeTest_Regular)
TEST(GAPI_Streaming_Desync, SmokeTest_Streaming)
{
initTestDataPath();
cv::GMat in;
cv::GMat tmp1 = cv::gapi::boxFilter(in, -1, cv::Size(3,3));
cv::GMat out1 = cv::gapi::Canny(tmp1, 32, 128, 3);
@@ -1487,8 +1439,6 @@ TEST(GAPI_Streaming_Desync, SmokeTest_Streaming)
TEST(GAPI_Streaming_Desync, SmokeTest_Streaming_TwoParts)
{
initTestDataPath();
cv::GMat in;
cv::GMat tmp1 = cv::gapi::boxFilter(in, -1, cv::Size(3,3));
cv::GMat out1 = cv::gapi::Canny(tmp1, 32, 128, 3);
@@ -1624,8 +1574,6 @@ TEST(GAPI_Streaming_Desync, Negative_CrossOtherDesync_Tier1)
TEST(GAPI_Streaming_Desync, Negative_SynchronizedPull)
{
initTestDataPath();
cv::GMat in;
cv::GMat out1 = cv::gapi::boxFilter(in, -1, cv::Size(3,3));
@@ -1649,8 +1597,6 @@ TEST(GAPI_Streaming_Desync, Negative_SynchronizedPull)
TEST(GAPI_Streaming_Desync, UseSpecialPull)
{
initTestDataPath();
cv::GMat in;
cv::GMat out1 = cv::gapi::boxFilter(in, -1, cv::Size(3,3));
@@ -1748,7 +1694,7 @@ TEST(GAPI_Streaming_Desync, MultipleDesyncOutputs_1) {
if (out_vec || out_int) {
EXPECT_EQ(320, out_vec.value()[0]);
EXPECT_EQ(240, out_vec.value()[1]);
EXPECT_EQ( 3, out_int.value());
EXPECT_EQ(3, out_int.value());
}
}
}
@@ -1807,7 +1753,6 @@ TEST(GAPI_Streaming_Desync, DesyncObjectConsumedByTwoIslandsViaSameDesync) {
TEST(GAPI_Streaming, CopyFrame)
{
initTestDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
cv::GFrame in;
@@ -1846,7 +1791,6 @@ TEST(GAPI_Streaming, CopyFrame)
TEST(GAPI_Streaming, CopyMat)
{
initTestDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
cv::GMat in;
@@ -1883,7 +1827,6 @@ TEST(GAPI_Streaming, CopyMat)
TEST(GAPI_Streaming, Reshape)
{
initTestDataPath();
std::string filepath = findDataFile("cv/video/768x576.avi");
cv::GFrame in;
@@ -2073,8 +2016,7 @@ TEST_P(GAPI_Accessors_In_Streaming, AccuracyTest)
auto accessor = gapi_functions[accessType];
auto fromBGR = ref_functions[std::make_pair(sourceType, accessType)];
initTestDataPathOrSkip();
const std::string& absFilePath = findDataFile(filepath, false);
const std::string& absFilePath = findDataFile(filepath);
cv::GFrame in;
cv::GMat out = accessor(in);
@@ -2125,8 +2067,7 @@ TEST_P(GAPI_Accessors_Meta_In_Streaming, AccuracyTest)
auto accessor = gapi_functions[accessType];
auto fromBGR = ref_functions[std::make_pair(sourceType, accessType)];
initTestDataPathOrSkip();
const std::string& absFilePath = findDataFile(filepath, false);
const std::string& absFilePath = findDataFile(filepath);
cv::GFrame in;
cv::GMat gmat = accessor(in);
@@ -2242,31 +2183,21 @@ TEST(GAPI_Streaming, TestPythonAPI)
}
#ifdef HAVE_ONEVPL
const unsigned char hevc_header[] = {
0x00, 0x00, 0x00, 0x01, 0x40, 0x01, 0x0C, 0x06, 0xFF, 0xFF, 0x01, 0x40, 0x00,
0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x78, 0x00,
0x00, 0x04, 0x02, 0x10, 0x30, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03,
0x01, 0xE5, 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x06, 0x01, 0x40, 0x00, 0x00,
0x03, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x78, 0x00, 0x00,
0xA0, 0x10, 0x20, 0x61, 0x63, 0x41, 0x00, 0x86, 0x49, 0x1B, 0x2B, 0x20, 0x00,
0x00, 0x00, 0x01, 0x44, 0x01, 0xC0, 0x71, 0xC0, 0xD9, 0x20, 0x00, 0x00, 0x00,
0x01, 0x26, 0x01, 0xAF, 0x0C
};
TEST(OneVPL_Source, Init)
{
using CfgParam = cv::gapi::wip::onevpl::CfgParam;
std::vector<CfgParam> src_params;
src_params.push_back(CfgParam::create<uint32_t>("mfxImplDescription.Impl",
MFX_IMPL_TYPE_HARDWARE));
src_params.push_back(CfgParam::create<uint32_t>("mfxImplDescription.AccelerationMode",
MFX_ACCEL_MODE_VIA_D3D11, false));
src_params.push_back(CfgParam::create<uint32_t>("mfxImplDescription.mfxDecoderDescription.decoder.CodecID",
MFX_CODEC_HEVC));
src_params.push_back(CfgParam::create_implementation(MFX_IMPL_TYPE_HARDWARE));
src_params.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
src_params.push_back(CfgParam::create_decoder_id(MFX_CODEC_HEVC));
std::stringstream stream(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
EXPECT_TRUE(stream.write(reinterpret_cast<char*>(const_cast<unsigned char *>(hevc_header)),
sizeof(hevc_header)));
std::shared_ptr<cv::gapi::wip::onevpl::IDataProvider> stream_data_provider = std::make_shared<StreamDataProvider>(stream);
EXPECT_TRUE(stream.write(reinterpret_cast<char*>(const_cast<unsigned char *>(streaming::onevpl::hevc_header)),
sizeof(streaming::onevpl::hevc_header)));
std::shared_ptr<cv::gapi::wip::onevpl::IDataProvider> stream_data_provider =
std::make_shared<streaming::onevpl::StreamDataProvider>(stream);
cv::Ptr<cv::gapi::wip::IStreamSource> cap;
bool cap_created = false;
@@ -2283,7 +2214,7 @@ TEST(OneVPL_Source, Init)
}
EXPECT_TRUE(stream_data_provider->empty());
}
#endif
#endif // HAVE_ONEVPL
TEST(GAPI_Streaming, TestDesyncRMat) {
cv::GMat in;
@@ -2324,7 +2255,6 @@ GAPI_OCV_KERNEL(GOcvTestBlur, GTestBlur) {
};
TEST(GAPI_Streaming, TestDesyncMediaFrame) {
initTestDataPath();
cv::GFrame in;
auto blurred = GTestBlur::on(in);
auto desynced = cv::gapi::streaming::desync(blurred);
@@ -0,0 +1,348 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation
#include "../test_precomp.hpp"
#include "../common/gapi_streaming_tests_common.hpp"
#include <chrono>
#include <future>
#define private public
#include "streaming/onevpl/accelerators/utils/shared_lock.hpp"
#undef private
#include "streaming/onevpl/accelerators/utils/elastic_barrier.hpp"
namespace opencv_test
{
namespace
{
using cv::gapi::wip::onevpl::SharedLock;
struct TestBarrier : public cv::gapi::wip::onevpl::elastic_barrier<TestBarrier> {
void on_first_in_impl(size_t visitor_id) {
static std::atomic<int> thread_counter{};
thread_counter++;
EXPECT_EQ(thread_counter.load(), 1);
visitors_in.insert(visitor_id);
last_visitor_id = visitor_id;
thread_counter--;
EXPECT_EQ(thread_counter.load(), 0);
}
void on_last_out_impl(size_t visitor_id) {
static std::atomic<int> thread_counter{};
thread_counter++;
EXPECT_EQ(thread_counter.load(), 1);
visitors_out.insert(visitor_id);
last_visitor_id = visitor_id;
thread_counter--;
EXPECT_EQ(thread_counter.load(), 0);
}
size_t last_visitor_id = 0;
std::set<size_t> visitors_in;
std::set<size_t> visitors_out;
};
TEST(OneVPL_SharedLock, Create) {
SharedLock lock;
EXPECT_EQ(lock.shared_counter.load(), size_t{0});
}
TEST(OneVPL_SharedLock, Read_SingleThread)
{
SharedLock lock;
const size_t single_thread_read_count = 100;
for(size_t i = 0; i < single_thread_read_count; i++) {
lock.shared_lock();
EXPECT_FALSE(lock.owns());
}
EXPECT_EQ(lock.shared_counter.load(), single_thread_read_count);
for(size_t i = 0; i < single_thread_read_count; i++) {
lock.unlock_shared();
EXPECT_FALSE(lock.owns());
}
EXPECT_EQ(lock.shared_counter.load(), size_t{0});
}
TEST(OneVPL_SharedLock, TryLock_SingleThread)
{
SharedLock lock;
EXPECT_TRUE(lock.try_lock());
EXPECT_TRUE(lock.owns());
lock.unlock();
EXPECT_FALSE(lock.owns());
EXPECT_EQ(lock.shared_counter.load(), size_t{0});
}
TEST(OneVPL_SharedLock, Write_SingleThread)
{
SharedLock lock;
lock.lock();
EXPECT_TRUE(lock.owns());
lock.unlock();
EXPECT_FALSE(lock.owns());
EXPECT_EQ(lock.shared_counter.load(), size_t{0});
}
TEST(OneVPL_SharedLock, TryLockTryLock_SingleThread)
{
SharedLock lock;
lock.try_lock();
EXPECT_FALSE(lock.try_lock());
lock.unlock();
EXPECT_FALSE(lock.owns());
}
TEST(OneVPL_SharedLock, ReadTryLock_SingleThread)
{
SharedLock lock;
lock.shared_lock();
EXPECT_FALSE(lock.owns());
EXPECT_FALSE(lock.try_lock());
lock.unlock_shared();
EXPECT_TRUE(lock.try_lock());
EXPECT_TRUE(lock.owns());
lock.unlock();
}
TEST(OneVPL_SharedLock, WriteTryLock_SingleThread)
{
SharedLock lock;
lock.lock();
EXPECT_TRUE(lock.owns());
EXPECT_FALSE(lock.try_lock());
lock.unlock();
EXPECT_TRUE(lock.try_lock());
EXPECT_TRUE(lock.owns());
lock.unlock();
}
TEST(OneVPL_SharedLock, Write_MultiThread)
{
SharedLock lock;
std::promise<void> barrier;
std::shared_future<void> sync = barrier.get_future();
static const size_t inc_count = 10000000;
size_t shared_value = 0;
auto work = [&lock, &shared_value](size_t count) {
for (size_t i = 0; i < count; i ++) {
lock.lock();
shared_value ++;
lock.unlock();
}
};
std::thread worker_thread([&barrier, sync, work] () {
std::thread sub_worker([&barrier, work] () {
barrier.set_value();
work(inc_count);
});
sync.wait();
work(inc_count);
sub_worker.join();
});
sync.wait();
work(inc_count);
worker_thread.join();
EXPECT_EQ(shared_value, inc_count * 3);
}
TEST(OneVPL_SharedLock, ReadWrite_MultiThread)
{
SharedLock lock;
std::promise<void> barrier;
std::future<void> sync = barrier.get_future();
static const size_t inc_count = 10000000;
size_t shared_value = 0;
auto write_work = [&lock, &shared_value](size_t count) {
for (size_t i = 0; i < count; i ++) {
lock.lock();
shared_value ++;
lock.unlock();
}
};
auto read_work = [&lock, &shared_value](size_t count) {
auto old_shared_value = shared_value;
for (size_t i = 0; i < count; i ++) {
lock.shared_lock();
EXPECT_TRUE(shared_value >= old_shared_value);
old_shared_value = shared_value;
lock.unlock_shared();
}
};
std::thread writer_thread([&barrier, write_work] () {
barrier.set_value();
write_work(inc_count);
});
sync.wait();
read_work(inc_count);
writer_thread.join();
EXPECT_EQ(shared_value, inc_count);
}
TEST(OneVPL_ElasticBarrier, single_thread_visit)
{
TestBarrier barrier;
const size_t max_visit_count = 10000;
size_t visit_id = 0;
for (visit_id = 0; visit_id < max_visit_count; visit_id++) {
barrier.visit_in(visit_id);
EXPECT_EQ(barrier.visitors_in.size(), size_t{1});
}
EXPECT_EQ(barrier.last_visitor_id, size_t{0});
EXPECT_EQ(barrier.visitors_out.size(), size_t{0});
for (visit_id = 0; visit_id < max_visit_count; visit_id++) {
barrier.visit_out(visit_id);
EXPECT_EQ(barrier.visitors_in.size(), size_t{1});
}
EXPECT_EQ(barrier.last_visitor_id, visit_id - 1);
EXPECT_EQ(barrier.visitors_out.size(), size_t{1});
}
TEST(OneVPL_ElasticBarrier, multi_thread_visit)
{
TestBarrier tested_barrier;
static const size_t max_visit_count = 10000000;
std::atomic<size_t> visit_in_wait_counter{};
std::promise<void> start_sync_barrier;
std::shared_future<void> start_sync = start_sync_barrier.get_future();
std::promise<void> phase_sync_barrier;
std::shared_future<void> phase_sync = phase_sync_barrier.get_future();
auto visit_worker_job = [&tested_barrier,
&visit_in_wait_counter,
start_sync,
phase_sync] (size_t worker_id) {
start_sync.wait();
// first phase
const size_t begin_range = worker_id * max_visit_count;
const size_t end_range = (worker_id + 1) * max_visit_count;
for (size_t visit_id = begin_range; visit_id < end_range; visit_id++) {
tested_barrier.visit_in(visit_id);
}
// notify all worker first phase ready
visit_in_wait_counter.fetch_add(1);
// wait main second phase
phase_sync.wait();
// second phase
for (size_t visit_id = begin_range; visit_id < end_range; visit_id++) {
tested_barrier.visit_out(visit_id);
}
};
auto visit_main_job = [&tested_barrier,
&visit_in_wait_counter,
&phase_sync_barrier] (size_t total_workers_count,
size_t worker_id) {
const size_t begin_range = worker_id * max_visit_count;
const size_t end_range = (worker_id + 1) * max_visit_count;
for (size_t visit_id = begin_range; visit_id < end_range; visit_id++) {
tested_barrier.visit_in(visit_id);
}
// wait all workers first phase done
visit_in_wait_counter.fetch_add(1);
while (visit_in_wait_counter.load() != total_workers_count) {
std::this_thread::yield();
};
// TEST invariant: last_visitor_id MUST be one from any FIRST worker visitor_id
bool one_of_available_ids_matched = false;
for (size_t id = 0; id < total_workers_count; id ++) {
size_t expected_last_visitor_for_id = id * max_visit_count;
one_of_available_ids_matched |=
(tested_barrier.last_visitor_id == expected_last_visitor_for_id) ;
}
EXPECT_TRUE(one_of_available_ids_matched);
// unblock all workers to work out second phase
phase_sync_barrier.set_value();
// continue second phase
for (size_t visit_id = begin_range; visit_id < end_range; visit_id++) {
tested_barrier.visit_out(visit_id);
}
};
size_t max_worker_count = std::thread::hardware_concurrency();
if (max_worker_count < 2) {
max_worker_count = 2; // logical 2 threads required at least
}
std::vector<std::thread> workers;
workers.reserve(max_worker_count);
for (size_t worker_id = 1; worker_id < max_worker_count; worker_id++) {
workers.emplace_back(visit_worker_job, worker_id);
}
// let's go for first phase
start_sync_barrier.set_value();
// utilize main thread as well
visit_main_job(max_worker_count, 0);
// join all threads second phase
for (auto& w : workers) {
w.join();
}
// TEST invariant: last_visitor_id MUST be one from any LATTER worker visitor_id
bool one_of_available_ids_matched = false;
for (size_t id = 0; id < max_worker_count; id ++) {
one_of_available_ids_matched |=
(tested_barrier.last_visitor_id == ((id + 1) * max_visit_count - 1)) ;
}
EXPECT_TRUE(one_of_available_ids_matched);
}
}
} // opencv_test
@@ -7,7 +7,7 @@
#include "../test_precomp.hpp"
#include "../common/gapi_tests_common.hpp"
#include "../common/gapi_streaming_tests_common.hpp"
#include <chrono>
#include <future>
@@ -27,14 +27,16 @@
#include <opencv2/gapi/streaming/desync.hpp>
#include <opencv2/gapi/streaming/format.hpp>
#include <opencv2/gapi/streaming/onevpl/source.hpp>
#ifdef HAVE_ONEVPL
#include <opencv2/gapi/streaming/onevpl/data_provider_interface.hpp>
#include "streaming/onevpl/cfg_param_device_selector.hpp"
#include "streaming/onevpl/accelerators/surface/surface.hpp"
#include "streaming/onevpl/accelerators/surface/cpu_frame_adapter.hpp"
#include "streaming/onevpl/accelerators/accel_policy_cpu.hpp"
#include "streaming/onevpl/accelerators/accel_policy_dx11.hpp"
#include "streaming/onevpl/accelerators/dx11_alloc_resource.hpp"
#include "streaming/onevpl/accelerators/utils/shared_lock.hpp"
#include "streaming/onevpl/engine/processing_engine_base.hpp"
#include "streaming/onevpl/engine/engine_session.hpp"
@@ -45,18 +47,26 @@ namespace
struct EmptyDataProvider : public cv::gapi::wip::onevpl::IDataProvider {
size_t fetch_data(size_t, void*) override {
return 0;
}
bool empty() const override {
return true;
}
mfx_codec_id_type get_mfx_codec_id() const override {
return std::numeric_limits<uint32_t>::max();
}
bool fetch_bitstream_data(std::shared_ptr<mfx_bitstream> &) override {
return false;
}
};
struct TestProcessingSession : public cv::gapi::wip::onevpl::EngineSession {
TestProcessingSession(mfxSession mfx_session) :
EngineSession(mfx_session, {}) {
}
const mfxVideoParam& get_video_param() const override {
static mfxVideoParam empty;
return empty;
}
};
struct TestProcessingEngine: public cv::gapi::wip::onevpl::ProcessingEngineBase {
@@ -95,14 +105,66 @@ struct TestProcessingEngine: public cv::gapi::wip::onevpl::ProcessingEngineBase
);
}
void initialize_session(mfxSession mfx_session,
cv::gapi::wip::onevpl::DecoderParams&&,
std::shared_ptr<cv::gapi::wip::onevpl::IDataProvider>) override {
std::shared_ptr<cv::gapi::wip::onevpl::EngineSession>
initialize_session(mfxSession mfx_session,
const std::vector<cv::gapi::wip::onevpl::CfgParam>&,
std::shared_ptr<cv::gapi::wip::onevpl::IDataProvider>) override {
register_session<TestProcessingSession>(mfx_session);
return register_session<TestProcessingSession>(mfx_session);
}
};
template <class LockProcessor, class UnlockProcessor>
class TestLockableAllocator {
public :
using self_t = TestLockableAllocator<LockProcessor, UnlockProcessor>;
mfxFrameAllocator get() {
return m_allocator;
}
private:
TestLockableAllocator(mfxFrameAllocator allocator) :
m_allocator(allocator) {
}
static mfxStatus MFX_CDECL lock_cb(mfxHDL, mfxMemId mid, mfxFrameData *ptr) {
auto it = lock_processor_table.find(mid);
EXPECT_TRUE(it != lock_processor_table.end());
return it->second(mid, ptr);
}
static mfxStatus MFX_CDECL unlock_cb(mfxHDL, mfxMemId mid, mfxFrameData *ptr) {
auto it = unlock_processor_table.find(mid);
EXPECT_TRUE(it != unlock_processor_table.end());
return it->second(mid, ptr);
}
template <class L, class U>
friend TestLockableAllocator<L,U> create_test_allocator(mfxMemId, L, U);
static std::map<mfxMemId, LockProcessor> lock_processor_table;
static std::map<mfxMemId, UnlockProcessor> unlock_processor_table;
mfxFrameAllocator m_allocator;
};
template <class LockProcessor, class UnlockProcessor>
std::map<mfxMemId, UnlockProcessor> TestLockableAllocator<LockProcessor, UnlockProcessor>::lock_processor_table {};
template <class LockProcessor, class UnlockProcessor>
std::map<mfxMemId, UnlockProcessor> TestLockableAllocator<LockProcessor, UnlockProcessor>::unlock_processor_table {};
template <class LockProcessor, class UnlockProcessor>
TestLockableAllocator<LockProcessor, UnlockProcessor>
create_test_allocator(mfxMemId mid, LockProcessor lock_p, UnlockProcessor unlock_p) {
mfxFrameAllocator allocator {};
TestLockableAllocator<LockProcessor, UnlockProcessor>::lock_processor_table[mid] = lock_p;
allocator.Lock = &TestLockableAllocator<LockProcessor, UnlockProcessor>::lock_cb;
TestLockableAllocator<LockProcessor, UnlockProcessor>::unlock_processor_table[mid] = unlock_p;
allocator.Unlock = &TestLockableAllocator<LockProcessor, UnlockProcessor>::unlock_cb;
return TestLockableAllocator<LockProcessor, UnlockProcessor> {allocator};
}
cv::gapi::wip::onevpl::surface_ptr_t create_test_surface(std::shared_ptr<void> out_buf_ptr,
size_t, size_t) {
std::unique_ptr<mfxFrameSurface1> handle(new mfxFrameSurface1{});
@@ -124,11 +186,11 @@ TEST(OneVPL_Source_Surface, InitSurface)
// check self consistency
EXPECT_EQ(reinterpret_cast<void*>(surf->get_handle()),
reinterpret_cast<void*>(mfx_core_handle));
EXPECT_EQ(surf->get_locks_count(), 0);
EXPECT_EQ(surf->obtain_lock(), 0);
EXPECT_EQ(surf->get_locks_count(), 1);
EXPECT_EQ(surf->release_lock(), 1);
EXPECT_EQ(surf->get_locks_count(), 0);
EXPECT_EQ(0, surf->get_locks_count());
EXPECT_EQ(0, surf->obtain_lock());
EXPECT_EQ(1, surf->get_locks_count());
EXPECT_EQ(1, surf->release_lock());
EXPECT_EQ(0, surf->get_locks_count());
}
TEST(OneVPL_Source_Surface, ConcurrentLock)
@@ -143,7 +205,7 @@ TEST(OneVPL_Source_Surface, ConcurrentLock)
auto surf = Surface::create_surface(std::move(handle), associated_memory);
// check self consistency
EXPECT_EQ(surf->get_locks_count(), 0);
EXPECT_EQ(0, surf->get_locks_count());
// MFX internal limitation: do not exceede U16 range
// so I16 is using here
@@ -168,7 +230,7 @@ TEST(OneVPL_Source_Surface, ConcurrentLock)
}
worker_thread.join();
EXPECT_EQ(surf->get_locks_count(), lock_counter * 2);
EXPECT_EQ(lock_counter * 2, surf->get_locks_count());
}
TEST(OneVPL_Source_Surface, MemoryLifeTime)
@@ -180,7 +242,7 @@ TEST(OneVPL_Source_Surface, MemoryLifeTime)
std::shared_ptr<void> associated_memory (preallocated_memory_ptr.get(),
[&preallocated_memory_ptr] (void* ptr) {
EXPECT_TRUE(preallocated_memory_ptr);
EXPECT_EQ(preallocated_memory_ptr.get(), ptr);
EXPECT_EQ(ptr, preallocated_memory_ptr.get());
preallocated_memory_ptr.reset();
});
@@ -201,7 +263,7 @@ TEST(OneVPL_Source_Surface, MemoryLifeTime)
}
// workspace memory must be alive
EXPECT_EQ(surfaces.size(), 0);
EXPECT_EQ(0, surfaces.size());
EXPECT_TRUE(associated_memory != nullptr);
EXPECT_TRUE(preallocated_memory_ptr.get() != nullptr);
@@ -223,7 +285,7 @@ TEST(OneVPL_Source_Surface, MemoryLifeTime)
associated_memory.reset();
// workspace memory must be still alive
EXPECT_EQ(surfaces.size(), 0);
EXPECT_EQ(0, surfaces.size());
EXPECT_TRUE(associated_memory == nullptr);
EXPECT_TRUE(preallocated_memory_ptr.get() != nullptr);
@@ -246,21 +308,23 @@ TEST(OneVPL_Source_CPU_FrameAdapter, InitFrameAdapter)
auto surf = Surface::create_surface(std::move(handle), associated_memory);
// check consistency
EXPECT_EQ(surf->get_locks_count(), 0);
EXPECT_EQ(0, surf->get_locks_count());
{
VPLMediaFrameCPUAdapter adapter(surf);
EXPECT_EQ(surf->get_locks_count(), 1);
EXPECT_EQ(1, surf->get_locks_count());
}
EXPECT_EQ(surf->get_locks_count(), 0);
EXPECT_EQ(0, surf->get_locks_count());
}
TEST(OneVPL_Source_CPU_Accelerator, InitDestroy)
{
using cv::gapi::wip::onevpl::VPLCPUAccelerationPolicy;
using cv::gapi::wip::onevpl::VPLAccelerationPolicy;
using cv::gapi::wip::onevpl::CfgParamDeviceSelector;
auto acceleration_policy = std::make_shared<VPLCPUAccelerationPolicy>();
auto acceleration_policy =
std::make_shared<VPLCPUAccelerationPolicy>(std::make_shared<CfgParamDeviceSelector>());
size_t surface_count = 10;
size_t surface_size_bytes = 1024;
@@ -276,8 +340,8 @@ TEST(OneVPL_Source_CPU_Accelerator, InitDestroy)
surface_size_bytes,
create_test_surface);
// check consistency
EXPECT_EQ(acceleration_policy->get_surface_count(key), surface_count);
EXPECT_EQ(acceleration_policy->get_free_surface_count(key), surface_count);
EXPECT_EQ(surface_count, acceleration_policy->get_surface_count(key));
EXPECT_EQ(surface_count, acceleration_policy->get_free_surface_count(key));
pool_export_keys.push_back(key);
}
@@ -289,9 +353,11 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConsume)
{
using cv::gapi::wip::onevpl::VPLCPUAccelerationPolicy;
using cv::gapi::wip::onevpl::VPLAccelerationPolicy;
using cv::gapi::wip::onevpl::CfgParamDeviceSelector;
using cv::gapi::wip::onevpl::Surface;
auto acceleration_policy = std::make_shared<VPLCPUAccelerationPolicy>();
auto acceleration_policy =
std::make_shared<VPLCPUAccelerationPolicy>(std::make_shared<CfgParamDeviceSelector>());
size_t surface_count = 10;
size_t surface_size_bytes = 1024;
@@ -301,8 +367,8 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConsume)
surface_size_bytes,
create_test_surface);
// check consistency
EXPECT_EQ(acceleration_policy->get_surface_count(key), surface_count);
EXPECT_EQ(acceleration_policy->get_free_surface_count(key), surface_count);
EXPECT_EQ(surface_count, acceleration_policy->get_surface_count(key));
EXPECT_EQ(surface_count, acceleration_policy->get_free_surface_count(key));
// consume available surfaces
std::vector<std::shared_ptr<Surface>> surfaces;
@@ -310,13 +376,13 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConsume)
for (size_t i = 0; i < surface_count; i++) {
std::shared_ptr<Surface> surf = acceleration_policy->get_free_surface(key).lock();
EXPECT_TRUE(surf.get() != nullptr);
EXPECT_EQ(surf->obtain_lock(), 0);
EXPECT_EQ(0, surf->obtain_lock());
surfaces.push_back(std::move(surf));
}
// check consistency (no free surfaces)
EXPECT_EQ(acceleration_policy->get_surface_count(key), surface_count);
EXPECT_EQ(acceleration_policy->get_free_surface_count(key), 0);
EXPECT_EQ(0, acceleration_policy->get_free_surface_count(key));
// fail consume non-free surfaces
for (size_t i = 0; i < surface_count; i++) {
@@ -325,19 +391,19 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConsume)
// release surfaces
for (auto& surf : surfaces) {
EXPECT_EQ(surf->release_lock(), 1);
EXPECT_EQ(1, surf->release_lock());
}
surfaces.clear();
// check consistency
EXPECT_EQ(acceleration_policy->get_surface_count(key), surface_count);
EXPECT_EQ(acceleration_policy->get_free_surface_count(key), surface_count);
EXPECT_EQ(surface_count, acceleration_policy->get_surface_count(key));
EXPECT_EQ(surface_count, acceleration_policy->get_free_surface_count(key));
//check availability after release
for (size_t i = 0; i < surface_count; i++) {
std::shared_ptr<Surface> surf = acceleration_policy->get_free_surface(key).lock();
EXPECT_TRUE(surf.get() != nullptr);
EXPECT_EQ(surf->obtain_lock(), 0);
EXPECT_EQ(0, surf->obtain_lock());
}
}
@@ -345,9 +411,11 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConcurrentConsume)
{
using cv::gapi::wip::onevpl::VPLCPUAccelerationPolicy;
using cv::gapi::wip::onevpl::VPLAccelerationPolicy;
using cv::gapi::wip::onevpl::CfgParamDeviceSelector;
using cv::gapi::wip::onevpl::Surface;
auto acceleration_policy = std::make_shared<VPLCPUAccelerationPolicy>();
auto acceleration_policy =
std::make_shared<VPLCPUAccelerationPolicy>(std::make_shared<CfgParamDeviceSelector>());
size_t surface_count = 10;
size_t surface_size_bytes = 1024;
@@ -358,8 +426,8 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConcurrentConsume)
create_test_surface);
// check consistency
EXPECT_EQ(acceleration_policy->get_surface_count(key), surface_count);
EXPECT_EQ(acceleration_policy->get_free_surface_count(key), surface_count);
EXPECT_EQ(surface_count, acceleration_policy->get_surface_count(key));
EXPECT_EQ(surface_count, acceleration_policy->get_free_surface_count(key));
// consume available surfaces
std::vector<std::shared_ptr<Surface>> surfaces;
@@ -367,7 +435,7 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConcurrentConsume)
for (size_t i = 0; i < surface_count; i++) {
std::shared_ptr<Surface> surf = acceleration_policy->get_free_surface(key).lock();
EXPECT_TRUE(surf.get() != nullptr);
EXPECT_EQ(surf->obtain_lock(), 0);
EXPECT_EQ(0, surf->obtain_lock());
surfaces.push_back(std::move(surf));
}
@@ -381,7 +449,7 @@ TEST(OneVPL_Source_CPU_Accelerator, PoolProduceConcurrentConsume)
// concurrent release surfaces
size_t surfaces_count = surfaces.size();
for (auto& surf : surfaces) {
EXPECT_EQ(surf->release_lock(), 1);
EXPECT_EQ(1, surf->release_lock());
std::this_thread::sleep_for(std::chrono::seconds(1));
}
surfaces.clear();
@@ -413,34 +481,209 @@ TEST(OneVPL_Source_ProcessingEngine, Init)
TestProcessingEngine engine(std::move(accel));
mfxSession mfx_session{};
engine.initialize_session(mfx_session, DecoderParams{}, std::shared_ptr<IDataProvider>{});
engine.initialize_session(mfx_session, {}, std::shared_ptr<IDataProvider>{});
EXPECT_EQ(engine.get_ready_frames_count(), 0);
EXPECT_EQ(0, engine.get_ready_frames_count());
ProcessingEngineBase::ExecutionStatus ret = engine.process(mfx_session);
EXPECT_EQ(ret, ProcessingEngineBase::ExecutionStatus::Continue);
EXPECT_EQ(engine.pipeline_stage_num, 0);
EXPECT_EQ(0, engine.pipeline_stage_num);
ret = engine.process(mfx_session);
EXPECT_EQ(ret, ProcessingEngineBase::ExecutionStatus::Continue);
EXPECT_EQ(engine.pipeline_stage_num, 1);
EXPECT_EQ(1, engine.pipeline_stage_num);
ret = engine.process(mfx_session);
EXPECT_EQ(ret, ProcessingEngineBase::ExecutionStatus::Continue);
EXPECT_EQ(engine.pipeline_stage_num, 2);
EXPECT_EQ(2, engine.pipeline_stage_num);
ret = engine.process(mfx_session);
EXPECT_EQ(ret, ProcessingEngineBase::ExecutionStatus::Processed);
EXPECT_EQ(engine.pipeline_stage_num, 3);
EXPECT_EQ(engine.get_ready_frames_count(), 1);
EXPECT_EQ(3, engine.pipeline_stage_num);
EXPECT_EQ(1, engine.get_ready_frames_count());
ret = engine.process(mfx_session);
EXPECT_EQ(ret, ProcessingEngineBase::ExecutionStatus::SessionNotFound);
EXPECT_EQ(engine.pipeline_stage_num, 3);
EXPECT_EQ(engine.get_ready_frames_count(), 1);
EXPECT_EQ(3, engine.pipeline_stage_num);
EXPECT_EQ(1, engine.get_ready_frames_count());
cv::gapi::wip::Data frame;
engine.get_frame(frame);
}
#ifdef HAVE_DIRECTX
#ifdef HAVE_D3D11
TEST(OneVPL_Source_DX11_Accel, Init)
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> cfg_params_w_dx11;
cfg_params_w_dx11.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
VPLDX11AccelerationPolicy accel(std::make_shared<CfgParamDeviceSelector>(cfg_params_w_dx11));
mfxLoader mfx_handle = MFXLoad();
mfxConfig cfg_inst_0 = MFXCreateConfig(mfx_handle);
EXPECT_TRUE(cfg_inst_0);
mfxVariant mfx_param_0;
mfx_param_0.Type = MFX_VARIANT_TYPE_U32;
mfx_param_0.Data.U32 = MFX_IMPL_TYPE_HARDWARE;
EXPECT_EQ(MFXSetConfigFilterProperty(cfg_inst_0,(mfxU8 *)CfgParam::implementation_name(),
mfx_param_0), MFX_ERR_NONE);
mfxConfig cfg_inst_1 = MFXCreateConfig(mfx_handle);
EXPECT_TRUE(cfg_inst_1);
mfxVariant mfx_param_1;
mfx_param_1.Type = MFX_VARIANT_TYPE_U32;
mfx_param_1.Data.U32 = MFX_ACCEL_MODE_VIA_D3D11;
EXPECT_EQ(MFXSetConfigFilterProperty(cfg_inst_1,(mfxU8 *)CfgParam::acceleration_mode_name(),
mfx_param_1), MFX_ERR_NONE);
mfxConfig cfg_inst_2 = MFXCreateConfig(mfx_handle);
EXPECT_TRUE(cfg_inst_2);
mfxVariant mfx_param_2;
mfx_param_2.Type = MFX_VARIANT_TYPE_U32;
mfx_param_2.Data.U32 = MFX_CODEC_HEVC;
EXPECT_EQ(MFXSetConfigFilterProperty(cfg_inst_2,(mfxU8 *)CfgParam::decoder_id_name(),
mfx_param_2), MFX_ERR_NONE);
// create session
mfxSession mfx_session{};
mfxStatus sts = MFXCreateSession(mfx_handle, 0, &mfx_session);
EXPECT_EQ(MFX_ERR_NONE, sts);
// assign acceleration
EXPECT_NO_THROW(accel.init(mfx_session));
// create proper bitstream
mfxBitstream bitstream{};
const int BITSTREAM_BUFFER_SIZE = 2000000;
bitstream.MaxLength = BITSTREAM_BUFFER_SIZE;
bitstream.Data = (mfxU8 *)calloc(bitstream.MaxLength, sizeof(mfxU8));
EXPECT_TRUE(bitstream.Data);
// simulate read stream
bitstream.DataOffset = 0;
bitstream.DataLength = sizeof(streaming::onevpl::hevc_header) * sizeof(streaming::onevpl::hevc_header[0]);
memcpy(bitstream.Data, streaming::onevpl::hevc_header, bitstream.DataLength);
bitstream.CodecId = MFX_CODEC_HEVC;
// prepare dec params
mfxVideoParam mfxDecParams {};
mfxDecParams.mfx.CodecId = bitstream.CodecId;
mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
sts = MFXVideoDECODE_DecodeHeader(mfx_session, &bitstream, &mfxDecParams);
EXPECT_EQ(MFX_ERR_NONE, sts);
mfxFrameAllocRequest request{};
memset(&request, 0, sizeof(request));
sts = MFXVideoDECODE_QueryIOSurf(mfx_session, &mfxDecParams, &request);
EXPECT_EQ(MFX_ERR_NONE, sts);
// Allocate surfaces for decoder
VPLAccelerationPolicy::pool_key_t key = accel.create_surface_pool(request,
mfxDecParams);
auto cand_surface = accel.get_free_surface(key).lock();
sts = MFXVideoDECODE_Init(mfx_session, &mfxDecParams);
EXPECT_EQ(MFX_ERR_NONE, sts);
MFXVideoDECODE_Close(mfx_session);
EXPECT_EQ(MFX_ERR_NONE, sts);
EXPECT_NO_THROW(accel.deinit(mfx_session));
MFXClose(mfx_session);
MFXUnload(mfx_handle);
}
#endif // HAVE_DIRECTX
#endif // HAVE_D3D11
TEST(OneVPL_Source_DX11_FrameLockable, LockUnlock_without_Adaptee)
{
using namespace cv::gapi::wip::onevpl;
mfxMemId mid = 0;
int lock_counter = 0;
int unlock_counter = 0;
std::function<mfxStatus(mfxMemId, mfxFrameData *)> lock =
[&lock_counter] (mfxMemId, mfxFrameData *) {
lock_counter ++;
return MFX_ERR_NONE;
};
std::function<mfxStatus(mfxMemId, mfxFrameData *)> unlock =
[&unlock_counter] (mfxMemId, mfxFrameData *) {
unlock_counter++;
return MFX_ERR_NONE;
};
auto test_allocator = create_test_allocator(mid, lock, unlock);
LockAdapter adapter(test_allocator.get());
mfxFrameData data;
const int exec_count = 123;
for (int i = 0; i < exec_count; i ++) {
EXPECT_EQ(adapter.read_lock(mid, data), 0);
adapter.write_lock(mid, data);
EXPECT_EQ(adapter.unlock_read(mid, data), 0);
adapter.unlock_write(mid, data);
}
EXPECT_EQ(lock_counter, exec_count * 2);
EXPECT_EQ(unlock_counter, exec_count * 2);
}
TEST(OneVPL_Source_DX11_FrameLockable, LockUnlock_with_Adaptee)
{
using namespace cv::gapi::wip::onevpl;
mfxMemId mid = 0;
int r_lock_counter = 0;
int r_unlock_counter = 0;
int w_lock_counter = 0;
int w_unlock_counter = 0;
SharedLock adaptee;
std::function<mfxStatus(mfxMemId, mfxFrameData *)> lock =
[&r_lock_counter, &w_lock_counter, &adaptee] (mfxMemId, mfxFrameData *) {
if (adaptee.owns()) {
w_lock_counter ++;
} else {
r_lock_counter ++;
}
return MFX_ERR_NONE;
};
std::function<mfxStatus(mfxMemId, mfxFrameData *)> unlock =
[&r_unlock_counter, &w_unlock_counter, &adaptee] (mfxMemId, mfxFrameData *) {
if (adaptee.owns()) {
w_unlock_counter ++;
} else {
r_unlock_counter ++;
}
return MFX_ERR_NONE;
};
auto test_allocator = create_test_allocator(mid, lock, unlock);
LockAdapter adapter(test_allocator.get());
adapter.set_adaptee(&adaptee);
mfxFrameData data;
const int exec_count = 123;
for (int i = 0; i < exec_count; i ++) {
EXPECT_EQ(adapter.read_lock(mid, data), 0);
EXPECT_FALSE(adaptee.try_lock());
EXPECT_EQ(adapter.unlock_read(mid, data), 1);
EXPECT_TRUE(adaptee.try_lock());
adaptee.unlock();
adapter.write_lock(mid, data);
adapter.unlock_write(mid, data);
}
EXPECT_EQ(r_lock_counter, exec_count);
EXPECT_EQ(r_unlock_counter, exec_count);
EXPECT_EQ(w_lock_counter, exec_count);
EXPECT_EQ(w_unlock_counter, exec_count);
}
}
} // namespace opencv_test
#endif // HAVE_ONEVPL
@@ -0,0 +1,302 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation
#ifdef HAVE_ONEVPL
#include <future>
#include "../test_precomp.hpp"
#include "../common/gapi_tests_common.hpp"
#include "streaming/onevpl/data_provider_dispatcher.hpp"
#include "streaming/onevpl/file_data_provider.hpp"
#include "streaming/onevpl/demux/async_mfp_demux_data_provider.hpp"
#include "streaming/onevpl/source_priv.hpp"
namespace opencv_test
{
namespace
{
using source_t = std::string;
using dd_valid_t = bool;
using demux_valid_t = bool;
using dec_valid_t = bool;
using array_element_t =
std::tuple<source_t, dd_valid_t, demux_valid_t, dec_valid_t>;
array_element_t files[] = {
array_element_t {"highgui/video/VID00003-20100701-2204.3GP",
false, true, false},
array_element_t {"highgui/video/VID00003-20100701-2204.avi",
false, true, false},
array_element_t {"highgui/video/VID00003-20100701-2204.mpg",
false, true, false},
array_element_t {"highgui/video/VID00003-20100701-2204.wmv",
false, true, false},
array_element_t {"highgui/video/sample_322x242_15frames.yuv420p.libaom-av1.mp4",
true, true, true},
array_element_t {"highgui/video/sample_322x242_15frames.yuv420p.libvpx-vp9.mp4",
true, true, true},
array_element_t {"highgui/video/sample_322x242_15frames.yuv420p.libx264.mp4",
true, true, true},
array_element_t {"highgui/video/sample_322x242_15frames.yuv420p.libx265.mp4",
true, true, true},
array_element_t {"highgui/video/sample_322x242_15frames.yuv420p.mjpeg.mp4",
/* MFP cannot extract video MJPEG subtype from that */
false, false, true},
array_element_t {"highgui/video/big_buck_bunny.h264",
false, false, false},
array_element_t {"highgui/video/big_buck_bunny.h265",
false, false, false}
};
class OneVPL_Source_MFPAsyncDispatcherTest : public ::testing::TestWithParam<array_element_t> {};
TEST_P(OneVPL_Source_MFPAsyncDispatcherTest, open_and_decode_file)
{
using namespace cv::gapi::wip::onevpl;
source_t path = findDataFile(std::get<0>(GetParam()));
dd_valid_t dd_result = std::get<1>(GetParam());
dec_valid_t dec_result = std::get<3>(GetParam());
// open demux source & check format support
std::unique_ptr<MFPAsyncDemuxDataProvider> provider_ptr;
try {
provider_ptr.reset(new MFPAsyncDemuxDataProvider(path));
} catch (...) {
EXPECT_FALSE(dd_result);
GTEST_SUCCEED();
return;
}
EXPECT_TRUE(dd_result);
// initialize MFX
mfxLoader mfx_handle = MFXLoad();
mfxConfig cfg_inst_0 = MFXCreateConfig(mfx_handle);
EXPECT_TRUE(cfg_inst_0);
mfxVariant mfx_param_0;
mfx_param_0.Type = MFX_VARIANT_TYPE_U32;
mfx_param_0.Data.U32 = provider_ptr->get_mfx_codec_id();
EXPECT_EQ(MFXSetConfigFilterProperty(cfg_inst_0,(mfxU8 *)CfgParam::decoder_id_name(),
mfx_param_0), MFX_ERR_NONE);
// create MFX session
mfxSession mfx_session{};
mfxStatus sts = MFXCreateSession(mfx_handle, 0, &mfx_session);
EXPECT_EQ(MFX_ERR_NONE, sts);
// create proper bitstream
std::shared_ptr<IDataProvider::mfx_bitstream> bitstream{};
// prepare dec params
mfxVideoParam mfxDecParams {};
mfxDecParams.mfx.CodecId = mfx_param_0.Data.U32;
mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
do {
bool fetched = provider_ptr->fetch_bitstream_data(bitstream);
if (dec_result) {
EXPECT_TRUE(fetched);
}
sts = MFXVideoDECODE_DecodeHeader(mfx_session, bitstream.get(), &mfxDecParams);
EXPECT_TRUE(MFX_ERR_NONE == sts || MFX_ERR_MORE_DATA == sts);
} while (sts == MFX_ERR_MORE_DATA && !provider_ptr->empty());
if (dec_result) {
EXPECT_EQ(MFX_ERR_NONE, sts);
} else {
EXPECT_FALSE(MFX_ERR_NONE == sts);
}
MFXVideoDECODE_Close(mfx_session);
MFXClose(mfx_session);
MFXUnload(mfx_handle);
}
TEST_P(OneVPL_Source_MFPAsyncDispatcherTest, choose_dmux_provider)
{
using namespace cv::gapi::wip::onevpl;
source_t path = findDataFile(std::get<0>(GetParam()));
dd_valid_t dd_result = std::get<1>(GetParam());
std::shared_ptr<IDataProvider> provider_ptr;
// choose demux provider for empty CfgParams
try {
provider_ptr = DataProviderDispatcher::create(path);
} catch (...) {
EXPECT_FALSE(dd_result);
provider_ptr = DataProviderDispatcher::create(path,
{ CfgParam::create<std::string>(
CfgParam::decoder_id_name(),
"MFX_CODEC_HEVC") /* Doesn't matter what codec for RAW here*/});
EXPECT_TRUE(std::dynamic_pointer_cast<FileDataProvider>(provider_ptr));
GTEST_SUCCEED();
return;
}
EXPECT_TRUE(dd_result);
EXPECT_TRUE(std::dynamic_pointer_cast<MFPAsyncDemuxDataProvider>(provider_ptr));
}
INSTANTIATE_TEST_CASE_P(MFP_VPL_DecodeHeaderTests, OneVPL_Source_MFPAsyncDispatcherTest,
testing::ValuesIn(files));
namespace test {
struct IntrusiveAsyncDemuxDataProvider :
public cv::gapi::wip::onevpl::MFPAsyncDemuxDataProvider {
using base_t = cv::gapi::wip::onevpl::MFPAsyncDemuxDataProvider;
using base_t::base_t;
~IntrusiveAsyncDemuxDataProvider() {
destroyed = true;
}
STDMETHODIMP OnReadSample(HRESULT status, DWORD stream_index,
DWORD stream_flag, LONGLONG timestamp,
IMFSample *sample_ptr) override {
if (IntrusiveAsyncDemuxDataProvider::need_request_next) {
return base_t::OnReadSample(status, stream_index, stream_flag,
timestamp, sample_ptr);
}
return status;
}
// implementation methods
size_t produce_worker_data(void *key,
cv::gapi::wip::onevpl::ComPtrGuard<IMFMediaBuffer> &&buffer,
std::shared_ptr<mfx_bitstream> &&staging_stream) override {
return base_t::produce_worker_data(key, std::move(buffer),
std::move(staging_stream));
}
static bool need_request_next;
static bool destroyed;
};
bool IntrusiveAsyncDemuxDataProvider::need_request_next{};
bool IntrusiveAsyncDemuxDataProvider::destroyed{};
} // namespace test
TEST(OneVPL_Source_MFPAsyncDemux, sync_flush) {
using namespace cv::gapi::wip::onevpl;
source_t path = findDataFile("highgui/video/sample_322x242_15frames.yuv420p.libx265.mp4");
test::IntrusiveAsyncDemuxDataProvider::need_request_next = false;
const size_t preprocessed_samples_count = 3;
{
test::IntrusiveAsyncDemuxDataProvider provider(path, preprocessed_samples_count);
size_t produce_buffer_count = 199 * preprocessed_samples_count;
std::thread producer([&provider, produce_buffer_count]() {
size_t total_produced_count = 0;
for (size_t i = 0; i < produce_buffer_count; i ++) {
total_produced_count += provider.produce_worker_data(
reinterpret_cast<void*>(i),
createCOMPtrGuard<IMFMediaBuffer>(nullptr),
{});
}
});
producer.join();
}
EXPECT_EQ(test::IntrusiveAsyncDemuxDataProvider::destroyed, true);
}
TEST(OneVPL_Source_MFPAsyncDemux, async_flush) {
using namespace cv::gapi::wip::onevpl;
source_t path = findDataFile("highgui/video/sample_322x242_15frames.yuv420p.libx265.mp4");
test::IntrusiveAsyncDemuxDataProvider::need_request_next = true;
const size_t preprocessed_samples_count = 999;
{
std::shared_ptr<IDataProvider::mfx_bitstream> stream;
test::IntrusiveAsyncDemuxDataProvider provider(path, preprocessed_samples_count);
EXPECT_TRUE(provider.fetch_bitstream_data(stream));
EXPECT_TRUE(stream);
}
EXPECT_EQ(test::IntrusiveAsyncDemuxDataProvider::destroyed, true);
}
TEST(OneVPL_Source_MFPAsyncDemux, eof_async_detection) {
using namespace cv::gapi::wip::onevpl;
source_t path = findDataFile("highgui/video/sample_322x242_15frames.yuv420p.libx265.mp4");
test::IntrusiveAsyncDemuxDataProvider::need_request_next = false;
const size_t preprocessed_samples_count = 0; // do not ask sample at start
test::IntrusiveAsyncDemuxDataProvider provider(path, preprocessed_samples_count);
std::promise<void> start_consume_data;
std::future<void> wait_consume_data = start_consume_data.get_future();
std::thread fetcher([&provider, &start_consume_data]() {
std::shared_ptr<IDataProvider::mfx_bitstream> stream;
start_consume_data.set_value();
EXPECT_FALSE(provider.fetch_bitstream_data(stream));
EXPECT_FALSE(stream);
});
wait_consume_data.wait();
std::this_thread::sleep_for(std::chrono::seconds(2)); // hope fetched has slept on condition
test::IntrusiveAsyncDemuxDataProvider::need_request_next = true;
provider.OnReadSample(S_OK, 0, MF_SOURCE_READERF_ENDOFSTREAM, 0, nullptr);
fetcher.join();
}
TEST(OneVPL_Source_MFPAsyncDemux, produce_consume) {
using namespace cv::gapi::wip::onevpl;
source_t path = findDataFile("highgui/video/sample_322x242_15frames.yuv420p.libx265.mp4");
test::IntrusiveAsyncDemuxDataProvider::need_request_next = false;
const size_t preprocessed_samples_count = 3;
test::IntrusiveAsyncDemuxDataProvider provider(path, preprocessed_samples_count);
std::promise<void> start_consume_data;
std::future<void> wait_consume_data = start_consume_data.get_future();
size_t produce_buffer_count = 199 * preprocessed_samples_count;
std::thread producer([&provider, &wait_consume_data, produce_buffer_count]() {
wait_consume_data.wait();
size_t total_produced_count = 0;
for (size_t i = 0; i < produce_buffer_count; i ++) {
std::shared_ptr<IDataProvider::mfx_bitstream> dummy_stream =
std::make_shared<IDataProvider::mfx_bitstream>();
dummy_stream->DataLength = static_cast<mfxU32>(i); // control block
dummy_stream->DataOffset = static_cast<mfxU32>(i); // control block
dummy_stream->Data = reinterpret_cast<mfxU8*>(i);
total_produced_count = provider.produce_worker_data(
dummy_stream->Data,
createCOMPtrGuard<IMFMediaBuffer>(nullptr),
std::move(dummy_stream));
EXPECT_TRUE(total_produced_count <= produce_buffer_count);
}
});
std::thread consumer([&provider, &start_consume_data, produce_buffer_count]() {
start_consume_data.set_value();
size_t total_consumed_count = 0;
std::shared_ptr<IDataProvider::mfx_bitstream> dummy_stream;
size_t stream_idx = 0;
do {
EXPECT_TRUE(provider.fetch_bitstream_data(dummy_stream));
EXPECT_TRUE(dummy_stream);
EXPECT_EQ(dummy_stream->DataLength, stream_idx);
stream_idx ++;
total_consumed_count++;
} while (total_consumed_count != produce_buffer_count);
});
producer.join();
consumer.join();
}
}
} // namespace opencv_test
#endif // HAVE_ONEVPL
@@ -0,0 +1,224 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation
#include "../test_precomp.hpp"
#include "../common/gapi_tests_common.hpp"
#include <opencv2/gapi/cpu/core.hpp>
#include <opencv2/gapi/ocl/core.hpp>
#include <opencv2/gapi/streaming/onevpl/source.hpp>
#ifdef HAVE_DIRECTX
#ifdef HAVE_D3D11
#pragma comment(lib,"d3d11.lib")
// get rid of generate macro max/min/etc from DX side
#define D3D11_NO_HELPERS
#define NOMINMAX
#include <d3d11.h>
#include <codecvt>
#include "opencv2/core/directx.hpp"
#undef D3D11_NO_HELPERS
#undef NOMINMAX
#endif // HAVE_D3D11
#endif // HAVE_DIRECTX
#ifdef HAVE_ONEVPL
#include "streaming/onevpl/onevpl_export.hpp"
#include "streaming/onevpl/cfg_param_device_selector.hpp"
namespace opencv_test
{
namespace
{
void test_dev_eq(const typename cv::gapi::wip::onevpl::IDeviceSelector::DeviceScoreTable::value_type &scored_device,
cv::gapi::wip::onevpl::IDeviceSelector::Score expected_score,
cv::gapi::wip::onevpl::AccelType expected_type,
cv::gapi::wip::onevpl::Device::Ptr expected_ptr) {
EXPECT_EQ(std::get<0>(scored_device), expected_score);
EXPECT_EQ(std::get<1>(scored_device).get_type(), expected_type);
EXPECT_EQ(std::get<1>(scored_device).get_ptr(), expected_ptr);
}
void test_ctx_eq(const typename cv::gapi::wip::onevpl::IDeviceSelector::DeviceContexts::value_type &ctx,
cv::gapi::wip::onevpl::AccelType expected_type,
cv::gapi::wip::onevpl::Context::Ptr expected_ptr) {
EXPECT_EQ(ctx.get_type(), expected_type);
EXPECT_EQ(ctx.get_ptr(), expected_ptr);
}
void test_host_dev_eq(const typename cv::gapi::wip::onevpl::IDeviceSelector::DeviceScoreTable::value_type &scored_device,
cv::gapi::wip::onevpl::IDeviceSelector::Score expected_score) {
test_dev_eq(scored_device, expected_score,
cv::gapi::wip::onevpl::AccelType::HOST, nullptr);
}
void test_host_ctx_eq(const typename cv::gapi::wip::onevpl::IDeviceSelector::DeviceContexts::value_type &ctx) {
test_ctx_eq(ctx, cv::gapi::wip::onevpl::AccelType::HOST, nullptr);
}
TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDevice)
{
using namespace cv::gapi::wip::onevpl;
CfgParamDeviceSelector selector;
IDeviceSelector::DeviceScoreTable devs = selector.select_devices();
EXPECT_EQ(devs.size(), 1);
test_host_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority);
IDeviceSelector::DeviceContexts ctxs = selector.select_context();
EXPECT_EQ(ctxs.size(), 1);
test_host_ctx_eq(*ctxs.begin());
}
TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDeviceWithEmptyCfgParam)
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> empty_params;
CfgParamDeviceSelector selector(empty_params);
IDeviceSelector::DeviceScoreTable devs = selector.select_devices();
EXPECT_EQ(devs.size(), 1);
test_host_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority);
IDeviceSelector::DeviceContexts ctxs = selector.select_context();
EXPECT_EQ(ctxs.size(), 1);
test_host_ctx_eq(*ctxs.begin());
}
TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDeviceWithAccelNACfgParam)
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> cfg_params_w_no_accel;
cfg_params_w_no_accel.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_NA));
CfgParamDeviceSelector selector(cfg_params_w_no_accel);
IDeviceSelector::DeviceScoreTable devs = selector.select_devices();
EXPECT_EQ(devs.size(), 1);
test_host_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority);
IDeviceSelector::DeviceContexts ctxs = selector.select_context();
EXPECT_EQ(ctxs.size(), 1);
test_host_ctx_eq(*ctxs.begin());
}
#ifdef HAVE_DIRECTX
#ifdef HAVE_D3D11
TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDeviceWithEmptyCfgParam_DX11_ENABLED)
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> empty_params;
CfgParamDeviceSelector selector(empty_params);
IDeviceSelector::DeviceScoreTable devs = selector.select_devices();
EXPECT_EQ(devs.size(), 1);
test_host_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority);
IDeviceSelector::DeviceContexts ctxs = selector.select_context();
EXPECT_EQ(ctxs.size(), 1);
test_host_ctx_eq(*ctxs.begin());
}
TEST(OneVPL_Source_Device_Selector_CfgParam, DefaultDeviceWithDX11AccelCfgParam_DX11_ENABLED)
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> cfg_params_w_dx11;
cfg_params_w_dx11.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
std::unique_ptr<CfgParamDeviceSelector> selector_ptr;
EXPECT_NO_THROW(selector_ptr.reset(new CfgParamDeviceSelector(cfg_params_w_dx11)));
IDeviceSelector::DeviceScoreTable devs = selector_ptr->select_devices();
EXPECT_EQ(devs.size(), 1);
test_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority,
AccelType::DX11,
std::get<1>(*devs.begin()).get_ptr() /* compare just type */);
IDeviceSelector::DeviceContexts ctxs = selector_ptr->select_context();
EXPECT_EQ(ctxs.size(), 1);
EXPECT_TRUE(ctxs.begin()->get_ptr());
}
TEST(OneVPL_Source_Device_Selector_CfgParam, NULLDeviceWithDX11AccelCfgParam_DX11_ENABLED)
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> cfg_params_w_dx11;
cfg_params_w_dx11.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
Device::Ptr empty_device_ptr = nullptr;
Context::Ptr empty_ctx_ptr = nullptr;
EXPECT_THROW(CfgParamDeviceSelector sel(empty_device_ptr, "GPU",
empty_ctx_ptr,
cfg_params_w_dx11),
std::logic_error); // empty_device_ptr must be invalid
}
TEST(OneVPL_Source_Device_Selector_CfgParam, ExternalDeviceWithDX11AccelCfgParam_DX11_ENABLED)
{
using namespace cv::gapi::wip::onevpl;
ID3D11Device *device = nullptr;
ID3D11DeviceContext* device_context = nullptr;
{
UINT flags = 0;
D3D_FEATURE_LEVEL features[] = { D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
};
D3D_FEATURE_LEVEL feature_level;
// Create the Direct3D 11 API device object and a corresponding context.
HRESULT err = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE,
nullptr, flags,
features,
ARRAYSIZE(features), D3D11_SDK_VERSION,
&device, &feature_level, &device_context);
EXPECT_FALSE(FAILED(err));
}
std::unique_ptr<CfgParamDeviceSelector> selector_ptr;
std::vector<CfgParam> cfg_params_w_dx11;
cfg_params_w_dx11.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
EXPECT_NO_THROW(selector_ptr.reset(new CfgParamDeviceSelector(device, "GPU",
device_context,
cfg_params_w_dx11)));
IDeviceSelector::DeviceScoreTable devs = selector_ptr->select_devices();
EXPECT_EQ(devs.size(), 1);
test_dev_eq(*devs.begin(), IDeviceSelector::Score::MaxActivePriority,
AccelType::DX11, device);
IDeviceSelector::DeviceContexts ctxs = selector_ptr->select_context();
EXPECT_EQ(ctxs.size(), 1);
EXPECT_EQ(reinterpret_cast<ID3D11DeviceContext*>(ctxs.begin()->get_ptr()),
device_context);
}
#endif // HAVE_D3D11
#endif // HAVE_DIRECTX
#ifndef HAVE_DIRECTX
#ifndef HAVE_D3D11
TEST(OneVPL_Source_Device_Selector_CfgParam, DX11DeviceFromCfgParamWithDX11Disabled)
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> cfg_params_w_non_existed_dx11;
cfg_params_w_not_existed_dx11.push_back(CfgParam::create_acceleration_mode(MFX_ACCEL_MODE_VIA_D3D11));
EXPECT_THROW(CfgParamDeviceSelector{cfg_params_w_non_existed_dx11},
std::logic_error);
}
#endif // HAVE_D3D11
#endif // HAVE_DIRECTX
TEST(OneVPL_Source_Device_Selector_CfgParam, UnknownPtrDeviceFromCfgParam)
{
using namespace cv::gapi::wip::onevpl;
std::vector<CfgParam> empty_params;
Device::Ptr empty_device_ptr = nullptr;
Context::Ptr empty_ctx_ptr = nullptr;
EXPECT_THROW(CfgParamDeviceSelector sel(empty_device_ptr, "",
empty_ctx_ptr,
empty_params),
std::logic_error); // params must describe device_ptr explicitly
}
}
} // namespace opencv_test
#endif // HAVE_ONEVPL
+1 -1
View File
@@ -9,4 +9,4 @@
#include "test_precomp.hpp"
CV_TEST_MAIN("gapi")
CV_TEST_MAIN("")
+15 -15
View File
@@ -17,10 +17,10 @@ TEST(Any, basic)
any a(8);
auto casted_pointer = any_cast<int>(&a);
ASSERT_NE(nullptr, casted_pointer);
ASSERT_EQ(*casted_pointer, 8);
ASSERT_EQ(8, *casted_pointer);
*casted_pointer = 7;
ASSERT_EQ(any_cast<int>(a), 7);
ASSERT_EQ(7, any_cast<int>(a));
}
TEST(Any, any_cast_ref_throws_on_empty)
@@ -36,13 +36,13 @@ TEST(Any, copy)
using namespace util;
any a(8);
ASSERT_EQ(any_cast<int>(a), 8);
ASSERT_EQ(8, any_cast<int>(a));
any b (a);
ASSERT_NE(nullptr, any_cast<int>(&b));
ASSERT_EQ(8 , any_cast<int>(b));
ASSERT_EQ(8 , any_cast<int>(a));
ASSERT_EQ(8, any_cast<int>(b));
ASSERT_EQ(8, any_cast<int>(a));
}
TEST(Any, copy_empty)
@@ -63,12 +63,12 @@ TEST(Any, move)
using namespace util;
any a(8);
ASSERT_EQ(any_cast<int>(a), 8);
ASSERT_EQ(8, any_cast<int>(a));
any b (std::move(a));
ASSERT_NE(nullptr, any_cast<int>(&b));
ASSERT_EQ(8 , any_cast<int>(b));
ASSERT_EQ(8, any_cast<int>(b));
ASSERT_EQ(nullptr, any_cast<int>(&a));
}
@@ -93,12 +93,12 @@ TEST(Any, move_assign)
any a(8);
any b;
ASSERT_EQ(any_cast<int>(a), 8);
ASSERT_EQ(8, any_cast<int>(a));
b = (std::move(a));
ASSERT_NE(nullptr, any_cast<int>(&b));
ASSERT_EQ(8 , any_cast<int>(b));
ASSERT_EQ(8, any_cast<int>(b));
ASSERT_EQ(nullptr, any_cast<int>(&a));
}
@@ -108,14 +108,14 @@ TEST(Any, copy_assign)
any a(8);
any b;
ASSERT_EQ(any_cast<int>(a), 8);
ASSERT_EQ(8, any_cast<int>(a));
ASSERT_EQ(nullptr, any_cast<int>(&b));
b = a;
ASSERT_NE(nullptr, any_cast<int>(&b));
ASSERT_EQ(8 , any_cast<int>(b));
ASSERT_EQ(8 , any_cast<int>(a));
ASSERT_EQ(8, any_cast<int>(b));
ASSERT_EQ(8, any_cast<int>(a));
}
TEST(Any, get_ref_to_val_from_any)
@@ -125,7 +125,7 @@ TEST(Any, get_ref_to_val_from_any)
any a(x);
int& casted_ref = any_cast<int>(a);
ASSERT_EQ(casted_ref, 8);
ASSERT_EQ(8, casted_ref);
}
TEST(Any, update_val_via_ref)
@@ -134,9 +134,9 @@ TEST(Any, update_val_via_ref)
int x = 8;
any a(x);
int& casted_ref = any_cast<int>(a);
ASSERT_EQ(casted_ref, 8);
ASSERT_EQ(8, casted_ref);
casted_ref = 7;
ASSERT_EQ(any_cast<int>(a), 7);
ASSERT_EQ(7, any_cast<int>(a));
}
} // namespace opencv_test
+21 -21
View File
@@ -587,34 +587,34 @@ TEST(Variant, DynamicVisitor)
test_validation::MyBoolParamIndexedVisitor visitor(ss);
EXPECT_TRUE(cv::util::visit(visitor, var, int{42}));
EXPECT_EQ(ss.str(), std::string("0:42,"));
EXPECT_EQ(std::string("0:42,"), ss.str());
}
std::stringstream ss;
test_validation::MyBoolNoParamNonIndexedVisitor visitor(ss);
cv::util::visit(visitor, var);
EXPECT_EQ(ss.str(), std::string("0:42,"));
EXPECT_EQ(std::string("0:42,"), ss.str());
var = double{1.0};
EXPECT_TRUE(cv::util::visit(visitor, var));
EXPECT_EQ(ss.str(), std::string("0:42,1:1,"));
EXPECT_EQ(std::string("0:42,1:1,"), ss.str());
var = char{'a'};
EXPECT_TRUE(cv::util::visit(visitor, var));
EXPECT_EQ(ss.str(), std::string("0:42,1:1,2:a,"));
EXPECT_EQ(std::string("0:42,1:1,2:a,"), ss.str());
var = float{6.0};
EXPECT_TRUE(cv::util::visit(visitor, var));
EXPECT_EQ(ss.str(), std::string("0:42,1:1,2:a,3:6,"));
EXPECT_EQ(std::string("0:42,1:1,2:a,3:6,"), ss.str());
var = test_validation::MyType{};
EXPECT_TRUE(cv::util::visit(visitor, var));
EXPECT_EQ(ss.str(), std::string("0:42,1:1,2:a,3:6,4:MyType,"));
EXPECT_EQ(std::string("0:42,1:1,2:a,3:6,4:MyType,"), ss.str());
var = test_validation::MyClass{};
EXPECT_TRUE(cv::util::visit(visitor, var));
EXPECT_EQ(ss.str(), std::string("0:42,1:1,2:a,3:6,4:MyType,5:MyClass,"));
EXPECT_EQ(std::string("0:42,1:1,2:a,3:6,4:MyType,5:MyClass,"), ss.str());
}
TEST(Variant, StaticVisitor)
@@ -625,27 +625,27 @@ TEST(Variant, StaticVisitor)
test_validation::MyVoidNoParamNonIndexedVisitor visitor(ss);
cv::util::visit(visitor, var);
EXPECT_EQ(ss.str(), std::string("42,"));
EXPECT_EQ(std::string("42,"), ss.str());
var = double{1.0};
cv::util::visit(visitor, var);
EXPECT_EQ(ss.str(), std::string("42,1,"));
EXPECT_EQ(std::string("42,1,"), ss.str());
var = char{'a'};
cv::util::visit(visitor, var);
EXPECT_EQ(ss.str(), std::string("42,1,a,"));
EXPECT_EQ(std::string("42,1,a,"), ss.str());
var = float{6.0};
cv::util::visit(visitor, var);
EXPECT_EQ(ss.str(), std::string("42,1,a,6,"));
EXPECT_EQ(std::string("42,1,a,6,"), ss.str());
var = test_validation::MyType{};
cv::util::visit(visitor, var);
EXPECT_EQ(ss.str(), std::string("42,1,a,6,MyType,"));
EXPECT_EQ(std::string("42,1,a,6,MyType,"), ss.str());
var = test_validation::MyClass{};
cv::util::visit(visitor, var);
EXPECT_EQ(ss.str(), std::string("42,1,a,6,MyType,MyClass,"));
EXPECT_EQ(std::string("42,1,a,6,MyType,MyClass,"), ss.str());
}
TEST(Variant, StaticIndexedVisitor)
@@ -655,27 +655,27 @@ TEST(Variant, StaticIndexedVisitor)
std::stringstream ss;
cv::util::visit(test_validation::MyVoidNoParamIndexedVisitor {ss}, var);
EXPECT_EQ(ss.str(), std::string("0:42,"));
EXPECT_EQ(std::string("0:42,"), ss.str());
var = double{1.0};
cv::util::visit(test_validation::MyVoidNoParamIndexedVisitor (ss), var);
EXPECT_EQ(ss.str(), std::string("0:42,1:1,"));
EXPECT_EQ(std::string("0:42,1:1,"), ss.str());
var = char{'a'};
cv::util::visit(test_validation::MyVoidNoParamIndexedVisitor (ss), var);
EXPECT_EQ(ss.str(), std::string("0:42,1:1,2:a,"));
EXPECT_EQ(std::string("0:42,1:1,2:a,"), ss.str());
var = float{6.0};
cv::util::visit(test_validation::MyVoidNoParamIndexedVisitor (ss), var);
EXPECT_EQ(ss.str(), std::string("0:42,1:1,2:a,3:6,"));
EXPECT_EQ(std::string("0:42,1:1,2:a,3:6,"), ss.str());
var = test_validation::MyType{};
cv::util::visit(test_validation::MyVoidNoParamIndexedVisitor (ss), var);
EXPECT_EQ(ss.str(), std::string("0:42,1:1,2:a,3:6,4:MyType,"));
EXPECT_EQ(std::string("0:42,1:1,2:a,3:6,4:MyType,"), ss.str());
var = test_validation::MyClass{};
cv::util::visit(test_validation::MyVoidNoParamIndexedVisitor (ss), var);
EXPECT_EQ(ss.str(), std::string("0:42,1:1,2:a,3:6,4:MyType,5:MyClass,"));
EXPECT_EQ(std::string("0:42,1:1,2:a,3:6,4:MyType,5:MyClass,"), ss.str());
}
@@ -686,7 +686,7 @@ TEST(Variant, LambdaVisitor)
{
cv::util::visit(cv::util::overload_lambdas(
[](int value) {
EXPECT_EQ(value, 42);
EXPECT_EQ(42, value);
},
[](double) {
ADD_FAILURE() << "can't be called for `double`";
@@ -719,7 +719,7 @@ TEST(Variant, LambdaVisitor)
ADD_FAILURE() << "can't be called for `double`";
},
[](char value) {
EXPECT_EQ(value, 'c');
EXPECT_EQ('c', value);
},
[](float) {
ADD_FAILURE() << "can't be called for `float`";