Merge pull request #15751 from TolyaTalamanov:at/refactor-render-tests
* Refactor render tests * Fix comment to review * Move ocv render tests stuff to specific file * Add OCV prefix for render tests * Fix comments to review
This commit is contained in:
committed by
Alexander Alekhin
parent
ea5499fa51
commit
ea64bb58a5
@@ -4,8 +4,8 @@
|
||||
|
||||
#include "api/render_priv.hpp"
|
||||
|
||||
void cv::gapi::wip::draw::render(cv::Mat &bgr,
|
||||
const cv::gapi::wip::draw::Prims &prims,
|
||||
void cv::gapi::wip::draw::render(cv::Mat& bgr,
|
||||
const cv::gapi::wip::draw::Prims& prims,
|
||||
cv::GCompileArgs&& args)
|
||||
{
|
||||
cv::GMat in;
|
||||
@@ -16,9 +16,9 @@ void cv::gapi::wip::draw::render(cv::Mat &bgr,
|
||||
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,
|
||||
void cv::gapi::wip::draw::render(cv::Mat& y_plane,
|
||||
cv::Mat& uv_plane,
|
||||
const Prims& prims,
|
||||
cv::GCompileArgs&& args)
|
||||
{
|
||||
cv::GMat y_in, uv_in, y_out, uv_out;
|
||||
@@ -30,22 +30,28 @@ void cv::gapi::wip::draw::render(cv::Mat &y_plane,
|
||||
cv::gout(y_plane, uv_plane), std::move(args));
|
||||
}
|
||||
|
||||
void cv::gapi::wip::draw::BGR2NV12(const cv::Mat &bgr,
|
||||
cv::Mat &y_plane,
|
||||
cv::Mat &uv_plane)
|
||||
void cv::gapi::wip::draw::cvtYUVToNV12(const cv::Mat& yuv,
|
||||
cv::Mat& y,
|
||||
cv::Mat& uv)
|
||||
{
|
||||
GAPI_Assert(bgr.size().width % 2 == 0);
|
||||
GAPI_Assert(bgr.size().height % 2 == 0);
|
||||
|
||||
cv::Mat yuv;
|
||||
cvtColor(bgr, yuv, cv::COLOR_BGR2YUV);
|
||||
GAPI_Assert(yuv.size().width % 2 == 0);
|
||||
GAPI_Assert(yuv.size().height % 2 == 0);
|
||||
|
||||
std::vector<cv::Mat> chs(3);
|
||||
cv::split(yuv, chs);
|
||||
y_plane = chs[0];
|
||||
y = chs[0];
|
||||
|
||||
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);
|
||||
cv::merge(std::vector<cv::Mat>{chs[1], chs[2]}, uv);
|
||||
cv::resize(uv, uv, uv.size() / 2, cv::INTER_LINEAR);
|
||||
}
|
||||
|
||||
void cv::gapi::wip::draw::cvtNV12ToYUV(const cv::Mat& y,
|
||||
const cv::Mat& uv,
|
||||
cv::Mat& yuv)
|
||||
{
|
||||
cv::Mat upsample_uv;
|
||||
cv::resize(uv, upsample_uv, uv.size() * 2, cv::INTER_LINEAR);
|
||||
cv::merge(std::vector<cv::Mat>{y, upsample_uv}, yuv);
|
||||
}
|
||||
|
||||
namespace cv
|
||||
|
||||
@@ -7,37 +7,32 @@ namespace cv
|
||||
{
|
||||
namespace gapi
|
||||
{
|
||||
|
||||
namespace ocv
|
||||
{
|
||||
} // namespace ocv
|
||||
|
||||
namespace wip
|
||||
{
|
||||
namespace draw
|
||||
{
|
||||
|
||||
void mosaic(cv::Mat mat, const cv::Rect &rect, int cellSz);
|
||||
void image(cv::Mat mat, cv::Point org, cv::Mat img, cv::Mat alpha);
|
||||
void poly(cv::Mat mat, std::vector<cv::Point>, cv::Scalar color, int lt, int shift);
|
||||
|
||||
void mosaic(cv::Mat mat, const cv::Rect &rect, int cellSz)
|
||||
// FIXME Support `decim` mosaic parameter
|
||||
inline void mosaic(cv::Mat& mat, const cv::Rect &rect, int cellSz)
|
||||
{
|
||||
cv::Mat msc_roi = mat(rect);
|
||||
int crop_x = msc_roi.cols - msc_roi.cols % cellSz;
|
||||
int crop_y = msc_roi.rows - msc_roi.rows % cellSz;
|
||||
|
||||
for(int i = 0; i < crop_y; i += cellSz )
|
||||
for(int i = 0; i < crop_y; i += cellSz ) {
|
||||
for(int j = 0; j < crop_x; j += cellSz) {
|
||||
auto cell_roi = msc_roi(cv::Rect(j, i, cellSz, cellSz));
|
||||
cell_roi = cv::mean(cell_roi);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void image(cv::Mat mat, cv::Point org, cv::Mat img, cv::Mat alpha)
|
||||
inline void image(cv::Mat& mat,
|
||||
const cv::Point& org,
|
||||
const cv::Mat& img,
|
||||
const cv::Mat& alpha)
|
||||
{
|
||||
auto roi = mat(cv::Rect(org.x, org.y, img.size().width, img.size().height));
|
||||
auto roi = mat(cv::Rect(org, img.size()));
|
||||
cv::Mat img32f_w;
|
||||
cv::merge(std::vector<cv::Mat>(3, alpha), img32f_w);
|
||||
|
||||
@@ -45,6 +40,7 @@ void image(cv::Mat mat, cv::Point org, cv::Mat img, cv::Mat alpha)
|
||||
roi32f_w -= img32f_w;
|
||||
|
||||
cv::Mat img32f, roi32f;
|
||||
|
||||
img.convertTo(img32f, CV_32F, 1.0/255);
|
||||
roi.convertTo(roi32f, CV_32F, 1.0/255);
|
||||
|
||||
@@ -55,10 +51,11 @@ void image(cv::Mat mat, cv::Point org, cv::Mat img, cv::Mat alpha)
|
||||
roi32f.convertTo(roi, CV_8U, 255.0);
|
||||
};
|
||||
|
||||
void poly(cv::Mat mat, std::vector<cv::Point> points, cv::Scalar color, int lt, int shift)
|
||||
inline void poly(cv::Mat& mat,
|
||||
const cv::gapi::wip::draw::Poly& pp)
|
||||
{
|
||||
std::vector<std::vector<cv::Point>> pp{points};
|
||||
cv::fillPoly(mat, pp, color, lt, shift);
|
||||
std::vector<std::vector<cv::Point>> points{pp.points};
|
||||
cv::fillPoly(mat, points, pp.color, pp.lt, pp.shift);
|
||||
};
|
||||
|
||||
struct BGR2YUVConverter
|
||||
@@ -92,60 +89,60 @@ void drawPrimitivesOCV(cv::Mat &in, const Prims &prims)
|
||||
{
|
||||
case Prim::index_of<Rect>():
|
||||
{
|
||||
const auto& t_p = cv::util::get<Rect>(p);
|
||||
const auto color = converter.cvtColor(t_p.color);
|
||||
cv::rectangle(in, t_p.rect, color , t_p.thick, t_p.lt, t_p.shift);
|
||||
const auto& rp = cv::util::get<Rect>(p);
|
||||
const auto color = converter.cvtColor(rp.color);
|
||||
cv::rectangle(in, rp.rect, color , rp.thick);
|
||||
break;
|
||||
}
|
||||
|
||||
case Prim::index_of<Text>():
|
||||
{
|
||||
const auto& t_p = cv::util::get<Text>(p);
|
||||
const auto color = converter.cvtColor(t_p.color);
|
||||
cv::putText(in, t_p.text, t_p.org, t_p.ff, t_p.fs,
|
||||
color, t_p.thick, t_p.lt, t_p.bottom_left_origin);
|
||||
const auto& tp = cv::util::get<Text>(p);
|
||||
const auto color = converter.cvtColor(tp.color);
|
||||
cv::putText(in, tp.text, tp.org, tp.ff, tp.fs, color, tp.thick, tp.lt, tp.bottom_left_origin);
|
||||
break;
|
||||
}
|
||||
|
||||
case Prim::index_of<Circle>():
|
||||
{
|
||||
const auto& c_p = cv::util::get<Circle>(p);
|
||||
const auto color = converter.cvtColor(c_p.color);
|
||||
cv::circle(in, c_p.center, c_p.radius, color, c_p.thick, c_p.lt, c_p.shift);
|
||||
const auto& cp = cv::util::get<Circle>(p);
|
||||
const auto color = converter.cvtColor(cp.color);
|
||||
cv::circle(in, cp.center, cp.radius, color, cp.thick);
|
||||
break;
|
||||
}
|
||||
|
||||
case Prim::index_of<Line>():
|
||||
{
|
||||
const auto& l_p = cv::util::get<Line>(p);
|
||||
const auto color = converter.cvtColor(l_p.color);
|
||||
cv::line(in, l_p.pt1, l_p.pt2, color, l_p.thick, l_p.lt, l_p.shift);
|
||||
const auto& lp = cv::util::get<Line>(p);
|
||||
const auto color = converter.cvtColor(lp.color);
|
||||
cv::line(in, lp.pt1, lp.pt2, color, lp.thick);
|
||||
break;
|
||||
}
|
||||
|
||||
case Prim::index_of<Mosaic>():
|
||||
{
|
||||
const auto& l_p = cv::util::get<Mosaic>(p);
|
||||
mosaic(in, l_p.mos, l_p.cellSz);
|
||||
const auto& mp = cv::util::get<Mosaic>(p);
|
||||
GAPI_Assert(mp.decim == 0 && "Only decim = 0 supported now");
|
||||
mosaic(in, mp.mos, mp.cellSz);
|
||||
break;
|
||||
}
|
||||
|
||||
case Prim::index_of<Image>():
|
||||
{
|
||||
const auto& i_p = cv::util::get<Image>(p);
|
||||
const auto& ip = cv::util::get<Image>(p);
|
||||
|
||||
cv::Mat img;
|
||||
converter.cvtImg(i_p.img, img);
|
||||
converter.cvtImg(ip.img, img);
|
||||
|
||||
image(in, i_p.org, img, i_p.alpha);
|
||||
image(in, ip.org, img, ip.alpha);
|
||||
break;
|
||||
}
|
||||
|
||||
case Prim::index_of<Poly>():
|
||||
{
|
||||
const auto& p_p = cv::util::get<Poly>(p);
|
||||
const auto color = converter.cvtColor(p_p.color);
|
||||
poly(in, p_p.points, color, p_p.lt, p_p.shift);
|
||||
auto pp = cv::util::get<Poly>(p);
|
||||
pp.color = converter.cvtColor(pp.color);
|
||||
poly(in, pp);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ namespace draw
|
||||
{
|
||||
|
||||
// FIXME only for tests
|
||||
GAPI_EXPORTS void BGR2NV12(const cv::Mat& bgr, cv::Mat& y_plane, cv::Mat& uv_plane);
|
||||
GAPI_EXPORTS void cvtNV12ToYUV(const cv::Mat& y, const cv::Mat& uv, cv::Mat& yuv);
|
||||
GAPI_EXPORTS void cvtYUVToNV12(const cv::Mat& yuv, cv::Mat& y, cv::Mat& uv);
|
||||
|
||||
} // namespace draw
|
||||
} // namespace wip
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <opencv2/gapi/cpu/gcpukernel.hpp>
|
||||
|
||||
GAPI_RENDER_OCV_KERNEL(RenderBGRImpl, cv::gapi::wip::draw::GRenderBGR)
|
||||
GAPI_RENDER_OCV_KERNEL(RenderBGROCVImpl, cv::gapi::wip::draw::GRenderBGR)
|
||||
{
|
||||
static void run(const cv::Mat& in, const cv::gapi::wip::draw::Prims& prims, cv::Mat& out)
|
||||
{
|
||||
@@ -20,7 +20,7 @@ GAPI_RENDER_OCV_KERNEL(RenderBGRImpl, cv::gapi::wip::draw::GRenderBGR)
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_RENDER_OCV_KERNEL(RenderNV12Impl, cv::gapi::wip::draw::GRenderNV12)
|
||||
GAPI_RENDER_OCV_KERNEL(RenderNV12OCVImpl, cv::gapi::wip::draw::GRenderNV12)
|
||||
{
|
||||
static void run(const cv::Mat& in_y,
|
||||
const cv::Mat& in_uv,
|
||||
@@ -76,6 +76,6 @@ GAPI_RENDER_OCV_KERNEL(RenderNV12Impl, cv::gapi::wip::draw::GRenderNV12)
|
||||
|
||||
cv::gapi::GKernelPackage cv::gapi::render::ocv::kernels()
|
||||
{
|
||||
const static auto pkg = cv::gapi::kernels<RenderBGRImpl, RenderNV12Impl>();
|
||||
const static auto pkg = cv::gapi::kernels<RenderBGROCVImpl, RenderNV12OCVImpl>();
|
||||
return pkg;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,6 @@ namespace {
|
||||
const ade::NodeHandle &op_node,
|
||||
const cv::GKernelImpl &impl) override {
|
||||
GRenderModel rm(gr);
|
||||
//auto render_impl = cv::util::any_cast<cv::gapi::render::ocv::KImpl>(impl.opaque);
|
||||
auto render_impl = cv::util::any_cast<cv::GCPUKernel>(impl.opaque);
|
||||
rm.metadata(op_node).set(cv::gimpl::render::ocv::RenderUnit{render_impl});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user