Skip to content

Commit eb82ba3

Browse files
Merge pull request opencv#19322 from TolyaTalamanov:at/python-callbacks
[G-API] Introduce cv.gin/cv.descr_of for python * Implement cv.gin/cv.descr_of * Fix macos build * Fix gcomputation tests * Add test * Add using to a void exceeded length for windows build * Add using to a void exceeded length for windows build * Fix comments to review * Fix comments to review * Update from latest master * Avoid graph compilation to obtain in/out info * Fix indentation * Fix comments to review * Avoid using default in switches * Post output meta for giebackend
1 parent 7bcb51e commit eb82ba3

26 files changed

+824
-219
lines changed

modules/gapi/include/opencv2/gapi/core.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,14 +1909,14 @@ kmeans(const GMat& data, const int K, const GMat& bestLabels,
19091909
- Function textual ID is "org.opencv.core.kmeansNDNoInit"
19101910
- #KMEANS_USE_INITIAL_LABELS flag must not be set while using this overload.
19111911
*/
1912-
GAPI_EXPORTS std::tuple<GOpaque<double>,GMat,GMat>
1912+
GAPI_EXPORTS_W std::tuple<GOpaque<double>,GMat,GMat>
19131913
kmeans(const GMat& data, const int K, const TermCriteria& criteria, const int attempts,
19141914
const KmeansFlags flags);
19151915

19161916
/** @overload
19171917
@note Function textual ID is "org.opencv.core.kmeans2D"
19181918
*/
1919-
GAPI_EXPORTS std::tuple<GOpaque<double>,GArray<int>,GArray<Point2f>>
1919+
GAPI_EXPORTS_W std::tuple<GOpaque<double>,GArray<int>,GArray<Point2f>>
19201920
kmeans(const GArray<Point2f>& data, const int K, const GArray<int>& bestLabels,
19211921
const TermCriteria& criteria, const int attempts, const KmeansFlags flags);
19221922

@@ -1935,7 +1935,7 @@ namespace streaming {
19351935
@param src Input tensor
19361936
@return Size (tensor dimensions).
19371937
*/
1938-
GAPI_EXPORTS GOpaque<Size> size(const GMat& src);
1938+
GAPI_EXPORTS_W GOpaque<Size> size(const GMat& src);
19391939

19401940
/** @overload
19411941
Gets dimensions from rectangle.

modules/gapi/include/opencv2/gapi/garg.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,30 @@ template<typename... Ts> inline GRunArgsP gout(Ts&... args)
249249
return GRunArgsP{ GRunArgP(detail::wrap_host_helper<Ts>::wrap_out(args))... };
250250
}
251251

252+
struct GTypeInfo;
253+
using GTypesInfo = std::vector<GTypeInfo>;
254+
255+
// FIXME: Needed for python bridge, must be moved to more appropriate header
256+
namespace detail {
257+
struct ExtractArgsCallback
258+
{
259+
cv::GRunArgs operator()(const cv::GTypesInfo& info) const { return c(info); }
260+
using CallBackT = std::function<cv::GRunArgs(const cv::GTypesInfo& info)>;
261+
CallBackT c;
262+
};
263+
264+
struct ExtractMetaCallback
265+
{
266+
cv::GMetaArgs operator()(const cv::GTypesInfo& info) const { return c(info); }
267+
using CallBackT = std::function<cv::GMetaArgs(const cv::GTypesInfo& info)>;
268+
CallBackT c;
269+
};
270+
271+
void constructGraphOutputs(const cv::GTypesInfo &out_info,
272+
cv::GRunArgs &args,
273+
cv::GRunArgsP &outs);
274+
} // namespace detail
275+
252276
} // namespace cv
253277

254278
#endif // OPENCV_GAPI_GARG_HPP

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,6 @@ template<typename T> class GArray
368368
detail::GArrayU m_ref;
369369
};
370370

371-
using GArrayP2f = GArray<cv::Point2f>;
372-
373371
/** @} */
374372

375373
} // namespace cv

modules/gapi/include/opencv2/gapi/gcomputation.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ class GAPI_EXPORTS_W GComputation
258258
void apply(GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args = {}); // Arg-to-arg overload
259259

260260
/// @private -- Exclude this function from OpenCV documentation
261-
GAPI_WRAP GRunArgs apply(GRunArgs &&ins, GCompileArgs &&args = {});
261+
GAPI_WRAP GRunArgs apply(const cv::detail::ExtractArgsCallback &callback,
262+
GCompileArgs &&args = {});
262263

263264
/// @private -- Exclude this function from OpenCV documentation
264265
void apply(const std::vector<cv::Mat>& ins, // Compatibility overload
@@ -436,7 +437,11 @@ class GAPI_EXPORTS_W GComputation
436437
*
437438
* @sa @ref gapi_compile_args
438439
*/
439-
GAPI_WRAP GStreamingCompiled compileStreaming(GMetaArgs &&in_metas, GCompileArgs &&args = {});
440+
GStreamingCompiled compileStreaming(GMetaArgs &&in_metas, GCompileArgs &&args = {});
441+
442+
/// @private -- Exclude this function from OpenCV documentation
443+
GAPI_WRAP GStreamingCompiled compileStreaming(const cv::detail::ExtractMetaCallback &callback,
444+
GCompileArgs &&args = {});
440445

441446
/**
442447
* @brief Compile the computation for streaming mode.

modules/gapi/include/opencv2/gapi/gkernel.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct GTypeInfo
3030
{
3131
GShape shape;
3232
cv::detail::OpaqueKind kind;
33+
detail::HostCtor ctor;
3334
};
3435

3536
using GShapes = std::vector<GShape>;

modules/gapi/include/opencv2/gapi/gproto.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ GRunArg value_of(const GOrigin &origin);
135135
// Transform run-time computation arguments into a collection of metadata
136136
// extracted from that arguments
137137
GMetaArg GAPI_EXPORTS descr_of(const GRunArg &arg );
138-
GMetaArgs GAPI_EXPORTS_W descr_of(const GRunArgs &args);
138+
GMetaArgs GAPI_EXPORTS descr_of(const GRunArgs &args);
139139

140140
// Transform run-time operation result argument into metadata extracted from that argument
141141
// Used to compare the metadata, which generated at compile time with the metadata result operation in run time

modules/gapi/include/opencv2/gapi/gstreaming.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ class GAPI_EXPORTS_W_SIMPLE GStreamingCompiled
180180
* @param ins vector of inputs to process.
181181
* @sa gin
182182
*/
183-
GAPI_WRAP void setSource(GRunArgs &&ins);
183+
void setSource(GRunArgs &&ins);
184+
185+
/// @private -- Exclude this function from OpenCV documentation
186+
GAPI_WRAP void setSource(const cv::detail::ExtractArgsCallback& callback);
184187

185188
/**
186189
* @brief Specify an input video stream for a single-input
@@ -251,6 +254,7 @@ class GAPI_EXPORTS_W_SIMPLE GStreamingCompiled
251254
bool pull(cv::GRunArgsP &&outs);
252255

253256
// NB: Used from python
257+
/// @private -- Exclude this function from OpenCV documentation
254258
GAPI_WRAP std::tuple<bool, cv::GRunArgs> pull();
255259

256260
/**

modules/gapi/include/opencv2/gapi/imgproc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ if there are 2 channels, or have 2 columns if there is a single channel. Mat sho
11581158
@param src Input gray-scale image @ref CV_8UC1; or input set of @ref CV_32S or @ref CV_32F
11591159
2D points stored in Mat.
11601160
*/
1161-
GAPI_EXPORTS GOpaque<Rect> boundingRect(const GMat& src);
1161+
GAPI_EXPORTS_W GOpaque<Rect> boundingRect(const GMat& src);
11621162

11631163
/** @overload
11641164

modules/gapi/include/opencv2/gapi/infer/parsers.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ the larger side of the rectangle.
8585
@param filterOutOfBounds If provided true, out-of-frame boxes are filtered.
8686
@return a vector of detected bounding boxes.
8787
*/
88-
GAPI_EXPORTS GArray<Rect> parseSSD(const GMat& in,
89-
const GOpaque<Size>& inSz,
90-
const float confidenceThreshold = 0.5f,
91-
const bool alignmentToSquare = false,
92-
const bool filterOutOfBounds = false);
88+
GAPI_EXPORTS_W GArray<Rect> parseSSD(const GMat& in,
89+
const GOpaque<Size>& inSz,
90+
const float confidenceThreshold = 0.5f,
91+
const bool alignmentToSquare = false,
92+
const bool filterOutOfBounds = false);
9393

9494
/** @brief Parses output of Yolo network.
9595

0 commit comments

Comments
 (0)