Merge pull request #15699 from TolyaTalamanov:at/graph-ocv-render-backend-skeleton
G-API: Implement OpenCV render backend * Implement render opencv backend * Fix comment to review * Add comment * Add wrappers for kernels * Fix comments to review * Fix comment to review
This commit is contained in:
committed by
Alexander Alekhin
parent
cc9b199ecb
commit
2ff12c4981
@@ -1,34 +1,33 @@
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/gapi/render.hpp>
|
||||
#include <opencv2/gapi/render/render.hpp>
|
||||
#include <opencv2/gapi/own/assert.hpp>
|
||||
|
||||
#include "api/render_priv.hpp"
|
||||
|
||||
void cv::gapi::wip::draw::render(cv::Mat &bgr,
|
||||
const cv::gapi::wip::draw::Prims &prims,
|
||||
const cv::gapi::GKernelPackage& pkg)
|
||||
cv::GCompileArgs&& args)
|
||||
{
|
||||
cv::GMat in;
|
||||
cv::GArray<Prim> arr;
|
||||
|
||||
cv::GComputation comp(cv::GIn(in, arr),
|
||||
cv::GOut(cv::gapi::wip::draw::GRenderBGR::on(in, arr)));
|
||||
comp.apply(cv::gin(bgr, prims), cv::gout(bgr), cv::compile_args(pkg));
|
||||
cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
|
||||
comp.apply(cv::gin(bgr, prims), cv::gout(bgr), std::move(args));
|
||||
}
|
||||
|
||||
void cv::gapi::wip::draw::render(cv::Mat &y_plane,
|
||||
cv::Mat &uv_plane,
|
||||
const Prims &prims,
|
||||
const GKernelPackage& pkg)
|
||||
cv::GCompileArgs&& args)
|
||||
{
|
||||
cv::GMat y_in, uv_in, y_out, uv_out;
|
||||
cv::GArray<Prim> arr;
|
||||
std::tie(y_out, uv_out) = cv::gapi::wip::draw::GRenderNV12::on(y_in, uv_in, arr);
|
||||
std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
|
||||
|
||||
cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
|
||||
comp.apply(cv::gin(y_plane, uv_plane, prims),
|
||||
cv::gout(y_plane, uv_plane),
|
||||
cv::compile_args(pkg));
|
||||
cv::gout(y_plane, uv_plane), std::move(args));
|
||||
}
|
||||
|
||||
void cv::gapi::wip::draw::BGR2NV12(const cv::Mat &bgr,
|
||||
@@ -48,3 +47,28 @@ void cv::gapi::wip::draw::BGR2NV12(const cv::Mat &bgr,
|
||||
cv::merge(std::vector<cv::Mat>{chs[1], chs[2]}, uv_plane);
|
||||
cv::resize(uv_plane, uv_plane, uv_plane.size() / 2, cv::INTER_LINEAR);
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<> struct CompileArgTag<cv::gapi::wip::draw::use_freetype>
|
||||
{
|
||||
static const char* tag() { return "gapi.use_freetype"; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
GMat cv::gapi::wip::draw::render3ch(const GMat& src, const GArray<Prim>& prims)
|
||||
{
|
||||
return cv::gapi::wip::draw::GRenderBGR::on(src, prims);
|
||||
}
|
||||
|
||||
std::tuple<GMat, GMat> cv::gapi::wip::draw::renderNV12(const GMat& y,
|
||||
const GMat& uv,
|
||||
const GArray<cv::gapi::wip::draw::Prim>& prims)
|
||||
{
|
||||
return cv::gapi::wip::draw::GRenderNV12::on(y, uv, prims);
|
||||
}
|
||||
|
||||
} // namespace cv
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <opencv2/gapi/cpu/gcpukernel.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/gapi/render.hpp> // Kernel API's
|
||||
#include <opencv2/gapi/render/render.hpp> // Kernel API's
|
||||
|
||||
#include "api/render_ocv.hpp"
|
||||
|
||||
@@ -11,61 +10,6 @@ namespace gapi
|
||||
|
||||
namespace ocv
|
||||
{
|
||||
|
||||
GAPI_OCV_KERNEL(GOCVRenderNV12, cv::gapi::wip::draw::GRenderNV12)
|
||||
{
|
||||
static void run(const cv::Mat& y, const cv::Mat& uv, const cv::gapi::wip::draw::Prims& prims,
|
||||
cv::Mat& out_y, cv::Mat& out_uv)
|
||||
{
|
||||
/* FIXME How to render correctly on NV12 format ?
|
||||
*
|
||||
* Rendering on NV12 via OpenCV looks like this:
|
||||
*
|
||||
* y --------> 1)(NV12 -> YUV) -> yuv -> 2)draw -> yuv -> 3)split -------> out_y
|
||||
* ^ |
|
||||
* | |
|
||||
* uv -------------- `----------> out_uv
|
||||
*
|
||||
*
|
||||
* 1) Collect yuv mat from two planes, uv plain in two times less than y plane
|
||||
* so, upsample uv in tow times, with bilinear interpolation
|
||||
*
|
||||
* 2) Render primitives on YUV
|
||||
*
|
||||
* 3) Convert yuv to NV12 (using bilinear interpolation)
|
||||
*
|
||||
*/
|
||||
|
||||
// NV12 -> YUV
|
||||
cv::Mat upsample_uv, yuv;
|
||||
cv::resize(uv, upsample_uv, uv.size() * 2, cv::INTER_LINEAR);
|
||||
cv::merge(std::vector<cv::Mat>{y, upsample_uv}, yuv);
|
||||
|
||||
cv::gapi::wip::draw::drawPrimitivesOCVYUV(yuv, prims);
|
||||
|
||||
// YUV -> NV12
|
||||
cv::Mat out_u, out_v, uv_plane;
|
||||
std::vector<cv::Mat> chs = {out_y, out_u, out_v};
|
||||
cv::split(yuv, chs);
|
||||
cv::merge(std::vector<cv::Mat>{chs[1], chs[2]}, uv_plane);
|
||||
cv::resize(uv_plane, out_uv, uv_plane.size() / 2, cv::INTER_LINEAR);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(GOCVRenderBGR, cv::gapi::wip::draw::GRenderBGR)
|
||||
{
|
||||
static void run(const cv::Mat&, const cv::gapi::wip::draw::Prims& prims, cv::Mat& out)
|
||||
{
|
||||
cv::gapi::wip::draw::drawPrimitivesOCVBGR(out, prims);
|
||||
}
|
||||
};
|
||||
|
||||
cv::gapi::GKernelPackage kernels()
|
||||
{
|
||||
static const auto pkg = cv::gapi::kernels<GOCVRenderNV12, GOCVRenderBGR>();
|
||||
return pkg;
|
||||
}
|
||||
|
||||
} // namespace ocv
|
||||
|
||||
namespace wip
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef OPENCV_RENDER_PRIV_HPP
|
||||
#define OPENCV_RENDER_PRIV_HPP
|
||||
|
||||
#include <opencv2/gapi/render.hpp>
|
||||
#include <opencv2/gapi/render/render.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user