Commit b4a3c928 authored by cudawarped's avatar cudawarped Committed by Alexander Alekhin

Merge pull request #15957 from cudawarped:fix_cudacodec_python

Fix cudacodec python

* Add python bindings to cudacodec.

* Allow args with CV_OUT GpuMat& or CV_OUT cuda::GpuMat& to generate python bindings that allow the argument to be an optional output in the same way as OutputArray.

* Add wrapper flag to indicate that an OutputArray is a GpuMat.

* python: drop CV_GPU, extra checks in test

* Remove "cuda::GpuMat" check rom python parser
parent 72315e7b
...@@ -349,8 +349,7 @@ class ArgInfo(object): ...@@ -349,8 +349,7 @@ class ArgInfo(object):
self.py_outputarg = False self.py_outputarg = False
def isbig(self): def isbig(self):
return self.tp == "Mat" or self.tp == "vector_Mat" or self.tp == "cuda::GpuMat"\ return self.tp in ["Mat", "vector_Mat", "GpuMat", "UMat", "vector_UMat"] # or self.tp.startswith("vector")
or self.tp == "UMat" or self.tp == "vector_UMat" # or self.tp.startswith("vector")
def crepr(self): def crepr(self):
return "ArgInfo(\"%s\", %d)" % (self.name, self.outputarg) return "ArgInfo(\"%s\", %d)" % (self.name, self.outputarg)
......
...@@ -913,9 +913,9 @@ class CppHeaderParser(object): ...@@ -913,9 +913,9 @@ class CppHeaderParser(object):
else: else:
decls.append(decl) decls.append(decl)
if self._generate_gpumat_decls and "cv.cuda." in decl[0]: if self._generate_gpumat_decls and "cv.cuda" in decl[0]:
# If function takes as one of arguments Mat or vector<Mat> - we want to create the # If function takes as one of arguments Mat or vector<Mat> - we want to create the
# same declaration working with GpuMat (this is important for T-Api access) # same declaration working with GpuMat
args = decl[3] args = decl[3]
has_mat = len(list(filter(lambda x: x[0] in {"Mat", "vector_Mat"}, args))) > 0 has_mat = len(list(filter(lambda x: x[0] in {"Mat", "vector_Mat"}, args))) > 0
if has_mat: if has_mat:
......
...@@ -9,8 +9,9 @@ from __future__ import print_function ...@@ -9,8 +9,9 @@ from __future__ import print_function
import numpy as np import numpy as np
import cv2 as cv import cv2 as cv
import os
from tests_common import NewOpenCVTests from tests_common import NewOpenCVTests, unittest
class cuda_test(NewOpenCVTests): class cuda_test(NewOpenCVTests):
def setUp(self): def setUp(self):
...@@ -100,12 +101,40 @@ class cuda_test(NewOpenCVTests): ...@@ -100,12 +101,40 @@ class cuda_test(NewOpenCVTests):
self.assertTrue(True) #It is sufficient that no exceptions have been there self.assertTrue(True) #It is sufficient that no exceptions have been there
def test_cudacodec_existence(self): @unittest.skipIf('OPENCV_TEST_DATA_PATH' not in os.environ,
"OPENCV_TEST_DATA_PATH is not defined")
def test_cudacodec(self):
#Test the functionality but not the results of the video reader
vid_path = os.environ['OPENCV_TEST_DATA_PATH'] + '/cv/video/1920x1080.avi'
try:
reader = cv.cudacodec.createVideoReader(vid_path)
ret, gpu_mat = reader.nextFrame()
self.assertTrue(ret)
self.assertTrue('GpuMat' in str(type(gpu_mat)), msg=type(gpu_mat))
#TODO: print(cv.utils.dumpInputArray(gpu_mat)) # - no support for GpuMat
# not checking output, therefore sepearate tests for different signatures is unecessary
ret, _gpu_mat2 = reader.nextFrame(gpu_mat)
#TODO: self.assertTrue(gpu_mat == gpu_mat2)
self.assertTrue(ret)
except cv.error as e:
notSupported = (e.code == cv.Error.StsNotImplemented or e.code == cv.Error.StsUnsupportedFormat or e.code == cv.Error.GPU_API_CALL_ERROR)
self.assertTrue(notSupported)
if e.code == cv.Error.StsNotImplemented:
self.skipTest("NVCUVID is not installed")
elif e.code == cv.Error.StsUnsupportedFormat:
self.skipTest("GPU hardware video decoder missing or video format not supported")
elif e.code == cv.Error.GPU_API_CALL_ERRROR:
self.skipTest("GPU hardware video decoder is missing")
else:
self.skipTest(e.err)
def test_cudacodec_writer_existence(self):
#Test at least the existence of wrapped functions for now #Test at least the existence of wrapped functions for now
try: try:
_writer = cv.cudacodec.createVideoWriter("tmp", (128, 128), 30) _writer = cv.cudacodec.createVideoWriter("tmp", (128, 128), 30)
_reader = cv.cudacodec.createVideoReader("tmp")
except cv.error as e: except cv.error as e:
self.assertEqual(e.code, cv.Error.StsNotImplemented) self.assertEqual(e.code, cv.Error.StsNotImplemented)
self.skipTest("NVCUVENC is not installed") self.skipTest("NVCUVENC is not installed")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment