mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge pull request #14917 from rgarnov:gapi_planar_kernels
G-API planar kernels (#14917) * Added resizeP with tests * NV12 planar filters * fix warnings in ResizeP test * fix out mat ocv warning * sz_on - > sz rename * cpu tests new signature * try to fix resizeP test * trailing spaces remove * doxygen doc fixed * doxygen minor fix * more doxygen fixes * Doxygen corrected and extended after review.
This commit is contained in:
committed by
Alexander Alekhin
parent
097d81363b
commit
ad49138fae
@@ -145,6 +145,8 @@ GAPI_TEST_FIXTURE(Split3Test, initMatrixRandU, <>, 0)
|
||||
GAPI_TEST_FIXTURE(Split4Test, initMatrixRandU, <>, 0)
|
||||
GAPI_TEST_FIXTURE(ResizeTest, initNothing, FIXTURE_API(compare_f,int,cv::Size), 3,
|
||||
cmpF, interp, sz_out)
|
||||
GAPI_TEST_FIXTURE(ResizePTest, initNothing, FIXTURE_API(compare_f,int,cv::Size), 3,
|
||||
cmpF, interp, sz_out)
|
||||
GAPI_TEST_FIXTURE(ResizeTestFxFy, initNothing, FIXTURE_API(compare_f,int,double,double), 4,
|
||||
cmpF, interp, fx, fy)
|
||||
GAPI_TEST_FIXTURE(Merge3Test, initMatsRandU, <>, 0)
|
||||
|
||||
@@ -848,6 +848,37 @@ 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);
|
||||
|
||||
@@ -42,6 +42,8 @@ GAPI_TEST_FIXTURE(BGR2GrayTest, initMatrixRandN, FIXTURE_API(compare_f), 1, cmpF
|
||||
GAPI_TEST_FIXTURE(RGB2YUVTest, initMatrixRandN, FIXTURE_API(compare_f), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(YUV2RGBTest, initMatrixRandN, FIXTURE_API(compare_f), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NV12toRGBTest, initMatrixRandN, FIXTURE_API(compare_f), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NV12toBGRpTest, initMatrixRandN, FIXTURE_API(compare_f), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NV12toRGBpTest, initMatrixRandN, FIXTURE_API(compare_f), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(NV12toBGRTest, initMatrixRandN, FIXTURE_API(compare_f), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(RGB2LabTest, initMatrixRandN, FIXTURE_API(compare_f), 1, cmpF)
|
||||
GAPI_TEST_FIXTURE(BGR2LUVTest, initMatrixRandN, FIXTURE_API(compare_f), 1, cmpF)
|
||||
|
||||
@@ -489,6 +489,80 @@ TEST_P(NV12toBGRTest, AccuracyTest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void toPlanar(const cv::Mat& in, cv::Mat& out)
|
||||
{
|
||||
GAPI_Assert(out.depth() == in.depth());
|
||||
GAPI_Assert(out.channels() == 1);
|
||||
GAPI_Assert(in.channels() == 3);
|
||||
GAPI_Assert(out.cols == in.cols);
|
||||
GAPI_Assert(out.rows == 3*in.rows);
|
||||
|
||||
std::vector<cv::Mat> outs(3);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
outs[i] = out(cv::Rect(0, i*in.rows, in.cols, in.rows));
|
||||
}
|
||||
cv::split(in, outs);
|
||||
}
|
||||
|
||||
TEST_P(NV12toRGBpTest, AccuracyTest)
|
||||
{
|
||||
cv::Size sz_p = cv::Size(sz.width, sz.height * 3);
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in_y;
|
||||
cv::GMat in_uv;
|
||||
auto out = cv::gapi::NV12toRGBp(in_y, in_uv);
|
||||
|
||||
// Additional mat for uv
|
||||
cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
|
||||
cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
|
||||
|
||||
cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
|
||||
cv::Mat out_mat_gapi_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
|
||||
c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi_planar), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
cv::Mat out_mat_ocv_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
|
||||
{
|
||||
cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2RGB_NV12);
|
||||
toPlanar(out_mat_ocv, out_mat_ocv_planar);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi_planar, out_mat_ocv_planar));
|
||||
EXPECT_EQ(out_mat_gapi_planar.size(), sz_p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_P(NV12toBGRpTest, AccuracyTest)
|
||||
{
|
||||
cv::Size sz_p = cv::Size(sz.width, sz.height * 3);
|
||||
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
cv::GMat in_y;
|
||||
cv::GMat in_uv;
|
||||
auto out = cv::gapi::NV12toBGRp(in_y, in_uv);
|
||||
|
||||
// Additional mat for uv
|
||||
cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
|
||||
cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
|
||||
|
||||
cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
|
||||
cv::Mat out_mat_gapi_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
|
||||
c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi_planar), getCompileArgs());
|
||||
// OpenCV code /////////////////////////////////////////////////////////////
|
||||
cv::Mat out_mat_ocv_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
|
||||
{
|
||||
cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2BGR_NV12);
|
||||
toPlanar(out_mat_ocv, out_mat_ocv_planar);
|
||||
}
|
||||
// Comparison //////////////////////////////////////////////////////////////
|
||||
{
|
||||
EXPECT_TRUE(cmpF(out_mat_gapi_planar, out_mat_ocv_planar));
|
||||
EXPECT_EQ(out_mat_gapi_planar.size(), sz_p);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(RGB2LabTest, AccuracyTest)
|
||||
{
|
||||
// G-API code //////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user