Skip to content

Commit d7540c9

Browse files
dmatveevalalek
authored andcommitted
Merge pull request opencv#13176 from dmatveev:gapi_doxygen
G-API: Doxygen class reference * G-API Doxygen documentation: covered cv::GComputation * G-API Doxygen documentation: added sections on compile arguments * G-API Doxygen documentation: restructuring & more text * Added new sections (organized API reference into it); * Documented GCompiled, compile args, backends, etc. * G-API Doxygen documentation: documented GKernelPackage and added group for meta
1 parent bea312b commit d7540c9

File tree

12 files changed

+880
-34
lines changed

12 files changed

+880
-34
lines changed

modules/gapi/include/opencv2/gapi.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010

1111
#include <memory>
1212

13+
/** \defgroup gapi G-API framework
14+
@{
15+
@defgroup gapi_main_classes G-API Main Classes
16+
@defgroup gapi_data_objects G-API Data Objects
17+
@{
18+
@defgroup gapi_meta_args G-API Metadata Descriptors
19+
@}
20+
@defgroup gapi_std_backends G-API Standard backends
21+
@defgroup gapi_compile_args G-API Graph Compilation Arguments
22+
@}
23+
*/
24+
1325
#include "opencv2/gapi/gmat.hpp"
1426
#include "opencv2/gapi/garray.hpp"
1527
#include "opencv2/gapi/gcomputation.hpp"

modules/gapi/include/opencv2/gapi/cpu/gcpukernel.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,37 @@ namespace gapi
3333
{
3434
namespace cpu
3535
{
36+
/**
37+
* \addtogroup gapi_std_backends
38+
* @{
39+
*
40+
* @brief G-API backends available in this OpenCV version
41+
*
42+
* G-API backends play a corner stone role in G-API execution
43+
* stack. Every backend is hardware-oriented and thus can run its
44+
* kernels efficiently on the target platform.
45+
*
46+
* Backends are usually "back boxes" for G-API users -- on the API
47+
* side, all backends are represented as different objects of the
48+
* same class cv::gapi::GBackend. User can manipulate with backends
49+
* mainly by specifying which kernels to use or where to look up
50+
* for kernels first.
51+
*
52+
* @sa @ref gapi_hld, cv::gapi::lookup_order()
53+
*/
54+
55+
/**
56+
* @brief Get a reference to CPU (OpenCV) backend.
57+
*
58+
* This is the default backend in G-API at the moment, providing
59+
* broader functional coverage but losing some graph model
60+
* advantages. Provided mostly for reference and prototyping
61+
* purposes.
62+
*
63+
* @sa gapi_std_backends
64+
*/
3665
GAPI_EXPORTS cv::gapi::GBackend backend();
66+
/** @} */
3767
} // namespace cpu
3868
} // namespace gapi
3969

modules/gapi/include/opencv2/gapi/fluid/gfluidkernel.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,21 @@ namespace gapi
2828
{
2929
namespace fluid
3030
{
31+
/**
32+
* \addtogroup gapi_std_backends G-API Standard backends
33+
* @{
34+
*/
35+
/**
36+
* @brief Get a reference to Fluid backend.
37+
*
38+
* @sa gapi_std_backends
39+
*/
3140
GAPI_EXPORTS cv::gapi::GBackend backend();
41+
/** @} */
3242
} // namespace flud
3343
} // namespace gapi
3444

45+
3546
class GAPI_EXPORTS GFluidKernel
3647
{
3748
public:

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@ struct GOrigin;
2929

3030
template<typename T> class GArray;
3131

32+
/**
33+
* \addtogroup gapi_meta_args
34+
* @{
35+
*/
3236
struct GArrayDesc
3337
{
3438
// FIXME: Body
3539
// FIXME: Also implement proper operator== then
3640
bool operator== (const GArrayDesc&) const { return true; }
3741
};
3842
template<typename U> GArrayDesc descr_of(const std::vector<U> &) { return {};}
39-
inline GArrayDesc empty_array_desc() {return {}; }
43+
static inline GArrayDesc empty_array_desc() {return {}; }
44+
/** @} */
45+
4046
std::ostream& operator<<(std::ostream& os, const cv::GArrayDesc &desc);
4147

4248
namespace detail
@@ -218,6 +224,10 @@ namespace detail
218224
};
219225
} // namespace detail
220226

227+
/** \addtogroup gapi_data_objects
228+
* @{
229+
*/
230+
221231
template<typename T> class GArray
222232
{
223233
public:
@@ -234,6 +244,8 @@ template<typename T> class GArray
234244
detail::GArrayU m_ref;
235245
};
236246

247+
/** @} */
248+
237249
} // namespace cv
238250

239251
#endif // OPENCV_GAPI_GARRAY_HPP

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,41 @@ namespace detail {
5353
// CompileArg is an unified interface over backend-specific compilation
5454
// information
5555
// FIXME: Move to a separate file?
56+
/** \addtogroup gapi_compile_args
57+
* @{
58+
*
59+
* @brief Compilation arguments: a set of data structures which can be
60+
* passed to control compilation process
61+
*
62+
* G-API comes with a number of graph compilation options which can be
63+
* passed to cv::GComputation::apply() or
64+
* cv::GComputation::compile(). Known compilation options are listed
65+
* in this page, while extra backends may introduce their own
66+
* compilation options (G-API transparently accepts _everything_ which
67+
* can be passed to cv::compile_args(), it depends on underlying
68+
* backends if an option would be interpreted or not).
69+
*
70+
* For example, if an example computation is executed like this:
71+
*
72+
* @snippet modules/gapi/samples/api_ref_snippets.cpp graph_decl_apply
73+
*
74+
* Extra parameter specifying which kernels to compile with can be
75+
* passed like this:
76+
*
77+
* @snippet modules/gapi/samples/api_ref_snippets.cpp apply_with_param
78+
*/
79+
80+
/**
81+
* @brief Represents an arbitrary compilation argument.
82+
*
83+
* Any value can be wrapped into cv::GCompileArg, but only known ones
84+
* (to G-API or its backends) can be interpreted correctly.
85+
*
86+
* Normally objects of this class shouldn't be created manually, use
87+
* cv::compile_args() function which automatically wraps everything
88+
* passed in (a variadic template parameter pack) into a vector of
89+
* cv::GCompileArg objects.
90+
*/
5691
struct GAPI_EXPORTS GCompileArg
5792
{
5893
public:
@@ -82,15 +117,28 @@ struct GAPI_EXPORTS GCompileArg
82117

83118
using GCompileArgs = std::vector<GCompileArg>;
84119

120+
/**
121+
* Wraps a list of arguments (a parameter pack) into a vector of
122+
* compilation arguments (cv::GCompileArg).
123+
*/
85124
template<typename... Ts> GCompileArgs compile_args(Ts&&... args)
86125
{
87126
return GCompileArgs{ GCompileArg(args)... };
88127
}
89128

129+
/**
130+
* @brief Ask G-API to dump compiled graph in Graphviz format under
131+
* the given file name.
132+
*
133+
* Specifies a graph dump path (path to .dot file to be generated).
134+
* G-API will dump a .dot file under specified path during a
135+
* compilation process if this flag is passed.
136+
*/
90137
struct graph_dump_path
91138
{
92139
std::string m_dump_path;
93140
};
141+
/** @} */
94142

95143
namespace detail
96144
{

modules/gapi/include/opencv2/gapi/gcompiled.hpp

Lines changed: 159 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,190 @@ namespace cv {
2727
// FIXME: In future, there should be a way to name I/O objects and specify it
2828
// to GCompiled externally (for example, when it is loaded on the target system).
2929

30+
/**
31+
* \addtogroup gapi_main_classes
32+
* @{
33+
*/
34+
/**
35+
* @brief Represents a compiled computation (graph). Can only be used
36+
* with image / data formats & resolutions it was compiled for, with
37+
* some exceptions.
38+
*
39+
* This class represents a product of graph compilation (calling
40+
* cv::GComputation::compile()). Objects of this class actually do
41+
* data processing, and graph execution is incapsulated into objects
42+
* of this class. Execution model itself depends on kernels and
43+
* backends which were using during the compilation, see @ref
44+
* gapi_compile_args for details.
45+
*
46+
* In a general case, GCompiled objects can be applied to data only in
47+
* that formats/resolutions they were compiled for (see @ref
48+
* gapi_meta_args). However, if the underlying backends allow, a
49+
* compiled object can be _reshaped_ to handle data (images) of
50+
* different resolution, though formats and types must remain the same.
51+
*
52+
* GCompiled is very similar to `std::function<>` in its semantics --
53+
* running it looks like a function call in the user code.
54+
*
55+
* At the moment, GCompiled objects are not reentrant -- generally,
56+
* the objects are stateful since graph execution itself is a stateful
57+
* process and this state is now maintained in GCompiled's own memory
58+
* (not on the process stack).
59+
*
60+
* At the same time, two different GCompiled objects produced from the
61+
* single cv::GComputation are completely independent and can be used
62+
* concurrently.
63+
*/
3064
class GAPI_EXPORTS GCompiled
3165
{
3266
public:
67+
/// @private
3368
class GAPI_EXPORTS Priv;
3469

70+
/**
71+
* @brief Constructs an empty object
72+
*/
3573
GCompiled();
3674

75+
/**
76+
* @brief Run the compiled computation, a generic version.
77+
*
78+
* @param ins vector of inputs to process.
79+
* @param outs vector of outputs to produce.
80+
*
81+
* Input/output vectors must have the same number of elements as
82+
* defined in the cv::GComputation protocol (at the moment of its
83+
* construction). Shapes of elements also must conform to protocol
84+
* (e.g. cv::Mat needs to be passed where cv::GMat has been
85+
* declared as input, and so on). Run-time exception is generated
86+
* otherwise.
87+
*
88+
* Objects in output vector may remain empty (like cv::Mat) --
89+
* G-API will automatically initialize output objects to proper formats.
90+
*
91+
* @note Don't construct GRunArgs/GRunArgsP objects manually, use
92+
* cv::gin()/cv::gout() wrappers instead.
93+
*/
3794
void operator() (GRunArgs &&ins, GRunArgsP &&outs); // Generic arg-to-arg
3895
#if !defined(GAPI_STANDALONE)
96+
97+
/**
98+
* @brief Execute an unary computation
99+
*
100+
* @overload
101+
* @param in input cv::Mat for unary computation
102+
* @param out output cv::Mat for unary computation
103+
* process.
104+
*/
39105
void operator() (cv::Mat in, cv::Mat &out); // Unary overload
106+
107+
/**
108+
* @brief Execute an unary computation
109+
*
110+
* @overload
111+
* @param in input cv::Mat for unary computation
112+
* @param out output cv::Scalar for unary computation
113+
* process.
114+
*/
40115
void operator() (cv::Mat in, cv::Scalar &out); // Unary overload (scalar)
116+
117+
/**
118+
* @brief Execute a binary computation
119+
*
120+
* @overload
121+
* @param in1 first input cv::Mat for binary computation
122+
* @param in2 second input cv::Mat for binary computation
123+
* @param out output cv::Mat for binary computation
124+
* process.
125+
*/
41126
void operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out); // Binary overload
127+
128+
/**
129+
* @brief Execute an binary computation
130+
*
131+
* @overload
132+
* @param in1 first input cv::Mat for binary computation
133+
* @param in2 second input cv::Mat for binary computation
134+
* @param out output cv::Scalar for binary computation
135+
* process.
136+
*/
42137
void operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out); // Binary overload (scalar)
138+
139+
/**
140+
* @brief Execute a computation with arbitrary number of
141+
* inputs/outputs.
142+
*
143+
* @overload
144+
* @param ins vector of input cv::Mat objects to process by the
145+
* computation.
146+
* @param outs vector of output cv::Mat objects to produce by the
147+
* computation.
148+
*
149+
* Numbers of elements in ins/outs vectos must match numbers of
150+
* inputs/outputs which were used to define the source GComputation.
151+
*/
43152
void operator() (const std::vector<cv::Mat> &ins, // Compatibility overload
44153
const std::vector<cv::Mat> &outs);
45154
#endif // !defined(GAPI_STANDALONE)
155+
/// @private
46156
Priv& priv();
47157

48-
explicit operator bool () const; // Check if GCompiled is runnable or empty
158+
/**
159+
* @brief Check if compiled object is valid (non-empty)
160+
*
161+
* @return true if the object is runnable (valid), false otherwise
162+
*/
163+
explicit operator bool () const;
49164

165+
/**
166+
* @brief Vector of metadata this graph was compiled for.
167+
*
168+
* @return Unless _reshape_ is not supported, return value is the
169+
* same vector which was passed to cv::GComputation::compile() to
170+
* produce this compiled object. Otherwise, it is the latest
171+
* metadata vector passed to reshape() (if that call was
172+
* successful).
173+
*/
50174
const GMetaArgs& metas() const; // Meta passed to compile()
51-
const GMetaArgs& outMetas() const; // Inferred output metadata
52175

53-
bool canReshape() const; // is reshape mechanism supported by GCompiled
54-
void reshape(const GMetaArgs& inMetas, const GCompileArgs& args); // run reshape procedure
176+
/**
177+
* @brief Vector of metadata descriptions of graph outputs
178+
*
179+
* @return vector with formats/resolutions of graph's output
180+
* objects, auto-inferred from input metadata vector by
181+
* operations which form this computation.
182+
*
183+
* @note GCompiled objects produced from the same
184+
* cv::GComputiation graph with different input metas may return
185+
* different values in this vector.
186+
*/
187+
const GMetaArgs& outMetas() const;
188+
189+
/**
190+
* @brief Check if the underlying backends support reshape or not.
191+
*
192+
* @return true if supported, false otherwise.
193+
*/
194+
bool canReshape() const;
195+
196+
/**
197+
* @brief Reshape a compiled graph to support new image
198+
* resolutions.
199+
*
200+
* Throws an exception if an error occurs.
201+
*
202+
* @param inMetas new metadata to reshape on. Vector size and
203+
* metadata shapes must match the computation's protocol.
204+
* @param args compilation arguments to use.
205+
*/
206+
// FIXME: Why it requires compile args?
207+
void reshape(const GMetaArgs& inMetas, const GCompileArgs& args);
55208

56209
protected:
210+
/// @private
57211
std::shared_ptr<Priv> m_priv;
58212
};
213+
/** @} */
59214

60215
}
61216

0 commit comments

Comments
 (0)