Merge pull request #17493 from TolyaTalamanov:at/python-bindings-gapi

* Implement G-API python bindings

* Fix hdr_parser

* Drop initlization with brackets using regexp

* Handle bracket initilization another way

* Add test for core operations

* Declaration and definition of View constructor now in different files

* Refactor tests

* Remove combine decorator from tests

* Fix comment to review

* Fix test

* Fix comments to review

* Remove GCompilerArgs implementation from python

Co-authored-by: Pinaev <danil.pinaev@intel.com>
This commit is contained in:
Anatoliy Talamanov
2020-07-29 16:18:52 +03:00
committed by GitHub
parent afe9993376
commit c708f506a4
18 changed files with 128 additions and 24 deletions
@@ -0,0 +1,13 @@
using gapi_GKernelPackage = cv::gapi::GKernelPackage;
template<>
bool pyopencv_to(PyObject* obj, std::vector<GCompileArg>& value, const ArgInfo& info)
{
return pyopencv_to_generic_vec(obj, value, info);
}
template<>
PyObject* pyopencv_from(const std::vector<GCompileArg>& value)
{
return pyopencv_from_generic_vec(value);
}
+7
View File
@@ -0,0 +1,7 @@
#error This is a shadow header file, which is not intended for processing by any compiler. \
Only bindings parser should handle this file.
namespace cv
{
GAPI_EXPORTS_W GCompileArgs compile_args(gapi::GKernelPackage pkg);
} // namespace cv
@@ -0,0 +1,42 @@
#!/usr/bin/env python
import numpy as np
import cv2 as cv
from tests_common import NewOpenCVTests
# Plaidml is an optional backend
pkgs = [
cv.gapi.core.ocl.kernels(),
cv.gapi.core.cpu.kernels(),
cv.gapi.core.fluid.kernels()
# cv.gapi.core.plaidml.kernels()
]
class gapi_core_test(NewOpenCVTests):
def test_add(self):
# TODO: Extend to use any type and size here
sz = (1280, 720)
in1 = np.random.randint(0, 100, sz).astype(np.uint8)
in2 = np.random.randint(0, 100, sz).astype(np.uint8)
# OpenCV
expected = in1 + in2
# G-API
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)
for pkg in pkgs:
actual = comp.apply(in1, in2, args=cv.compile_args(pkg))
# Comparison
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
if __name__ == '__main__':
NewOpenCVTests.bootstrap()