mirror of
https://github.com/zebrajr/opencv.git
synced 2025-12-06 12:19:50 +01:00
Merge pull request #20555 from TolyaTalamanov:at/fix-compileStreaming-bug
[G-API] Extend compileStreaming to support different overloads * Make different overloads * Order python compileStreaming overloads * Fix compileStreaming bug * Replace gin -> descr_of * Set error message * Fix review comments * Use macros for pyopencv_to GMetaArgs * Use GAPI_PROP_RW * Not split Prims python stuff
This commit is contained in:
parent
fdaa6ff9e3
commit
5ad6ff239b
|
|
@ -437,11 +437,7 @@ public:
|
||||||
*
|
*
|
||||||
* @sa @ref gapi_compile_args
|
* @sa @ref gapi_compile_args
|
||||||
*/
|
*/
|
||||||
GStreamingCompiled compileStreaming(GMetaArgs &&in_metas, GCompileArgs &&args = {});
|
GAPI_WRAP GStreamingCompiled compileStreaming(GMetaArgs &&in_metas, GCompileArgs &&args = {});
|
||||||
|
|
||||||
/// @private -- Exclude this function from OpenCV documentation
|
|
||||||
GAPI_WRAP GStreamingCompiled compileStreaming(const cv::detail::ExtractMetaCallback &callback,
|
|
||||||
GCompileArgs &&args = {});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compile the computation for streaming mode.
|
* @brief Compile the computation for streaming mode.
|
||||||
|
|
@ -464,6 +460,10 @@ public:
|
||||||
*/
|
*/
|
||||||
GAPI_WRAP GStreamingCompiled compileStreaming(GCompileArgs &&args = {});
|
GAPI_WRAP GStreamingCompiled compileStreaming(GCompileArgs &&args = {});
|
||||||
|
|
||||||
|
/// @private -- Exclude this function from OpenCV documentation
|
||||||
|
GAPI_WRAP GStreamingCompiled compileStreaming(const cv::detail::ExtractMetaCallback &callback,
|
||||||
|
GCompileArgs &&args = {});
|
||||||
|
|
||||||
// 2. Direct metadata version
|
// 2. Direct metadata version
|
||||||
/**
|
/**
|
||||||
* @overload
|
* @overload
|
||||||
|
|
|
||||||
|
|
@ -396,9 +396,11 @@ namespace streaming {
|
||||||
* In the streaming mode the pipeline steps are connected with queues
|
* In the streaming mode the pipeline steps are connected with queues
|
||||||
* and this compile argument controls every queue's size.
|
* and this compile argument controls every queue's size.
|
||||||
*/
|
*/
|
||||||
struct GAPI_EXPORTS queue_capacity
|
struct GAPI_EXPORTS_W_SIMPLE queue_capacity
|
||||||
{
|
{
|
||||||
|
GAPI_WRAP
|
||||||
explicit queue_capacity(size_t cap = 1) : capacity(cap) { };
|
explicit queue_capacity(size_t cap = 1) : capacity(cap) { };
|
||||||
|
GAPI_PROP_RW
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
};
|
};
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
||||||
|
|
@ -295,3 +295,5 @@ cv.gapi.wip.draw.Line = cv.gapi_wip_draw_Line
|
||||||
cv.gapi.wip.draw.Mosaic = cv.gapi_wip_draw_Mosaic
|
cv.gapi.wip.draw.Mosaic = cv.gapi_wip_draw_Mosaic
|
||||||
cv.gapi.wip.draw.Image = cv.gapi_wip_draw_Image
|
cv.gapi.wip.draw.Image = cv.gapi_wip_draw_Image
|
||||||
cv.gapi.wip.draw.Poly = cv.gapi_wip_draw_Poly
|
cv.gapi.wip.draw.Poly = cv.gapi_wip_draw_Poly
|
||||||
|
|
||||||
|
cv.gapi.streaming.queue_capacity = cv.gapi_streaming_queue_capacity
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,14 @@
|
||||||
#include <opencv2/gapi/python/python.hpp>
|
#include <opencv2/gapi/python/python.hpp>
|
||||||
|
|
||||||
// NB: Python wrapper replaces :: with _ for classes
|
// NB: Python wrapper replaces :: with _ for classes
|
||||||
using gapi_GKernelPackage = cv::gapi::GKernelPackage;
|
using gapi_GKernelPackage = cv::gapi::GKernelPackage;
|
||||||
using gapi_GNetPackage = cv::gapi::GNetPackage;
|
using gapi_GNetPackage = cv::gapi::GNetPackage;
|
||||||
using gapi_ie_PyParams = cv::gapi::ie::PyParams;
|
using gapi_ie_PyParams = cv::gapi::ie::PyParams;
|
||||||
using gapi_wip_IStreamSource_Ptr = cv::Ptr<cv::gapi::wip::IStreamSource>;
|
using gapi_wip_IStreamSource_Ptr = cv::Ptr<cv::gapi::wip::IStreamSource>;
|
||||||
using detail_ExtractArgsCallback = cv::detail::ExtractArgsCallback;
|
using detail_ExtractArgsCallback = cv::detail::ExtractArgsCallback;
|
||||||
using detail_ExtractMetaCallback = cv::detail::ExtractMetaCallback;
|
using detail_ExtractMetaCallback = cv::detail::ExtractMetaCallback;
|
||||||
using vector_GNetParam = std::vector<cv::gapi::GNetParam>;
|
using vector_GNetParam = std::vector<cv::gapi::GNetParam>;
|
||||||
|
using gapi_streaming_queue_capacity = cv::gapi::streaming::queue_capacity;
|
||||||
|
|
||||||
// NB: Python wrapper generate T_U for T<U>
|
// NB: Python wrapper generate T_U for T<U>
|
||||||
// This behavior is only observed for inputs
|
// This behavior is only observed for inputs
|
||||||
|
|
@ -159,7 +160,7 @@ PyObject* pyopencv_from(const cv::gapi::wip::draw::Prims& value)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
bool pyopencv_to(PyObject* obj, cv::gapi::wip::draw::Prim& value, const ArgInfo& info)
|
bool pyopencv_to(PyObject* obj, cv::gapi::wip::draw::Prim& value, const ArgInfo&)
|
||||||
{
|
{
|
||||||
#define TRY_EXTRACT(Prim) \
|
#define TRY_EXTRACT(Prim) \
|
||||||
if (PyObject_TypeCheck(obj, reinterpret_cast<PyTypeObject*>(pyopencv_gapi_wip_draw_##Prim##_TypePtr))) \
|
if (PyObject_TypeCheck(obj, reinterpret_cast<PyTypeObject*>(pyopencv_gapi_wip_draw_##Prim##_TypePtr))) \
|
||||||
|
|
@ -175,6 +176,7 @@ bool pyopencv_to(PyObject* obj, cv::gapi::wip::draw::Prim& value, const ArgInfo&
|
||||||
TRY_EXTRACT(Mosaic)
|
TRY_EXTRACT(Mosaic)
|
||||||
TRY_EXTRACT(Image)
|
TRY_EXTRACT(Image)
|
||||||
TRY_EXTRACT(Poly)
|
TRY_EXTRACT(Poly)
|
||||||
|
#undef TRY_EXTRACT
|
||||||
|
|
||||||
failmsg("Unsupported primitive type");
|
failmsg("Unsupported primitive type");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -186,6 +188,34 @@ bool pyopencv_to(PyObject* obj, cv::gapi::wip::draw::Prims& value, const ArgInfo
|
||||||
return pyopencv_to_generic_vec(obj, value, info);
|
return pyopencv_to_generic_vec(obj, value, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
bool pyopencv_to(PyObject* obj, cv::GMetaArg& value, const ArgInfo&)
|
||||||
|
{
|
||||||
|
#define TRY_EXTRACT(Meta) \
|
||||||
|
if (PyObject_TypeCheck(obj, \
|
||||||
|
reinterpret_cast<PyTypeObject*>(pyopencv_##Meta##_TypePtr))) \
|
||||||
|
{ \
|
||||||
|
value = reinterpret_cast<pyopencv_##Meta##_t*>(obj)->v; \
|
||||||
|
return true; \
|
||||||
|
} \
|
||||||
|
|
||||||
|
TRY_EXTRACT(GMatDesc)
|
||||||
|
TRY_EXTRACT(GScalarDesc)
|
||||||
|
TRY_EXTRACT(GArrayDesc)
|
||||||
|
TRY_EXTRACT(GOpaqueDesc)
|
||||||
|
#undef TRY_EXTRACT
|
||||||
|
|
||||||
|
failmsg("Unsupported cv::GMetaArg type");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
bool pyopencv_to(PyObject* obj, cv::GMetaArgs& value, const ArgInfo& info)
|
||||||
|
{
|
||||||
|
return pyopencv_to_generic_vec(obj, value, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
PyObject* pyopencv_from(const cv::GArg& value)
|
PyObject* pyopencv_from(const cv::GArg& value)
|
||||||
{
|
{
|
||||||
|
|
@ -707,30 +737,12 @@ static cv::GRunArgs run_py_kernel(cv::detail::PyObjectHolder kernel,
|
||||||
|
|
||||||
static GMetaArg get_meta_arg(PyObject* obj)
|
static GMetaArg get_meta_arg(PyObject* obj)
|
||||||
{
|
{
|
||||||
if (PyObject_TypeCheck(obj,
|
cv::GMetaArg arg;
|
||||||
reinterpret_cast<PyTypeObject*>(pyopencv_GMatDesc_TypePtr)))
|
if (!pyopencv_to(obj, arg, ArgInfo("arg", false)))
|
||||||
{
|
|
||||||
return cv::GMetaArg{reinterpret_cast<pyopencv_GMatDesc_t*>(obj)->v};
|
|
||||||
}
|
|
||||||
else if (PyObject_TypeCheck(obj,
|
|
||||||
reinterpret_cast<PyTypeObject*>(pyopencv_GScalarDesc_TypePtr)))
|
|
||||||
{
|
|
||||||
return cv::GMetaArg{reinterpret_cast<pyopencv_GScalarDesc_t*>(obj)->v};
|
|
||||||
}
|
|
||||||
else if (PyObject_TypeCheck(obj,
|
|
||||||
reinterpret_cast<PyTypeObject*>(pyopencv_GArrayDesc_TypePtr)))
|
|
||||||
{
|
|
||||||
return cv::GMetaArg{reinterpret_cast<pyopencv_GArrayDesc_t*>(obj)->v};
|
|
||||||
}
|
|
||||||
else if (PyObject_TypeCheck(obj,
|
|
||||||
reinterpret_cast<PyTypeObject*>(pyopencv_GOpaqueDesc_TypePtr)))
|
|
||||||
{
|
|
||||||
return cv::GMetaArg{reinterpret_cast<pyopencv_GOpaqueDesc_t*>(obj)->v};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
util::throw_error(std::logic_error("Unsupported output meta type"));
|
util::throw_error(std::logic_error("Unsupported output meta type"));
|
||||||
}
|
}
|
||||||
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cv::GMetaArgs get_meta_args(PyObject* tuple)
|
static cv::GMetaArgs get_meta_args(PyObject* tuple)
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ namespace cv
|
||||||
{
|
{
|
||||||
struct GAPI_EXPORTS_W_SIMPLE GCompileArg
|
struct GAPI_EXPORTS_W_SIMPLE GCompileArg
|
||||||
{
|
{
|
||||||
GAPI_WRAP GCompileArg(gapi::GKernelPackage pkg);
|
GAPI_WRAP GCompileArg(gapi::GKernelPackage arg);
|
||||||
GAPI_WRAP GCompileArg(gapi::GNetPackage pkg);
|
GAPI_WRAP GCompileArg(gapi::GNetPackage arg);
|
||||||
|
GAPI_WRAP GCompileArg(gapi::streaming::queue_capacity arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
class GAPI_EXPORTS_W_SIMPLE GInferInputs
|
class GAPI_EXPORTS_W_SIMPLE GInferInputs
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,7 @@ try:
|
||||||
if curr_frame_number == max_num_frames:
|
if curr_frame_number == max_num_frames:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def test_desync(self):
|
def test_desync(self):
|
||||||
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
||||||
|
|
||||||
|
|
@ -307,6 +308,49 @@ try:
|
||||||
self.assertLess(0, none_counter)
|
self.assertLess(0, none_counter)
|
||||||
|
|
||||||
|
|
||||||
|
def test_compile_streaming_empty(self):
|
||||||
|
g_in = cv.GMat()
|
||||||
|
comp = cv.GComputation(g_in, cv.gapi.medianBlur(g_in, 3))
|
||||||
|
comp.compileStreaming()
|
||||||
|
|
||||||
|
|
||||||
|
def test_compile_streaming_args(self):
|
||||||
|
g_in = cv.GMat()
|
||||||
|
comp = cv.GComputation(g_in, cv.gapi.medianBlur(g_in, 3))
|
||||||
|
comp.compileStreaming(cv.gapi.compile_args(cv.gapi.streaming.queue_capacity(1)))
|
||||||
|
|
||||||
|
|
||||||
|
def test_compile_streaming_descr_of(self):
|
||||||
|
g_in = cv.GMat()
|
||||||
|
comp = cv.GComputation(g_in, cv.gapi.medianBlur(g_in, 3))
|
||||||
|
img = np.zeros((3,300,300), dtype=np.float32)
|
||||||
|
comp.compileStreaming(cv.gapi.descr_of(img))
|
||||||
|
|
||||||
|
|
||||||
|
def test_compile_streaming_descr_of_and_args(self):
|
||||||
|
g_in = cv.GMat()
|
||||||
|
comp = cv.GComputation(g_in, cv.gapi.medianBlur(g_in, 3))
|
||||||
|
img = np.zeros((3,300,300), dtype=np.float32)
|
||||||
|
comp.compileStreaming(cv.gapi.descr_of(img),
|
||||||
|
cv.gapi.compile_args(cv.gapi.streaming.queue_capacity(1)))
|
||||||
|
|
||||||
|
|
||||||
|
def test_compile_streaming_meta(self):
|
||||||
|
g_in = cv.GMat()
|
||||||
|
comp = cv.GComputation(g_in, cv.gapi.medianBlur(g_in, 3))
|
||||||
|
img = np.zeros((3,300,300), dtype=np.float32)
|
||||||
|
comp.compileStreaming([cv.GMatDesc(cv.CV_8U, 3, (300, 300))])
|
||||||
|
|
||||||
|
|
||||||
|
def test_compile_streaming_meta_and_args(self):
|
||||||
|
g_in = cv.GMat()
|
||||||
|
comp = cv.GComputation(g_in, cv.gapi.medianBlur(g_in, 3))
|
||||||
|
img = np.zeros((3,300,300), dtype=np.float32)
|
||||||
|
comp.compileStreaming([cv.GMatDesc(cv.CV_8U, 3, (300, 300))],
|
||||||
|
cv.gapi.compile_args(cv.gapi.streaming.queue_capacity(1)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
except unittest.SkipTest as e:
|
except unittest.SkipTest as e:
|
||||||
|
|
||||||
message = str(e)
|
message = str(e)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user