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:
Ruslan Garnov
2019-07-04 18:19:09 +03:00
committed by Alexander Alekhin
parent 097d81363b
commit ad49138fae
12 changed files with 305 additions and 1 deletions
+5
View File
@@ -301,6 +301,11 @@ GMat resize(const GMat& src, const Size& dsize, double fx, double fy, int interp
return core::GResize::on(src, dsize, fx, fy, interpolation);
}
GMatP resizeP(const GMatP& src, const Size& dsize, int interpolation)
{
return core::GResizeP::on(src, dsize, interpolation);
}
GMat remap(const GMat& src, const Mat& map1, const Mat& map2,
int interpolation, int borderMode,
const Scalar& borderValue)
+10
View File
@@ -169,5 +169,15 @@ GMat RGB2YUV422(const GMat& src) {
return imgproc::GRGB2YUV422::on(src);
}
GMatP NV12toRGBp(const GMat &y, const GMat &uv)
{
return imgproc::GNV12toRGBp::on(y, uv);
}
GMatP NV12toBGRp(const GMat &y, const GMat &uv)
{
return imgproc::GNV12toBGRp::on(y, uv);
}
} //namespace gapi
} //namespace cv
@@ -461,6 +461,22 @@ GAPI_OCV_KERNEL(GCPUResize, cv::gapi::core::GResize)
}
};
GAPI_OCV_KERNEL(GCPUResizeP, cv::gapi::core::GResizeP)
{
static void run(const cv::Mat& in, cv::Size out_sz, int interp, cv::Mat& out)
{
int inH = in.rows / 3;
int inW = in.cols;
int outH = out.rows / 3;
int outW = out.cols;
for (int i = 0; i < 3; i++) {
auto in_plane = in(cv::Rect(0, i*inH, inW, inH));
auto out_plane = out(cv::Rect(0, i*outH, outW, outH));
cv::resize(in_plane, out_plane, out_sz, 0, 0, interp);
}
}
};
GAPI_OCV_KERNEL(GCPURemap, cv::gapi::core::GRemap)
{
static void run(const cv::Mat& in, const cv::Mat& x, const cv::Mat& y, int a, int b, cv::Scalar s, cv::Mat& out)
@@ -589,6 +605,7 @@ cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()
, GCPUSplit3
, GCPUSplit4
, GCPUResize
, GCPUResizeP
, GCPUMerge3
, GCPUMerge4
, GCPURemap
@@ -309,6 +309,43 @@ GAPI_OCV_KERNEL(GCPURGB2YUV422, cv::gapi::imgproc::GRGB2YUV422)
}
};
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);
}
GAPI_OCV_KERNEL(GCPUNV12toRGBp, cv::gapi::imgproc::GNV12toRGBp)
{
static void run(const cv::Mat& inY, const cv::Mat& inUV, cv::Mat& out)
{
cv::Mat rgb;
cv::cvtColorTwoPlane(inY, inUV, rgb, cv::COLOR_YUV2RGB_NV12);
toPlanar(rgb, out);
}
};
GAPI_OCV_KERNEL(GCPUNV12toBGRp, cv::gapi::imgproc::GNV12toBGRp)
{
static void run(const cv::Mat& inY, const cv::Mat& inUV, cv::Mat& out)
{
cv::Mat rgb;
cv::cvtColorTwoPlane(inY, inUV, rgb, cv::COLOR_YUV2BGR_NV12);
toPlanar(rgb, out);
}
};
cv::gapi::GKernelPackage cv::gapi::imgproc::cpu::kernels()
{
static auto pkg = cv::gapi::kernels
@@ -339,6 +376,8 @@ cv::gapi::GKernelPackage cv::gapi::imgproc::cpu::kernels()
, GCPUBayerGR2RGB
, GCPURGB2HSV
, GCPURGB2YUV422
, GCPUNV12toRGBp
, GCPUNV12toBGRp
>();
return pkg;
}