#ifndef OPENCV_GAPI_RENDER_HPP
#define OPENCV_GAPI_RENDER_HPP
#include <string>
#include <vector>
#include <opencv2/imgproc.hpp>
#include <opencv2/gapi.hpp>
#include <opencv2/gapi/opencv_includes.hpp>
#include <opencv2/gapi/util/variant.hpp>
#include <opencv2/gapi/own/exports.hpp>
#include <opencv2/gapi/own/scalar.hpp>
namespace cv
{
namespace gapi
{
namespace wip
{
namespace draw
{
struct freetype_font
{
std::string path;
};
struct Text
{
Text(const std::string& text_,
const cv::Point& org_,
int ff_,
double fs_,
const cv::Scalar& color_,
int thick_ = 1,
int lt_ = cv::LINE_8,
bool bottom_left_origin_ = false) :
text(text_), org(org_), ff(ff_), fs(fs_),
color(color_), thick(thick_), lt(lt_), bottom_left_origin(bottom_left_origin_)
{
}
std::string text; cv::Point org; int ff; double fs; cv::Scalar color; int thick; int lt; bool bottom_left_origin;
};
struct FText
{
FText(const std::wstring& text_,
const cv::Point& org_,
int fh_,
const cv::Scalar& color_) :
text(text_), org(org_), fh(fh_), color(color_)
{
}
std::wstring text; cv::Point org; int fh; cv::Scalar color;
};
struct Rect
{
Rect(const cv::Rect& rect_,
const cv::Scalar& color_,
int thick_ = 1,
int lt_ = cv::LINE_8,
int shift_ = 0) :
rect(rect_), color(color_), thick(thick_), lt(lt_), shift(shift_)
{
}
cv::Rect rect; cv::Scalar color; int thick; int lt; int shift;
};
struct Circle
{
Circle(const cv::Point& center_,
int radius_,
const cv::Scalar& color_,
int thick_ = 1,
int lt_ = cv::LINE_8,
int shift_ = 0) :
center(center_), radius(radius_), color(color_), thick(thick_), lt(lt_), shift(shift_)
{
}
cv::Point center; int radius; cv::Scalar color; int thick; int lt; int shift;
};
struct Line
{
Line(const cv::Point& pt1_,
const cv::Point& pt2_,
const cv::Scalar& color_,
int thick_ = 1,
int lt_ = cv::LINE_8,
int shift_ = 0) :
pt1(pt1_), pt2(pt2_), color(color_), thick(thick_), lt(lt_), shift(shift_)
{
}
cv::Point pt1; cv::Point pt2; cv::Scalar color; int thick; int lt; int shift;
};
struct Mosaic
{
Mosaic(const cv::Rect& mos_,
int cellSz_,
int decim_) :
mos(mos_), cellSz(cellSz_), decim(decim_)
{
}
cv::Rect mos; int cellSz; int decim;
};
struct Image
{
Image(const cv::Point& org_,
const cv::Mat& img_,
const cv::Mat& alpha_) :
org(org_), img(img_), alpha(alpha_)
{
}
cv::Point org; cv::Mat img; cv::Mat alpha;
};
struct Poly
{
Poly(const std::vector<cv::Point>& points_,
const cv::Scalar& color_,
int thick_ = 1,
int lt_ = cv::LINE_8,
int shift_ = 0) :
points(points_), color(color_), thick(thick_), lt(lt_), shift(shift_)
{
}
std::vector<cv::Point> points; cv::Scalar color; int thick; int lt; int shift;
};
using Prim = util::variant
< Text
, FText
, Rect
, Circle
, Line
, Mosaic
, Image
, Poly
>;
using Prims = std::vector<Prim>;
using GMat2 = std::tuple<cv::GMat,cv::GMat>;
using GMatDesc2 = std::tuple<cv::GMatDesc,cv::GMatDesc>;
void GAPI_EXPORTS render(cv::Mat& bgr,
const Prims& prims,
cv::GCompileArgs&& args = {});
void GAPI_EXPORTS render(cv::Mat& y_plane,
cv::Mat& uv_plane,
const Prims& prims,
cv::GCompileArgs&& args = {});
G_TYPED_KERNEL_M(GRenderNV12, <GMat2(cv::GMat,cv::GMat,cv::GArray<wip::draw::Prim>)>, "org.opencv.render.nv12")
{
static GMatDesc2 outMeta(GMatDesc y_plane, GMatDesc uv_plane, GArrayDesc)
{
return std::make_tuple(y_plane, uv_plane);
}
};
G_TYPED_KERNEL(GRenderBGR, <cv::GMat(cv::GMat,cv::GArray<wip::draw::Prim>)>, "org.opencv.render.bgr")
{
static GMatDesc outMeta(GMatDesc bgr, GArrayDesc)
{
return bgr;
}
};
GAPI_EXPORTS GMat render3ch(const GMat& src, const GArray<Prim>& prims);
GAPI_EXPORTS GMat2 renderNV12(const GMat& y,
const GMat& uv,
const GArray<Prim>& prims);
} }
namespace render
{
namespace ocv
{
GAPI_EXPORTS cv::gapi::GKernelPackage kernels();
} } }
namespace detail
{
template<> struct CompileArgTag<cv::gapi::wip::draw::freetype_font>
{
static const char* tag() { return "gapi.freetype_font"; }
};
}
}
#endif