Merge pull request #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
This commit is contained in:
committed by
GitHub
parent
7bcb51eded
commit
eb82ba36a3
@@ -1608,13 +1608,53 @@ template<typename _Tp> static inline bool pyopencv_to_generic_vec(PyObject* obj,
|
||||
return true;
|
||||
}
|
||||
|
||||
template<> inline bool pyopencv_to_generic_vec(PyObject* obj, std::vector<bool>& value, const ArgInfo& info)
|
||||
{
|
||||
if(!obj || obj == Py_None)
|
||||
return true;
|
||||
if (!PySequence_Check(obj))
|
||||
return false;
|
||||
size_t n = PySequence_Size(obj);
|
||||
value.resize(n);
|
||||
for(size_t i = 0; i < n; i++ )
|
||||
{
|
||||
SafeSeqItem item_wrap(obj, i);
|
||||
bool elem{};
|
||||
if(!pyopencv_to(item_wrap.item, elem, info))
|
||||
return false;
|
||||
value[i] = elem;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename _Tp> static inline PyObject* pyopencv_from_generic_vec(const std::vector<_Tp>& value)
|
||||
{
|
||||
int i, n = (int)value.size();
|
||||
PyObject* seq = PyList_New(n);
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
PyObject* item = pyopencv_from(value[i]);
|
||||
_Tp elem = value[i];
|
||||
PyObject* item = pyopencv_from(elem);
|
||||
if(!item)
|
||||
break;
|
||||
PyList_SetItem(seq, i, item);
|
||||
}
|
||||
if( i < n )
|
||||
{
|
||||
Py_DECREF(seq);
|
||||
return 0;
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
template<> inline PyObject* pyopencv_from_generic_vec(const std::vector<bool>& value)
|
||||
{
|
||||
int i, n = (int)value.size();
|
||||
PyObject* seq = PyList_New(n);
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
bool elem = value[i];
|
||||
PyObject* item = pyopencv_from(elem);
|
||||
if(!item)
|
||||
break;
|
||||
PyList_SetItem(seq, i, item);
|
||||
@@ -2160,7 +2200,8 @@ static PyMethodDef special_methods[] = {
|
||||
#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"},
|
||||
{"gin", CV_PY_FN_WITH_KW(pyopencv_cv_gin), "gin(...) -> GRunArgs"},
|
||||
{"gin", CV_PY_FN_WITH_KW(pyopencv_cv_gin), "gin(...) -> ExtractArgsCallback"},
|
||||
{"descr_of", CV_PY_FN_WITH_KW(pyopencv_cv_descr_of), "descr_of(...) -> ExtractMetaCallback"},
|
||||
#endif
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user