|
|
|
@ -131,7 +131,8 @@ PyObject* pyopencv_from(const cv::detail::PyObjectHolder& v) |
|
|
|
|
template <> |
|
|
|
|
PyObject* pyopencv_from(const cv::gapi::wip::draw::Prim& prim) |
|
|
|
|
{ |
|
|
|
|
switch (prim.index()) { |
|
|
|
|
switch (prim.index()) |
|
|
|
|
{ |
|
|
|
|
case cv::gapi::wip::draw::Prim::index_of<cv::gapi::wip::draw::Rect>(): |
|
|
|
|
return pyopencv_from(cv::util::get<cv::gapi::wip::draw::Rect>(prim)); |
|
|
|
|
case cv::gapi::wip::draw::Prim::index_of<cv::gapi::wip::draw::Text>(): |
|
|
|
@ -319,40 +320,69 @@ PyObject* pyopencv_from(const GRunArg& v) |
|
|
|
|
return pyopencv_from(util::get<cv::detail::OpaqueRef>(v)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Failed to unpack GRunArgs"); |
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Failed to unpack GRunArgs. Index of variant is unknown"); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
PyObject* pyopencv_from(const GRunArgs& value) |
|
|
|
|
template <typename T> |
|
|
|
|
PyObject* pyopencv_from(const cv::optional<T>& opt) |
|
|
|
|
{ |
|
|
|
|
size_t i, n = value.size(); |
|
|
|
|
if (!opt.has_value()) |
|
|
|
|
{ |
|
|
|
|
Py_RETURN_NONE; |
|
|
|
|
} |
|
|
|
|
return pyopencv_from(*opt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NB: It doesn't make sense to return list with a single element
|
|
|
|
|
if (n == 1) |
|
|
|
|
template <> |
|
|
|
|
PyObject* pyopencv_from(const GOptRunArg& v) |
|
|
|
|
{ |
|
|
|
|
switch (v.index()) |
|
|
|
|
{ |
|
|
|
|
PyObject* item = pyopencv_from(value[0]); |
|
|
|
|
if(!item) |
|
|
|
|
{ |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
return item; |
|
|
|
|
case GOptRunArg::index_of<cv::optional<cv::Mat>>(): |
|
|
|
|
return pyopencv_from(util::get<cv::optional<cv::Mat>>(v)); |
|
|
|
|
|
|
|
|
|
case GOptRunArg::index_of<cv::optional<cv::Scalar>>(): |
|
|
|
|
return pyopencv_from(util::get<cv::optional<cv::Scalar>>(v)); |
|
|
|
|
|
|
|
|
|
case GOptRunArg::index_of<optional<cv::detail::VectorRef>>(): |
|
|
|
|
return pyopencv_from(util::get<optional<cv::detail::VectorRef>>(v)); |
|
|
|
|
|
|
|
|
|
case GOptRunArg::index_of<optional<cv::detail::OpaqueRef>>(): |
|
|
|
|
return pyopencv_from(util::get<optional<cv::detail::OpaqueRef>>(v)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PyObject* list = PyList_New(n); |
|
|
|
|
for(i = 0; i < n; ++i) |
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Failed to unpack GOptRunArg. Index of variant is unknown"); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
PyObject* pyopencv_from(const GRunArgs& value) |
|
|
|
|
{ |
|
|
|
|
return value.size() == 1 ? pyopencv_from(value[0]) : pyopencv_from_generic_vec(value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
PyObject* pyopencv_from(const GOptRunArgs& value) |
|
|
|
|
{ |
|
|
|
|
return value.size() == 1 ? pyopencv_from(value[0]) : pyopencv_from_generic_vec(value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// FIXME: cv::variant should be wrapped once for all types.
|
|
|
|
|
template <> |
|
|
|
|
PyObject* pyopencv_from(const cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>& v) |
|
|
|
|
{ |
|
|
|
|
using RunArgs = cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>; |
|
|
|
|
switch (v.index()) |
|
|
|
|
{ |
|
|
|
|
PyObject* item = pyopencv_from(value[i]); |
|
|
|
|
if(!item) |
|
|
|
|
{ |
|
|
|
|
Py_DECREF(list); |
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Failed to unpack GRunArgs"); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
PyList_SetItem(list, i, item); |
|
|
|
|
case RunArgs::index_of<cv::GRunArgs>(): |
|
|
|
|
return pyopencv_from(util::get<cv::GRunArgs>(v)); |
|
|
|
|
case RunArgs::index_of<cv::GOptRunArgs>(): |
|
|
|
|
return pyopencv_from(util::get<cv::GOptRunArgs>(v)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Failed to recognize kind of RunArgs. Index of variant is unknown"); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
@ -634,7 +664,8 @@ static cv::GRunArgs run_py_kernel(cv::detail::PyObjectHolder kernel, |
|
|
|
|
cv::detail::PyObjectHolder result( |
|
|
|
|
PyObject_CallObject(kernel.get(), args.get()), false); |
|
|
|
|
|
|
|
|
|
if (PyErr_Occurred()) { |
|
|
|
|
if (PyErr_Occurred()) |
|
|
|
|
{ |
|
|
|
|
PyErr_PrintEx(0); |
|
|
|
|
PyErr_Clear(); |
|
|
|
|
throw std::logic_error("Python kernel failed with error!"); |
|
|
|
@ -717,8 +748,9 @@ static cv::GMetaArgs get_meta_args(PyObject* tuple) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static GMetaArgs run_py_meta(cv::detail::PyObjectHolder out_meta, |
|
|
|
|
const cv::GMetaArgs &meta, |
|
|
|
|
const cv::GArgs &gargs) { |
|
|
|
|
const cv::GMetaArgs &meta, |
|
|
|
|
const cv::GArgs &gargs) |
|
|
|
|
{ |
|
|
|
|
PyGILState_STATE gstate; |
|
|
|
|
gstate = PyGILState_Ensure(); |
|
|
|
|
|
|
|
|
@ -760,7 +792,8 @@ static GMetaArgs run_py_meta(cv::detail::PyObjectHolder out_meta, |
|
|
|
|
cv::detail::PyObjectHolder result( |
|
|
|
|
PyObject_CallObject(out_meta.get(), args.get()), false); |
|
|
|
|
|
|
|
|
|
if (PyErr_Occurred()) { |
|
|
|
|
if (PyErr_Occurred()) |
|
|
|
|
{ |
|
|
|
|
PyErr_PrintEx(0); |
|
|
|
|
PyErr_Clear(); |
|
|
|
|
throw std::logic_error("Python outMeta failed with error!"); |
|
|
|
@ -792,21 +825,24 @@ static PyObject* pyopencv_cv_gapi_kernels(PyObject* , PyObject* py_args, PyObjec |
|
|
|
|
PyObject* user_kernel = PyTuple_GetItem(py_args, i); |
|
|
|
|
|
|
|
|
|
PyObject* id_obj = PyObject_GetAttrString(user_kernel, "id"); |
|
|
|
|
if (!id_obj) { |
|
|
|
|
if (!id_obj) |
|
|
|
|
{ |
|
|
|
|
PyErr_SetString(PyExc_TypeError, |
|
|
|
|
"Python kernel should contain id, please use cv.gapi.kernel to define kernel"); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PyObject* out_meta = PyObject_GetAttrString(user_kernel, "outMeta"); |
|
|
|
|
if (!out_meta) { |
|
|
|
|
if (!out_meta) |
|
|
|
|
{ |
|
|
|
|
PyErr_SetString(PyExc_TypeError, |
|
|
|
|
"Python kernel should contain outMeta, please use cv.gapi.kernel to define kernel"); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PyObject* run = PyObject_GetAttrString(user_kernel, "run"); |
|
|
|
|
if (!run) { |
|
|
|
|
if (!run) |
|
|
|
|
{ |
|
|
|
|
PyErr_SetString(PyExc_TypeError, |
|
|
|
|
"Python kernel should contain run, please use cv.gapi.kernel to define kernel"); |
|
|
|
|
return NULL; |
|
|
|
@ -951,9 +987,12 @@ struct PyOpenCV_Converter<cv::GArray<T>> |
|
|
|
|
if (PyObject_TypeCheck(obj, reinterpret_cast<PyTypeObject*>(pyopencv_GArrayT_TypePtr))) |
|
|
|
|
{ |
|
|
|
|
auto& array = reinterpret_cast<pyopencv_GArrayT_t*>(obj)->v; |
|
|
|
|
try { |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
value = cv::util::get<cv::GArray<T>>(array.arg()); |
|
|
|
|
} catch (...) { |
|
|
|
|
} |
|
|
|
|
catch (...) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
@ -974,9 +1013,12 @@ struct PyOpenCV_Converter<cv::GOpaque<T>> |
|
|
|
|
if (PyObject_TypeCheck(obj, reinterpret_cast<PyTypeObject*>(pyopencv_GOpaqueT_TypePtr))) |
|
|
|
|
{ |
|
|
|
|
auto& opaque = reinterpret_cast<pyopencv_GOpaqueT_t*>(obj)->v; |
|
|
|
|
try { |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
value = cv::util::get<cv::GOpaque<T>>(opaque.arg()); |
|
|
|
|
} catch (...) { |
|
|
|
|
} |
|
|
|
|
catch (...) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|