Skip to content

Commit f6aa9ac

Browse files
Merge pull request opencv#18292 from smirnov-alexey:as/osd_serialization
[G-API]: Support render primitives serialization * Add GOpaque and GArray serialization support * Address review comments * Remove holds() method * Add serialization mechanism for render primitives * Fix standalone mode * Fix wchar_t error on win64 * Fix assert on windows * Address review comments * Fix GArray and GOpaque reset() method to store proper kind * Reset wchar before deserializing it * Fix wchar_t cross-platform issue * Address review comments * Fix wchar_t serialization and tests * Remove FText serialization
1 parent f52a2cf commit f6aa9ac

File tree

11 files changed

+678
-315
lines changed

11 files changed

+678
-315
lines changed

modules/gapi/include/opencv2/gapi/garray.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ namespace detail
261261
template<typename T> void reset()
262262
{
263263
if (!m_ref) m_ref.reset(new VectorRefT<T>());
264-
265264
check<T>();
265+
storeKind<T>();
266266
static_cast<VectorRefT<T>&>(*m_ref).reset();
267267
}
268268

modules/gapi/include/opencv2/gapi/gcommon.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <opencv2/gapi/util/optional.hpp>
1919
#include <opencv2/gapi/own/exports.hpp>
2020
#include <opencv2/gapi/own/assert.hpp>
21+
#include <opencv2/gapi/render/render_types.hpp>
2122

2223
namespace cv {
2324

@@ -48,6 +49,7 @@ namespace detail
4849
CV_RECT, // cv::Rect user G-API data
4950
CV_SCALAR, // cv::Scalar user G-API data
5051
CV_MAT, // cv::Mat user G-API data
52+
CV_PRIM, // cv::gapi::wip::draw::Prim user G-API data
5153
};
5254

5355
// Type traits helper which simplifies the extraction of kind from type
@@ -62,10 +64,12 @@ namespace detail
6264
template<> struct GOpaqueTraits<cv::Mat> { static constexpr const OpaqueKind kind = OpaqueKind::CV_MAT; };
6365
template<> struct GOpaqueTraits<cv::Rect> { static constexpr const OpaqueKind kind = OpaqueKind::CV_RECT; };
6466
template<> struct GOpaqueTraits<cv::GMat> { static constexpr const OpaqueKind kind = OpaqueKind::CV_MAT; };
67+
template<> struct GOpaqueTraits<cv::gapi::wip::draw::Prim>
68+
{ static constexpr const OpaqueKind kind = OpaqueKind::CV_PRIM; };
6569
// GArray is not supporting bool type for now due to difference in std::vector<bool> implementation
66-
using GOpaqueTraitsArrayTypes = std::tuple<int, double, cv::Size, cv::Scalar, cv::Point, cv::Mat, cv::Rect>;
70+
using GOpaqueTraitsArrayTypes = std::tuple<int, double, cv::Size, cv::Scalar, cv::Point, cv::Mat, cv::Rect, cv::gapi::wip::draw::Prim>;
6771
// GOpaque is not supporting cv::Mat and cv::Scalar since there are GScalar and GMat types
68-
using GOpaqueTraitsOpaqueTypes = std::tuple<bool, int, double, cv::Size, cv::Point, cv::Rect>;
72+
using GOpaqueTraitsOpaqueTypes = std::tuple<bool, int, double, cv::Size, cv::Point, cv::Rect, cv::gapi::wip::draw::Prim>;
6973
} // namespace detail
7074

7175
// This definition is here because it is reused by both public(?) and internal

modules/gapi/include/opencv2/gapi/gopaque.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ namespace detail
250250
template<typename T> void reset()
251251
{
252252
if (!m_ref) m_ref.reset(new OpaqueRefT<T>());
253-
254253
check<T>();
254+
storeKind<T>();
255255
static_cast<OpaqueRefT<T>&>(*m_ref).reset();
256256
}
257257

modules/gapi/include/opencv2/gapi/render/render.hpp

Lines changed: 2 additions & 309 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22
// It is subject to the license terms in the LICENSE file found in the top-level directory
33
// of this distribution and at http://opencv.org/license.html.
44
//
5-
// Copyright (C) 2018-2019 Intel Corporation
5+
// Copyright (C) 2018-2020 Intel Corporation
66

77

88
#ifndef OPENCV_GAPI_RENDER_HPP
99
#define OPENCV_GAPI_RENDER_HPP
1010

11-
#include <string>
12-
#include <vector>
11+
#include <opencv2/gapi/render/render_types.hpp>
1312

14-
#include <opencv2/imgproc.hpp>
1513
#include <opencv2/gapi.hpp>
1614

17-
#include <opencv2/gapi/opencv_includes.hpp>
18-
#include <opencv2/gapi/util/variant.hpp>
19-
#include <opencv2/gapi/own/exports.hpp>
20-
21-
2215
/** \defgroup gapi_draw G-API Drawing and composition functionality
2316
* @{
2417
*
@@ -77,309 +70,9 @@ namespace wip
7770
namespace draw
7871
{
7972

80-
/**
81-
* @brief This structure specifies which FreeType font to use by FText primitives.
82-
*/
83-
struct freetype_font
84-
{
85-
/*@{*/
86-
std::string path; //!< The path to the font file (.ttf)
87-
/*@{*/
88-
};
89-
90-
//! @addtogroup gapi_draw_prims
91-
//! @{
92-
/**
93-
* @brief This structure represents a text string to draw.
94-
*
95-
* Parameters match cv::putText().
96-
*/
97-
struct Text
98-
{
99-
/**
100-
* @brief Text constructor
101-
*
102-
* @param text_ The text string to be drawn
103-
* @param org_ The bottom-left corner of the text string in the image
104-
* @param ff_ The font type, see #HersheyFonts
105-
* @param fs_ The font scale factor that is multiplied by the font-specific base size
106-
* @param color_ The text color
107-
* @param thick_ The thickness of the lines used to draw a text
108-
* @param lt_ The line type. See #LineTypes
109-
* @param bottom_left_origin_ When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner
110-
*/
111-
Text(const std::string& text_,
112-
const cv::Point& org_,
113-
int ff_,
114-
double fs_,
115-
const cv::Scalar& color_,
116-
int thick_ = 1,
117-
int lt_ = cv::LINE_8,
118-
bool bottom_left_origin_ = false) :
119-
text(text_), org(org_), ff(ff_), fs(fs_),
120-
color(color_), thick(thick_), lt(lt_), bottom_left_origin(bottom_left_origin_)
121-
{
122-
}
123-
124-
/*@{*/
125-
std::string text; //!< The text string to be drawn
126-
cv::Point org; //!< The bottom-left corner of the text string in the image
127-
int ff; //!< The font type, see #HersheyFonts
128-
double fs; //!< The font scale factor that is multiplied by the font-specific base size
129-
cv::Scalar color; //!< The text color
130-
int thick; //!< The thickness of the lines used to draw a text
131-
int lt; //!< The line type. See #LineTypes
132-
bool bottom_left_origin; //!< When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner
133-
/*@{*/
134-
};
135-
136-
/**
137-
* @brief This structure represents a text string to draw using
138-
* FreeType renderer.
139-
*
140-
* If OpenCV is built without FreeType support, this primitive will
141-
* fail at the execution stage.
142-
*/
143-
struct FText
144-
{
145-
/**
146-
* @brief FText constructor
147-
*
148-
* @param text_ The text string to be drawn
149-
* @param org_ The bottom-left corner of the text string in the image
150-
* @param fh_ The height of text
151-
* @param color_ The text color
152-
*/
153-
FText(const std::wstring& text_,
154-
const cv::Point& org_,
155-
int fh_,
156-
const cv::Scalar& color_) :
157-
text(text_), org(org_), fh(fh_), color(color_)
158-
{
159-
}
160-
161-
/*@{*/
162-
std::wstring text; //!< The text string to be drawn
163-
cv::Point org; //!< The bottom-left corner of the text string in the image
164-
int fh; //!< The height of text
165-
cv::Scalar color; //!< The text color
166-
/*@{*/
167-
};
168-
169-
/**
170-
* @brief This structure represents a rectangle to draw.
171-
*
172-
* Parameters match cv::rectangle().
173-
*/
174-
struct Rect
175-
{
176-
/**
177-
* @brief Rect constructor
178-
*
179-
* @param rect_ Coordinates of the rectangle
180-
* @param color_ The bottom-left corner of the text string in the image
181-
* @param thick_ The thickness of lines that make up the rectangle. Negative values, like #FILLED, mean that the function has to draw a filled rectangle
182-
* @param lt_ The type of the line. See #LineTypes
183-
* @param shift_ The number of fractional bits in the point coordinates
184-
*/
185-
Rect(const cv::Rect& rect_,
186-
const cv::Scalar& color_,
187-
int thick_ = 1,
188-
int lt_ = cv::LINE_8,
189-
int shift_ = 0) :
190-
rect(rect_), color(color_), thick(thick_), lt(lt_), shift(shift_)
191-
{
192-
}
193-
194-
/*@{*/
195-
cv::Rect rect; //!< Coordinates of the rectangle
196-
cv::Scalar color; //!< The rectangle color or brightness (grayscale image)
197-
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
198-
int lt; //!< The type of the line. See #LineTypes
199-
int shift; //!< The number of fractional bits in the point coordinates
200-
/*@{*/
201-
};
202-
203-
/**
204-
* @brief This structure represents a circle to draw.
205-
*
206-
* Parameters match cv::circle().
207-
*/
208-
struct Circle
209-
{
210-
/**
211-
* @brief Circle constructor
212-
*
213-
* @param center_ The center of the circle
214-
* @param radius_ The radius of the circle
215-
* @param color_ The color of the circle
216-
* @param thick_ The thickness of the circle outline, if positive. Negative values, like #FILLED, mean that a filled circle is to be drawn
217-
* @param lt_ The Type of the circle boundary. See #LineTypes
218-
* @param shift_ The Number of fractional bits in the coordinates of the center and in the radius value
219-
*/
220-
Circle(const cv::Point& center_,
221-
int radius_,
222-
const cv::Scalar& color_,
223-
int thick_ = 1,
224-
int lt_ = cv::LINE_8,
225-
int shift_ = 0) :
226-
center(center_), radius(radius_), color(color_), thick(thick_), lt(lt_), shift(shift_)
227-
{
228-
}
229-
230-
/*@{*/
231-
cv::Point center; //!< The center of the circle
232-
int radius; //!< The radius of the circle
233-
cv::Scalar color; //!< The color of the circle
234-
int thick; //!< The thickness of the circle outline, if positive. Negative values, like #FILLED, mean that a filled circle is to be drawn
235-
int lt; //!< The Type of the circle boundary. See #LineTypes
236-
int shift; //!< The Number of fractional bits in the coordinates of the center and in the radius value
237-
/*@{*/
238-
};
239-
240-
/**
241-
* @brief This structure represents a line to draw.
242-
*
243-
* Parameters match cv::line().
244-
*/
245-
struct Line
246-
{
247-
/**
248-
* @brief Line constructor
249-
*
250-
* @param pt1_ The first point of the line segment
251-
* @param pt2_ The second point of the line segment
252-
* @param color_ The line color
253-
* @param thick_ The thickness of line
254-
* @param lt_ The Type of the line. See #LineTypes
255-
* @param shift_ The number of fractional bits in the point coordinates
256-
*/
257-
Line(const cv::Point& pt1_,
258-
const cv::Point& pt2_,
259-
const cv::Scalar& color_,
260-
int thick_ = 1,
261-
int lt_ = cv::LINE_8,
262-
int shift_ = 0) :
263-
pt1(pt1_), pt2(pt2_), color(color_), thick(thick_), lt(lt_), shift(shift_)
264-
{
265-
}
266-
267-
/*@{*/
268-
cv::Point pt1; //!< The first point of the line segment
269-
cv::Point pt2; //!< The second point of the line segment
270-
cv::Scalar color; //!< The line color
271-
int thick; //!< The thickness of line
272-
int lt; //!< The Type of the line. See #LineTypes
273-
int shift; //!< The number of fractional bits in the point coordinates
274-
/*@{*/
275-
};
276-
277-
/**
278-
* @brief This structure represents a mosaicing operation.
279-
*
280-
* Mosaicing is a very basic method to obfuscate regions in the image.
281-
*/
282-
struct Mosaic
283-
{
284-
/**
285-
* @brief Mosaic constructor
286-
*
287-
* @param mos_ Coordinates of the mosaic
288-
* @param cellSz_ Cell size (same for X, Y)
289-
* @param decim_ Decimation (0 stands for no decimation)
290-
*/
291-
Mosaic(const cv::Rect& mos_,
292-
int cellSz_,
293-
int decim_) :
294-
mos(mos_), cellSz(cellSz_), decim(decim_)
295-
{
296-
}
297-
298-
/*@{*/
299-
cv::Rect mos; //!< Coordinates of the mosaic
300-
int cellSz; //!< Cell size (same for X, Y)
301-
int decim; //!< Decimation (0 stands for no decimation)
302-
/*@{*/
303-
};
304-
305-
/**
306-
* @brief This structure represents an image to draw.
307-
*
308-
* Image is blended on a frame using the specified mask.
309-
*/
310-
struct Image
311-
{
312-
/**
313-
* @brief Mosaic constructor
314-
*
315-
* @param org_ The bottom-left corner of the image
316-
* @param img_ Image to draw
317-
* @param alpha_ Alpha channel for image to draw (same size and number of channels)
318-
*/
319-
Image(const cv::Point& org_,
320-
const cv::Mat& img_,
321-
const cv::Mat& alpha_) :
322-
org(org_), img(img_), alpha(alpha_)
323-
{
324-
}
325-
326-
/*@{*/
327-
cv::Point org; //!< The bottom-left corner of the image
328-
cv::Mat img; //!< Image to draw
329-
cv::Mat alpha; //!< Alpha channel for image to draw (same size and number of channels)
330-
/*@{*/
331-
};
332-
333-
/**
334-
* @brief This structure represents a polygon to draw.
335-
*/
336-
struct Poly
337-
{
338-
/**
339-
* @brief Mosaic constructor
340-
*
341-
* @param points_ Points to connect
342-
* @param color_ The line color
343-
* @param thick_ The thickness of line
344-
* @param lt_ The Type of the line. See #LineTypes
345-
* @param shift_ The number of fractional bits in the point coordinate
346-
*/
347-
Poly(const std::vector<cv::Point>& points_,
348-
const cv::Scalar& color_,
349-
int thick_ = 1,
350-
int lt_ = cv::LINE_8,
351-
int shift_ = 0) :
352-
points(points_), color(color_), thick(thick_), lt(lt_), shift(shift_)
353-
{
354-
}
355-
356-
/*@{*/
357-
std::vector<cv::Point> points; //!< Points to connect
358-
cv::Scalar color; //!< The line color
359-
int thick; //!< The thickness of line
360-
int lt; //!< The Type of the line. See #LineTypes
361-
int shift; //!< The number of fractional bits in the point coordinate
362-
/*@{*/
363-
};
364-
365-
using Prim = util::variant
366-
< Text
367-
, FText
368-
, Rect
369-
, Circle
370-
, Line
371-
, Mosaic
372-
, Image
373-
, Poly
374-
>;
375-
376-
using Prims = std::vector<Prim>;
377-
//! @} gapi_draw_prims
378-
37973
using GMat2 = std::tuple<cv::GMat,cv::GMat>;
38074
using GMatDesc2 = std::tuple<cv::GMatDesc,cv::GMatDesc>;
38175

382-
38376
//! @addtogroup gapi_draw_api
38477
//! @{
38578
/** @brief The function renders on the input image passed drawing primitivies

0 commit comments

Comments
 (0)