mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 11:10:21 +08:00
Merge pull request #18332 from TolyaTalamanov:at/wrap-GIn-GOut
[G-API] Wrap GIn & GOut * Wrap GIn & GOut into python * Remove extra brackets * Use reinterpret_cast
This commit is contained in:
parent
ea4b491a73
commit
a07f064e50
@ -161,8 +161,8 @@ public:
|
||||
*
|
||||
* @sa @ref gapi_data_objects
|
||||
*/
|
||||
GComputation(GProtoInputArgs &&ins,
|
||||
GProtoOutputArgs &&outs); // Arg-to-arg overload
|
||||
GAPI_WRAP GComputation(GProtoInputArgs &&ins,
|
||||
GProtoOutputArgs &&outs); // Arg-to-arg overload
|
||||
|
||||
// 2. Syntax sugar and compatibility overloads
|
||||
/**
|
||||
|
@ -57,6 +57,8 @@ template<class Tag>
|
||||
struct GIOProtoArgs
|
||||
{
|
||||
public:
|
||||
// NB: Used by python wrapper
|
||||
GIOProtoArgs() = default;
|
||||
explicit GIOProtoArgs(const GProtoArgs& args) : m_args(args) {}
|
||||
explicit GIOProtoArgs(GProtoArgs &&args) : m_args(std::move(args)) {}
|
||||
|
||||
|
@ -11,3 +11,35 @@ PyObject* pyopencv_from(const std::vector<GCompileArg>& value)
|
||||
{
|
||||
return pyopencv_from_generic_vec(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static PyObject* extract_proto_args(PyObject* py_args, PyObject* kw)
|
||||
{
|
||||
using namespace cv;
|
||||
|
||||
GProtoArgs args;
|
||||
Py_ssize_t size = PyTuple_Size(py_args);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
PyObject* item = PyTuple_GetItem(py_args, i);
|
||||
if (PyObject_TypeCheck(item, reinterpret_cast<PyTypeObject*>(pyopencv_GScalar_TypePtr))) {
|
||||
args.emplace_back(reinterpret_cast<pyopencv_GScalar_t*>(item)->v);
|
||||
} else if (PyObject_TypeCheck(item, reinterpret_cast<PyTypeObject*>(pyopencv_GMat_TypePtr))) {
|
||||
args.emplace_back(reinterpret_cast<pyopencv_GMat_t*>(item)->v);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "cv.GIn() supports only cv.GMat and cv.GScalar");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return pyopencv_from<T>(T{std::move(args)});
|
||||
}
|
||||
|
||||
static PyObject* pyopencv_cv_GIn(PyObject* , PyObject* py_args, PyObject* kw)
|
||||
{
|
||||
return extract_proto_args<GProtoInputArgs>(py_args, kw);
|
||||
}
|
||||
|
||||
static PyObject* pyopencv_cv_GOut(PyObject* , PyObject* py_args, PyObject* kw)
|
||||
{
|
||||
return extract_proto_args<GProtoOutputArgs>(py_args, kw);
|
||||
}
|
||||
|
@ -4,4 +4,10 @@
|
||||
namespace cv
|
||||
{
|
||||
GAPI_EXPORTS_W GCompileArgs compile_args(gapi::GKernelPackage pkg);
|
||||
class GAPI_EXPORTS_W_SIMPLE GProtoArg { };
|
||||
class GAPI_EXPORTS_W_SIMPLE GProtoInputArgs { };
|
||||
class GAPI_EXPORTS_W_SIMPLE GProtoOutputArgs { };
|
||||
|
||||
using GProtoInputArgs = GIOProtoArgs<In_Tag>;
|
||||
using GProtoOutputArgs = GIOProtoArgs<Out_Tag>;
|
||||
} // namespace cv
|
||||
|
@ -30,7 +30,7 @@ class gapi_core_test(NewOpenCVTests):
|
||||
g_in1 = cv.GMat()
|
||||
g_in2 = cv.GMat()
|
||||
g_out = cv.gapi.add(g_in1, g_in2)
|
||||
comp = cv.GComputation(g_in1, g_in2, g_out)
|
||||
comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out))
|
||||
|
||||
for pkg in pkgs:
|
||||
actual = comp.apply(in1, in2, args=cv.compile_args(pkg))
|
||||
|
@ -1891,7 +1891,6 @@ static int convert_to_char(PyObject *o, char *dst, const ArgInfo& info)
|
||||
|
||||
|
||||
#include "pyopencv_generated_enums.h"
|
||||
#include "pyopencv_custom_headers.h"
|
||||
|
||||
#ifdef CVPY_DYNAMIC_INIT
|
||||
#define CVPY_TYPE(NAME, STORAGE, SNAME, _1, _2) CVPY_TYPE_DECLARE_DYNAMIC(NAME, STORAGE, SNAME)
|
||||
@ -1900,6 +1899,7 @@ static int convert_to_char(PyObject *o, char *dst, const ArgInfo& info)
|
||||
#endif
|
||||
#include "pyopencv_generated_types.h"
|
||||
#undef CVPY_TYPE
|
||||
#include "pyopencv_custom_headers.h"
|
||||
|
||||
#include "pyopencv_generated_types_content.h"
|
||||
#include "pyopencv_generated_funcs.h"
|
||||
@ -1915,6 +1915,10 @@ static PyMethodDef special_methods[] = {
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
{"dnn_registerLayer", CV_PY_FN_WITH_KW(pyopencv_cv_dnn_registerLayer), "registerLayer(type, class) -> None"},
|
||||
{"dnn_unregisterLayer", CV_PY_FN_WITH_KW(pyopencv_cv_dnn_unregisterLayer), "unregisterLayer(type) -> None"},
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_GAPI
|
||||
{"GIn", CV_PY_FN_WITH_KW(pyopencv_cv_GIn), "GIn(...) -> GInputProtoArgs"},
|
||||
{"GOut", CV_PY_FN_WITH_KW(pyopencv_cv_GOut), "GOut(...) -> GOutputProtoArgs"},
|
||||
#endif
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user