Merge pull request #14700 from TolyaTalamanov:at/cv_gapi_render
G-API: Render (#14700) * cv::Render Implement OCVRedner for BGR as input * Support two plane cv::Render::run * Snapshot * Add RenderCreator * text2Points * Snapshot * Refactoring tests * Remove text2points * Fix render input data type in tests * Refactoring * Fix headers * Change struct fields name * Fix headers * Fix warnings * Replace cv::Scalar -> cv::gapi::own::Scalar * Add test * PutText and rectangle case * Fix comments to review * Fix comments to review * Fix comments to review * Create render_priv.hpp * Implement BGR2NV12 * Fix NV12 test * Fix comments to review * Add header for GAPI_Assert
This commit is contained in:
committed by
Alexander Alekhin
parent
cf9bddcb89
commit
d3c0f4ef98
@@ -0,0 +1,77 @@
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include "opencv2/gapi/render.hpp"
|
||||
#include "opencv2/gapi/own/assert.hpp"
|
||||
|
||||
#include "api/render_priv.hpp"
|
||||
|
||||
using namespace cv::gapi::wip::draw;
|
||||
// FXIME util::visitor ?
|
||||
void cv::gapi::wip::draw::render(cv::Mat& bgr, const Prims& prims)
|
||||
{
|
||||
for (const auto& p : prims)
|
||||
{
|
||||
switch (p.index())
|
||||
{
|
||||
case Prim::index_of<Rect>():
|
||||
{
|
||||
auto t_p = cv::util::get<Rect>(p);
|
||||
cv::rectangle(bgr, t_p.rect, t_p.color , t_p.thick, t_p.lt, t_p.shift);
|
||||
break;
|
||||
}
|
||||
|
||||
case Prim::index_of<Text>():
|
||||
{
|
||||
auto t_p = cv::util::get<Text>(p);
|
||||
cv::putText(bgr, t_p.text, t_p.org, t_p.ff, t_p.fs,
|
||||
t_p.color, t_p.thick, t_p.bottom_left_origin);
|
||||
break;
|
||||
}
|
||||
|
||||
default: util::throw_error(std::logic_error("Unsupported draw event"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cv::gapi::wip::draw::render(cv::Mat& y_plane, cv::Mat& uv_plane , const Prims& prims)
|
||||
{
|
||||
cv::Mat bgr;
|
||||
cv::cvtColorTwoPlane(y_plane, uv_plane, bgr, cv::COLOR_YUV2BGR_NV12);
|
||||
render(bgr, prims);
|
||||
BGR2NV12(bgr, y_plane, uv_plane);
|
||||
}
|
||||
|
||||
void cv::gapi::wip::draw::splitNV12TwoPlane(const cv::Mat& yuv, cv::Mat& y_plane, cv::Mat& uv_plane) {
|
||||
y_plane.create(yuv.size(), CV_8UC1);
|
||||
uv_plane.create(yuv.size() / 2, CV_8UC2);
|
||||
|
||||
// Fill Y plane
|
||||
for (int i = 0; i < yuv.rows; ++i)
|
||||
{
|
||||
const uchar* in = yuv.ptr<uchar>(i);
|
||||
uchar* out = y_plane.ptr<uchar>(i);
|
||||
for (int j = 0; j < yuv.cols; j++) {
|
||||
out[j] = in[3 * j];
|
||||
}
|
||||
}
|
||||
|
||||
// Fill UV plane
|
||||
for (int i = 0; i < uv_plane.rows; i++)
|
||||
{
|
||||
const uchar* in = yuv.ptr<uchar>(2 * i);
|
||||
uchar* out = uv_plane.ptr<uchar>(i);
|
||||
for (int j = 0; j < uv_plane.cols; j++) {
|
||||
out[j * 2 ] = in[6 * j + 1];
|
||||
out[j * 2 + 1] = in[6 * j + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cv::gapi::wip::draw::BGR2NV12(const cv::Mat& bgr, cv::Mat& y_plane, cv::Mat& uv_plane)
|
||||
{
|
||||
GAPI_Assert(bgr.size().width % 2 == 0);
|
||||
GAPI_Assert(bgr.size().height % 2 == 0);
|
||||
|
||||
cvtColor(bgr, bgr, cv::COLOR_BGR2YUV);
|
||||
splitNV12TwoPlane(bgr, y_plane, uv_plane);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
//
|
||||
// Copyright (C) 2018 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_RENDER_PRIV_HPP
|
||||
#define OPENCV_RENDER_PRIV_HPP
|
||||
|
||||
#include <opencv2/gapi/render.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace gapi
|
||||
{
|
||||
namespace wip
|
||||
{
|
||||
namespace draw
|
||||
{
|
||||
// FIXME only for tests
|
||||
GAPI_EXPORTS void BGR2NV12(const cv::Mat& bgr, cv::Mat& y_plane, cv::Mat& uv_plane);
|
||||
void splitNV12TwoPlane(const cv::Mat& yuv, cv::Mat& y_plane, cv::Mat& uv_plane);
|
||||
|
||||
} // namespace draw
|
||||
} // namespace wip
|
||||
} // namespace gapi
|
||||
} // namespace cv
|
||||
|
||||
#endif // OPENCV_RENDER_PRIV_HPP
|
||||
Reference in New Issue
Block a user