Commit abfcb601 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #13838 from smirnov-alexey:gapi_add_nv12_to_rgb

parents 54a1bbe1 406392e1
......@@ -114,6 +114,34 @@ namespace imgproc {
}
};
G_TYPED_KERNEL(GNV12toRGB, <GMat(GMat, GMat)>, "org.opencv.imgproc.colorconvert.nv12torgb") {
static GMatDesc outMeta(GMatDesc in_y, GMatDesc in_uv) {
GAPI_Assert(in_y.chan == 1);
GAPI_Assert(in_uv.chan == 2);
GAPI_Assert(in_y.depth == CV_8U);
GAPI_Assert(in_uv.depth == CV_8U);
GAPI_Assert(in_uv.size.width % 2 == 0);
GAPI_Assert(in_uv.size.height % 2 == 0);
GAPI_Assert(in_y.size.width == 2 * in_uv.size.width);
GAPI_Assert(in_y.size.height == 2 * in_uv.size.height);
return in_y.withType(CV_8U, 3); // type will be CV_8UC3;
}
};
G_TYPED_KERNEL(GNV12toBGR, <GMat(GMat, GMat)>, "org.opencv.imgproc.colorconvert.nv12tobgr") {
static GMatDesc outMeta(GMatDesc in_y, GMatDesc in_uv) {
GAPI_Assert(in_y.chan == 1);
GAPI_Assert(in_uv.chan == 2);
GAPI_Assert(in_y.depth == CV_8U);
GAPI_Assert(in_uv.depth == CV_8U);
GAPI_Assert(in_uv.size.width % 2 == 0);
GAPI_Assert(in_uv.size.height % 2 == 0);
GAPI_Assert(in_y.size.width == 2 * in_uv.size.width);
GAPI_Assert(in_y.size.height == 2 * in_uv.size.height);
return in_y.withType(CV_8U, 3); // type will be CV_8UC3;
}
};
G_TYPED_KERNEL(GRGB2Lab, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.rgb2lab") {
static GMatDesc outMeta(GMatDesc in) {
return in; // type still remains CV_8UC3;
......@@ -728,6 +756,36 @@ Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
@sa RGB2Lab, RGB2YUV
*/
GAPI_EXPORTS GMat YUV2RGB(const GMat& src);
/** @brief Converts an image from NV12 (YUV420p) color space to RGB.
The function converts an input image from NV12 color space to RGB.
The conventional ranges for Y, U, and V channel values are 0 to 255.
Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgb"
@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2.
@sa YUV2RGB, NV12toBGR
*/
GAPI_EXPORTS GMat NV12toRGB(const GMat& src_y, const GMat& src_uv);
/** @brief Converts an image from NV12 (YUV420p) color space to BGR.
The function converts an input image from NV12 color space to RGB.
The conventional ranges for Y, U, and V channel values are 0 to 255.
Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12tobgr"
@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2.
@sa YUV2BGR, NV12toRGB
*/
GAPI_EXPORTS GMat NV12toBGR(const GMat& src_y, const GMat& src_uv);
//! @} gapi_colorconvert
} //namespace gapi
} //namespace cv
......
......@@ -142,6 +142,16 @@ GMat YUV2RGB(const GMat& src)
return imgproc::GYUV2RGB::on(src);
}
GMat NV12toRGB(const GMat& src_y, const GMat& src_uv)
{
return imgproc::GNV12toRGB::on(src_y, src_uv);
}
GMat NV12toBGR(const GMat& src_y, const GMat& src_uv)
{
return imgproc::GNV12toBGR::on(src_y, src_uv);
}
GMat RGB2Lab(const GMat& src)
{
return imgproc::GRGB2Lab::on(src);
......
......@@ -194,6 +194,22 @@ GAPI_OCV_KERNEL(GCPUYUV2RGB, cv::gapi::imgproc::GYUV2RGB)
}
};
GAPI_OCV_KERNEL(GCPUNV12toRGB, cv::gapi::imgproc::GNV12toRGB)
{
static void run(const cv::Mat& in_y, const cv::Mat& in_uv, cv::Mat &out)
{
cv::cvtColorTwoPlane(in_y, in_uv, out, cv::COLOR_YUV2RGB_NV12);
}
};
GAPI_OCV_KERNEL(GCPUNV12toBGR, cv::gapi::imgproc::GNV12toBGR)
{
static void run(const cv::Mat& in_y, const cv::Mat& in_uv, cv::Mat &out)
{
cv::cvtColorTwoPlane(in_y, in_uv, out, cv::COLOR_YUV2BGR_NV12);
}
};
GAPI_OCV_KERNEL(GCPURGB2Lab, cv::gapi::imgproc::GRGB2Lab)
{
static void run(const cv::Mat& in, cv::Mat &out)
......@@ -277,6 +293,8 @@ cv::gapi::GKernelPackage cv::gapi::imgproc::cpu::kernels()
, GCPUEqualizeHist
, GCPURGB2YUV
, GCPUYUV2RGB
, GCPUNV12toRGB
, GCPUNV12toBGR
, GCPURGB2Lab
, GCPUBGR2LUV
, GCPUBGR2YUV
......
......@@ -33,6 +33,8 @@ struct RGB2GrayTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::
struct BGR2GrayTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct RGB2YUVTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct YUV2RGBTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct NV12toRGBTest : public TestParams<std::tuple<compare_f,cv::Size,cv::GCompileArgs>> {};
struct NV12toBGRTest : public TestParams<std::tuple<compare_f,cv::Size,cv::GCompileArgs>> {};
struct RGB2LabTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct BGR2LUVTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct LUV2BGRTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
......
......@@ -548,6 +548,66 @@ TEST_P(YUV2RGBTest, AccuracyTest)
}
}
TEST_P(NV12toRGBTest, AccuracyTest)
{
compare_f cmpF;
cv::Size sz;
cv::GCompileArgs compile_args;
std::tie(cmpF, sz, compile_args) = GetParam();
initMatsRandN(CV_8UC1, sz, CV_8UC3);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in_y;
cv::GMat in_uv;
auto out = cv::gapi::NV12toRGB(in_y, in_uv);
// Additional mat for uv
cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi), std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2RGB_NV12);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(NV12toBGRTest, AccuracyTest)
{
compare_f cmpF;
cv::Size sz;
cv::GCompileArgs compile_args;
std::tie(cmpF, sz, compile_args) = GetParam();
initMatsRandN(CV_8UC1, sz, CV_8UC3);
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in_y;
cv::GMat in_uv;
auto out = cv::gapi::NV12toBGR(in_y, in_uv);
// Additional mat for uv
cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi), std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2BGR_NV12);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(RGB2LabTest, AccuracyTest)
{
auto param = GetParam();
......
......@@ -224,6 +224,18 @@ INSTANTIATE_TEST_CASE_P(YUV2RGBTestCPU, YUV2RGBTest,
/*init output matrices or not*/ testing::Bool(),
Values(cv::compile_args(IMGPROC_CPU))));
INSTANTIATE_TEST_CASE_P(NV12toRGBTestCPU, NV12toRGBTest,
Combine(Values(AbsExact().to_compare_f()),
Values(cv::Size(1280, 720),
cv::Size(640, 480)),
Values(cv::compile_args(IMGPROC_CPU))));
INSTANTIATE_TEST_CASE_P(NV12toBGRTestCPU, NV12toBGRTest,
Combine(Values(AbsExact().to_compare_f()),
Values(cv::Size(1280, 720),
cv::Size(640, 480)),
Values(cv::compile_args(IMGPROC_CPU))));
INSTANTIATE_TEST_CASE_P(RGB2LabTestCPU, RGB2LabTest,
Combine(Values(AbsExact().to_compare_f()),
Values(cv::Size(1280, 720),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment