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

Merge pull request #20284 from TolyaTalamanov:at/wrap-render

G-API: Wrap render functionality to python

* Wrap render Rect prim

* Add all primitives and tests

* Cover mosaic and image

* Handle error in pyopencv_to(Prim)

* Move Mosaic and Rect ctors wrappers to shadow file

* Use GAPI_PROP_RW

* Fix indent
This commit is contained in:
Anatoliy Talamanov
2021-07-01 12:36:19 +03:00
committed by GitHub
parent bf489feef1
commit 9fe49497bb
11 changed files with 512 additions and 165 deletions
@@ -13,11 +13,13 @@
# define GAPI_EXPORTS CV_EXPORTS
/* special informative macros for wrapper generators */
# define GAPI_PROP CV_PROP
# define GAPI_PROP_RW CV_PROP_RW
# define GAPI_WRAP CV_WRAP
# define GAPI_EXPORTS_W_SIMPLE CV_EXPORTS_W_SIMPLE
# define GAPI_EXPORTS_W CV_EXPORTS_W
# else
# define GAPI_PROP
# define GAPI_PROP_RW
# define GAPI_WRAP
# define GAPI_EXPORTS
# define GAPI_EXPORTS_W_SIMPLE
@@ -81,9 +81,9 @@ using GMatDesc2 = std::tuple<cv::GMatDesc,cv::GMatDesc>;
@param prims vector of drawing primitivies
@param args graph compile time parameters
*/
void GAPI_EXPORTS render(cv::Mat& bgr,
const Prims& prims,
cv::GCompileArgs&& args = {});
void GAPI_EXPORTS_W render(cv::Mat& bgr,
const Prims& prims,
cv::GCompileArgs&& args = {});
/** @brief The function renders on two NV12 planes passed drawing primitivies
@@ -92,10 +92,10 @@ void GAPI_EXPORTS render(cv::Mat& bgr,
@param prims vector of drawing primitivies
@param args graph compile time parameters
*/
void GAPI_EXPORTS render(cv::Mat& y_plane,
cv::Mat& uv_plane,
const Prims& prims,
cv::GCompileArgs&& args = {});
void GAPI_EXPORTS_W render(cv::Mat& y_plane,
cv::Mat& uv_plane,
const Prims& prims,
cv::GCompileArgs&& args = {});
/** @brief The function renders on the input media frame passed drawing primitivies
@@ -139,7 +139,7 @@ Output image must be 8-bit unsigned planar 3-channel image
@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3
@param prims draw primitives
*/
GAPI_EXPORTS GMat render3ch(const GMat& src, const GArray<Prim>& prims);
GAPI_EXPORTS_W GMat render3ch(const GMat& src, const GArray<Prim>& prims);
/** @brief Renders on two planes
@@ -150,9 +150,9 @@ uv image must be 8-bit unsigned planar 2-channel image @ref CV_8UC2
@param uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2
@param prims draw primitives
*/
GAPI_EXPORTS GMat2 renderNV12(const GMat& y,
const GMat& uv,
const GArray<Prim>& prims);
GAPI_EXPORTS_W GMat2 renderNV12(const GMat& y,
const GMat& uv,
const GArray<Prim>& prims);
/** @brief Renders Media Frame
@@ -177,7 +177,7 @@ namespace render
{
namespace ocv
{
GAPI_EXPORTS cv::gapi::GKernelPackage kernels();
GAPI_EXPORTS_W cv::gapi::GKernelPackage kernels();
} // namespace ocv
} // namespace render
@@ -41,7 +41,7 @@ struct freetype_font
*
* Parameters match cv::putText().
*/
struct Text
struct GAPI_EXPORTS_W_SIMPLE Text
{
/**
* @brief Text constructor
@@ -55,6 +55,7 @@ struct Text
* @param lt_ The line type. See #LineTypes
* @param bottom_left_origin_ When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner
*/
GAPI_WRAP
Text(const std::string& text_,
const cv::Point& org_,
int ff_,
@@ -68,17 +69,18 @@ struct Text
{
}
GAPI_WRAP
Text() = default;
/*@{*/
std::string text; //!< The text string to be drawn
cv::Point org; //!< The bottom-left corner of the text string in the image
int ff; //!< The font type, see #HersheyFonts
double fs; //!< The font scale factor that is multiplied by the font-specific base size
cv::Scalar color; //!< The text color
int thick; //!< The thickness of the lines used to draw a text
int lt; //!< The line type. See #LineTypes
bool bottom_left_origin; //!< When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner
GAPI_PROP_RW std::string text; //!< The text string to be drawn
GAPI_PROP_RW cv::Point org; //!< The bottom-left corner of the text string in the image
GAPI_PROP_RW int ff; //!< The font type, see #HersheyFonts
GAPI_PROP_RW double fs; //!< The font scale factor that is multiplied by the font-specific base size
GAPI_PROP_RW cv::Scalar color; //!< The text color
GAPI_PROP_RW int thick; //!< The thickness of the lines used to draw a text
GAPI_PROP_RW int lt; //!< The line type. See #LineTypes
GAPI_PROP_RW bool bottom_left_origin; //!< When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner
/*@{*/
};
@@ -122,7 +124,7 @@ struct FText
*
* Parameters match cv::rectangle().
*/
struct Rect
struct GAPI_EXPORTS_W_SIMPLE Rect
{
/**
* @brief Rect constructor
@@ -142,14 +144,15 @@ struct Rect
{
}
GAPI_WRAP
Rect() = default;
/*@{*/
cv::Rect rect; //!< Coordinates of the rectangle
cv::Scalar color; //!< The rectangle color or brightness (grayscale image)
int thick; //!< The thickness of lines that make up the rectangle. Negative values, like #FILLED, mean that the function has to draw a filled rectangle
int lt; //!< The type of the line. See #LineTypes
int shift; //!< The number of fractional bits in the point coordinates
GAPI_PROP_RW cv::Rect rect; //!< Coordinates of the rectangle
GAPI_PROP_RW cv::Scalar color; //!< The rectangle color or brightness (grayscale image)
GAPI_PROP_RW int thick; //!< The thickness of lines that make up the rectangle. Negative values, like #FILLED, mean that the function has to draw a filled rectangle
GAPI_PROP_RW int lt; //!< The type of the line. See #LineTypes
GAPI_PROP_RW int shift; //!< The number of fractional bits in the point coordinates
/*@{*/
};
@@ -158,7 +161,7 @@ struct Rect
*
* Parameters match cv::circle().
*/
struct Circle
struct GAPI_EXPORTS_W_SIMPLE Circle
{
/**
* @brief Circle constructor
@@ -170,6 +173,7 @@ struct Circle
* @param lt_ The Type of the circle boundary. See #LineTypes
* @param shift_ The Number of fractional bits in the coordinates of the center and in the radius value
*/
GAPI_WRAP
Circle(const cv::Point& center_,
int radius_,
const cv::Scalar& color_,
@@ -180,15 +184,16 @@ struct Circle
{
}
GAPI_WRAP
Circle() = default;
/*@{*/
cv::Point center; //!< The center of the circle
int radius; //!< The radius of the circle
cv::Scalar color; //!< The color of the circle
int thick; //!< The thickness of the circle outline, if positive. Negative values, like #FILLED, mean that a filled circle is to be drawn
int lt; //!< The Type of the circle boundary. See #LineTypes
int shift; //!< The Number of fractional bits in the coordinates of the center and in the radius value
GAPI_PROP_RW cv::Point center; //!< The center of the circle
GAPI_PROP_RW int radius; //!< The radius of the circle
GAPI_PROP_RW cv::Scalar color; //!< The color of the circle
GAPI_PROP_RW int thick; //!< The thickness of the circle outline, if positive. Negative values, like #FILLED, mean that a filled circle is to be drawn
GAPI_PROP_RW int lt; //!< The Type of the circle boundary. See #LineTypes
GAPI_PROP_RW int shift; //!< The Number of fractional bits in the coordinates of the center and in the radius value
/*@{*/
};
@@ -197,7 +202,7 @@ struct Circle
*
* Parameters match cv::line().
*/
struct Line
struct GAPI_EXPORTS_W_SIMPLE Line
{
/**
* @brief Line constructor
@@ -209,6 +214,7 @@ struct Line
* @param lt_ The Type of the line. See #LineTypes
* @param shift_ The number of fractional bits in the point coordinates
*/
GAPI_WRAP
Line(const cv::Point& pt1_,
const cv::Point& pt2_,
const cv::Scalar& color_,
@@ -219,15 +225,16 @@ struct Line
{
}
GAPI_WRAP
Line() = default;
/*@{*/
cv::Point pt1; //!< The first point of the line segment
cv::Point pt2; //!< The second point of the line segment
cv::Scalar color; //!< The line color
int thick; //!< The thickness of line
int lt; //!< The Type of the line. See #LineTypes
int shift; //!< The number of fractional bits in the point coordinates
GAPI_PROP_RW cv::Point pt1; //!< The first point of the line segment
GAPI_PROP_RW cv::Point pt2; //!< The second point of the line segment
GAPI_PROP_RW cv::Scalar color; //!< The line color
GAPI_PROP_RW int thick; //!< The thickness of line
GAPI_PROP_RW int lt; //!< The Type of the line. See #LineTypes
GAPI_PROP_RW int shift; //!< The number of fractional bits in the point coordinates
/*@{*/
};
@@ -236,7 +243,7 @@ struct Line
*
* Mosaicing is a very basic method to obfuscate regions in the image.
*/
struct Mosaic
struct GAPI_EXPORTS_W_SIMPLE Mosaic
{
/**
* @brief Mosaic constructor
@@ -252,12 +259,13 @@ struct Mosaic
{
}
GAPI_WRAP
Mosaic() : cellSz(0), decim(0) {}
/*@{*/
cv::Rect mos; //!< Coordinates of the mosaic
int cellSz; //!< Cell size (same for X, Y)
int decim; //!< Decimation (0 stands for no decimation)
GAPI_PROP_RW cv::Rect mos; //!< Coordinates of the mosaic
GAPI_PROP_RW int cellSz; //!< Cell size (same for X, Y)
GAPI_PROP_RW int decim; //!< Decimation (0 stands for no decimation)
/*@{*/
};
@@ -266,7 +274,7 @@ struct Mosaic
*
* Image is blended on a frame using the specified mask.
*/
struct Image
struct GAPI_EXPORTS_W_SIMPLE Image
{
/**
* @brief Mosaic constructor
@@ -275,6 +283,7 @@ struct Image
* @param img_ Image to draw
* @param alpha_ Alpha channel for image to draw (same size and number of channels)
*/
GAPI_WRAP
Image(const cv::Point& org_,
const cv::Mat& img_,
const cv::Mat& alpha_) :
@@ -282,19 +291,20 @@ struct Image
{
}
GAPI_WRAP
Image() = default;
/*@{*/
cv::Point org; //!< The bottom-left corner of the image
cv::Mat img; //!< Image to draw
cv::Mat alpha; //!< Alpha channel for image to draw (same size and number of channels)
GAPI_PROP_RW cv::Point org; //!< The bottom-left corner of the image
GAPI_PROP_RW cv::Mat img; //!< Image to draw
GAPI_PROP_RW cv::Mat alpha; //!< Alpha channel for image to draw (same size and number of channels)
/*@{*/
};
/**
* @brief This structure represents a polygon to draw.
*/
struct Poly
struct GAPI_EXPORTS_W_SIMPLE Poly
{
/**
* @brief Mosaic constructor
@@ -305,6 +315,7 @@ struct Poly
* @param lt_ The Type of the line. See #LineTypes
* @param shift_ The number of fractional bits in the point coordinate
*/
GAPI_WRAP
Poly(const std::vector<cv::Point>& points_,
const cv::Scalar& color_,
int thick_ = 1,
@@ -314,14 +325,15 @@ struct Poly
{
}
GAPI_WRAP
Poly() = default;
/*@{*/
std::vector<cv::Point> points; //!< Points to connect
cv::Scalar color; //!< The line color
int thick; //!< The thickness of line
int lt; //!< The Type of the line. See #LineTypes
int shift; //!< The number of fractional bits in the point coordinate
GAPI_PROP_RW std::vector<cv::Point> points; //!< Points to connect
GAPI_PROP_RW cv::Scalar color; //!< The line color
GAPI_PROP_RW int thick; //!< The thickness of line
GAPI_PROP_RW int lt; //!< The Type of the line. See #LineTypes
GAPI_PROP_RW int shift; //!< The number of fractional bits in the point coordinate
/*@{*/
};
@@ -336,7 +348,7 @@ using Prim = util::variant
, Poly
>;
using Prims = std::vector<Prim>;
using Prims = std::vector<Prim>;
//! @} gapi_draw_prims
} // namespace draw