mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 03:00:14 +08:00
Merge pull request #18512 from TolyaTalamanov:at/fix-untyped-np-array-for-gapi-python
[G-API] Numpy array with int64 failed in cv.gin * Fix bug with numpy array precision in G-API python * Fix comments to review
This commit is contained in:
parent
39d5e14c1f
commit
537494f4dd
@ -128,7 +128,7 @@ static PyObject* pyopencv_cv_gin(PyObject* , PyObject* py_args, PyObject* kw)
|
||||
if (PyTuple_Check(item))
|
||||
{
|
||||
cv::Scalar s;
|
||||
if (pyopencv_to(item, s, ArgInfo("scalar", true)))
|
||||
if (pyopencv_to(item, s, ArgInfo("scalar", false)))
|
||||
{
|
||||
args.emplace_back(s);
|
||||
}
|
||||
@ -141,7 +141,7 @@ static PyObject* pyopencv_cv_gin(PyObject* , PyObject* py_args, PyObject* kw)
|
||||
else if (PyArray_Check(item))
|
||||
{
|
||||
cv::Mat m;
|
||||
if (pyopencv_to(item, m, ArgInfo("mat", true)))
|
||||
if (pyopencv_to(item, m, ArgInfo("mat", false)))
|
||||
{
|
||||
args.emplace_back(m);
|
||||
}
|
||||
|
@ -20,11 +20,11 @@ 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)
|
||||
in1 = np.random.randint(0, 100, sz)
|
||||
in2 = np.random.randint(0, 100, sz)
|
||||
|
||||
# OpenCV
|
||||
expected = in1 + in2
|
||||
expected = cv.add(in1, in2)
|
||||
|
||||
# G-API
|
||||
g_in1 = cv.GMat()
|
||||
@ -36,11 +36,33 @@ class gapi_core_test(NewOpenCVTests):
|
||||
actual = comp.apply(cv.gin(in1, in2), args=cv.compile_args(pkg))
|
||||
# Comparison
|
||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||
self.assertEqual(expected.dtype, actual.dtype)
|
||||
|
||||
|
||||
def test_add_uint8(self):
|
||||
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 = cv.add(in1, in2)
|
||||
|
||||
# G-API
|
||||
g_in1 = cv.GMat()
|
||||
g_in2 = cv.GMat()
|
||||
g_out = cv.gapi.add(g_in1, g_in2)
|
||||
comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out))
|
||||
|
||||
for pkg in pkgs:
|
||||
actual = comp.apply(cv.gin(in1, in2), args=cv.compile_args(pkg))
|
||||
# Comparison
|
||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||
self.assertEqual(expected.dtype, actual.dtype)
|
||||
|
||||
|
||||
def test_mean(self):
|
||||
sz = (1280, 720, 3)
|
||||
in_mat = np.random.randint(0, 100, sz).astype(np.uint8)
|
||||
in_mat = np.random.randint(0, 100, sz)
|
||||
|
||||
# OpenCV
|
||||
expected = cv.mean(in_mat)
|
||||
@ -58,7 +80,7 @@ class gapi_core_test(NewOpenCVTests):
|
||||
|
||||
def test_split3(self):
|
||||
sz = (1280, 720, 3)
|
||||
in_mat = np.random.randint(0, 100, sz).astype(np.uint8)
|
||||
in_mat = np.random.randint(0, 100, sz)
|
||||
|
||||
# OpenCV
|
||||
expected = cv.split(in_mat)
|
||||
@ -73,6 +95,7 @@ class gapi_core_test(NewOpenCVTests):
|
||||
# Comparison
|
||||
for e, a in zip(expected, actual):
|
||||
self.assertEqual(0.0, cv.norm(e, a, cv.NORM_INF))
|
||||
self.assertEqual(e.dtype, a.dtype)
|
||||
|
||||
|
||||
def test_threshold(self):
|
||||
@ -94,6 +117,7 @@ class gapi_core_test(NewOpenCVTests):
|
||||
actual_mat, actual_thresh = comp.apply(cv.gin(in_mat, maxv), args=cv.compile_args(pkg))
|
||||
# Comparison
|
||||
self.assertEqual(0.0, cv.norm(expected_mat, actual_mat, cv.NORM_INF))
|
||||
self.assertEqual(expected_mat.dtype, actual_mat.dtype)
|
||||
self.assertEqual(expected_thresh, actual_thresh[0])
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user