Stream default to Stream::Null() when no default in function prototype
authorDavid Geldreich <david.geldreich@free.fr>
Sat, 1 May 2021 01:18:14 +0000 (01:18 +0000)
committerDavid Geldreich <david.geldreich@free.fr>
Sat, 1 May 2021 10:03:28 +0000 (10:03 +0000)
this corrects bug #16592 where a Stream is created at
each GpuMat::load(arr,stream) call

a correct solution would have been to add a default to GpuMat::load
but due to circular dependence between Stream and GpuMat, this is not possible
add test_cuda_upload_download_stream to test_cuda.py

modules/python/src2/gen2.py
modules/python/test/test_cuda.py

index 1a9dfb8e68c4aa2727cc1437a41b71f2738a1fef..bb2acb26746698e0160a9f3f14e0c0bff5a6aa5b 100755 (executable)
@@ -211,6 +211,7 @@ simple_argtype_mapping = {
     "double": ArgTypeInfo("double", FormatStrings.double, "0", True),
     "c_string": ArgTypeInfo("char*", FormatStrings.string, '(char*)""'),
     "string": ArgTypeInfo("std::string", FormatStrings.object, None, True),
+    "Stream": ArgTypeInfo("Stream", FormatStrings.object, 'Stream::Null()', True),
 }
 
 
index 4bcd4108f14ca93e22543172d002a90d788e1cd0..4b3fc7d27815063e97f762c57ac1d6136785d283 100644 (file)
@@ -26,6 +26,15 @@ class cuda_test(NewOpenCVTests):
 
         self.assertTrue(np.allclose(cuMat.download(), npMat))
 
+    def test_cuda_upload_download_stream(self):
+        stream = cv.cuda_Stream()
+        npMat = (np.random.random((128, 128, 3)) * 255).astype(np.uint8)
+        cuMat = cv.cuda_GpuMat(128,128, cv.CV_8UC3)
+        cuMat.upload(npMat, stream)
+        npMat2 = cuMat.download(stream=stream)
+        stream.waitForCompletion()
+        self.assertTrue(np.allclose(npMat2, npMat))
+
     def test_cuda_interop(self):
         npMat = (np.random.random((128, 128, 3)) * 255).astype(np.uint8)
         cuMat = cv.cuda_GpuMat()