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

Merge pull request #16803 from TolyaTalamanov:at/yuv-to-gray

* Implement NV12toGray

* Snapshot

* Implement NV12toGray as compound kernel

* Update gapi_imgproc_tests_inl.hpp

* Remove YUV2Gray from public API
This commit is contained in:
Anatoliy Talamanov
2020-03-24 13:51:18 +03:00
committed by GitHub
parent ea34b2fefb
commit 4d3d6230c5
6 changed files with 135 additions and 5 deletions
+11 -3
View File
@@ -157,18 +157,26 @@ GMat RGB2Lab(const GMat& src)
return imgproc::GRGB2Lab::on(src);
}
GMat BayerGR2RGB(const GMat& src_gr) {
GMat BayerGR2RGB(const GMat& src_gr)
{
return imgproc::GBayerGR2RGB::on(src_gr);
}
GMat RGB2HSV(const GMat& src) {
GMat RGB2HSV(const GMat& src)
{
return imgproc::GRGB2HSV::on(src);
}
GMat RGB2YUV422(const GMat& src) {
GMat RGB2YUV422(const GMat& src)
{
return imgproc::GRGB2YUV422::on(src);
}
GMat NV12toGray(const GMat &y, const GMat &uv)
{
return imgproc::GNV12toGray::on(y, uv);
}
GMatP NV12toRGBp(const GMat &y, const GMat &uv)
{
return imgproc::GNV12toRGBp::on(y, uv);
+56 -1
View File
@@ -10,9 +10,11 @@
#include <opencv2/gapi/imgproc.hpp>
#include <opencv2/gapi/cpu/imgproc.hpp>
#include <opencv2/gapi/cpu/gcpukernel.hpp>
#include <opencv2/gapi/gcompoundkernel.hpp>
#include "backends/fluid/gfluidimgproc_func.hpp"
namespace {
cv::Mat add_border(const cv::Mat& in, const int ksize, const int borderType, const cv::Scalar& bordVal){
if( borderType == cv::BORDER_CONSTANT )
@@ -335,6 +337,57 @@ GAPI_OCV_KERNEL(GCPUNV12toRGBp, cv::gapi::imgproc::GNV12toRGBp)
}
};
G_TYPED_KERNEL(GYUV2Gray, <cv::GMat(cv::GMat)>, "yuvtogray") {
static cv::GMatDesc outMeta(cv::GMatDesc in) {
GAPI_Assert(in.depth == CV_8U);
GAPI_Assert(in.planar == false);
GAPI_Assert(in.size.width % 2 == 0);
GAPI_Assert(in.size.height % 3 == 0);
/* YUV format for this kernel:
* Y Y Y Y Y Y Y Y
* Y Y Y Y Y Y Y Y
* Y Y Y Y Y Y Y Y
* Y Y Y Y Y Y Y Y
* U V U V U V U V
* U V U V U V U V
*/
return {CV_8U, 1, cv::gapi::own::Size{in.size.width, in.size.height - (in.size.height / 3)}, false};
}
};
GAPI_OCV_KERNEL(GCPUYUV2Gray, GYUV2Gray)
{
static void run(const cv::Mat& in, cv::Mat& out)
{
cv::cvtColor(in, out, cv::COLOR_YUV2GRAY_NV12);
}
};
G_TYPED_KERNEL(GConcatYUVPlanes, <cv::GMat(cv::GMat, cv::GMat)>, "concatyuvplanes") {
static cv::GMatDesc outMeta(cv::GMatDesc y, cv::GMatDesc uv) {
return {CV_8U, 1, cv::gapi::own::Size{y.size.width, y.size.height + uv.size.height}, false};
}
};
GAPI_OCV_KERNEL(GCPUConcatYUVPlanes, GConcatYUVPlanes)
{
static void run(const cv::Mat& in_y, const cv::Mat& in_uv, cv::Mat& out)
{
cv::Mat uv_planar(in_uv.rows, in_uv.cols * 2, CV_8UC1, in_uv.data);
cv::vconcat(in_y, uv_planar, out);
}
};
GAPI_COMPOUND_KERNEL(GCPUNV12toGray, cv::gapi::imgproc::GNV12toGray)
{
static cv::GMat expand(cv::GMat y, cv::GMat uv)
{
return GYUV2Gray::on(GConcatYUVPlanes::on(y, uv));
}
};
GAPI_OCV_KERNEL(GCPUNV12toBGRp, cv::gapi::imgproc::GNV12toBGRp)
{
static void run(const cv::Mat& inY, const cv::Mat& inUV, cv::Mat& out)
@@ -345,7 +398,6 @@ GAPI_OCV_KERNEL(GCPUNV12toBGRp, cv::gapi::imgproc::GNV12toBGRp)
}
};
cv::gapi::GKernelPackage cv::gapi::imgproc::cpu::kernels()
{
static auto pkg = cv::gapi::kernels
@@ -376,8 +428,11 @@ cv::gapi::GKernelPackage cv::gapi::imgproc::cpu::kernels()
, GCPUBayerGR2RGB
, GCPURGB2HSV
, GCPURGB2YUV422
, GCPUYUV2Gray
, GCPUNV12toRGBp
, GCPUNV12toBGRp
, GCPUNV12toGray
, GCPUConcatYUVPlanes
>();
return pkg;
}