test_cudacodec.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python
  2. import os
  3. import cv2 as cv
  4. import numpy as np
  5. from tests_common import NewOpenCVTests, unittest
  6. class cudacodec_test(NewOpenCVTests):
  7. def setUp(self):
  8. super(cudacodec_test, self).setUp()
  9. if not cv.cuda.getCudaEnabledDeviceCount():
  10. self.skipTest("No CUDA-capable device is detected")
  11. @unittest.skipIf('OPENCV_TEST_DATA_PATH' not in os.environ,
  12. "OPENCV_TEST_DATA_PATH is not defined")
  13. def test_reader(self):
  14. #Test the functionality but not the results of the video reader
  15. vid_path = os.environ['OPENCV_TEST_DATA_PATH'] + '/cv/video/1920x1080.avi'
  16. try:
  17. reader = cv.cudacodec.createVideoReader(vid_path)
  18. ret, gpu_mat = reader.nextFrame()
  19. self.assertTrue(ret)
  20. self.assertTrue('GpuMat' in str(type(gpu_mat)), msg=type(gpu_mat))
  21. #TODO: print(cv.utils.dumpInputArray(gpu_mat)) # - no support for GpuMat
  22. # not checking output, therefore sepearate tests for different signatures is unecessary
  23. ret, _gpu_mat2 = reader.nextFrame(gpu_mat)
  24. #TODO: self.assertTrue(gpu_mat == gpu_mat2)
  25. self.assertTrue(ret)
  26. except cv.error as e:
  27. notSupported = (e.code == cv.Error.StsNotImplemented or e.code == cv.Error.StsUnsupportedFormat or e.code == cv.Error.GPU_API_CALL_ERROR)
  28. self.assertTrue(notSupported)
  29. if e.code == cv.Error.StsNotImplemented:
  30. self.skipTest("NVCUVID is not installed")
  31. elif e.code == cv.Error.StsUnsupportedFormat:
  32. self.skipTest("GPU hardware video decoder missing or video format not supported")
  33. elif e.code == cv.Error.GPU_API_CALL_ERRROR:
  34. self.skipTest("GPU hardware video decoder is missing")
  35. else:
  36. self.skipTest(e.err)
  37. def test_writer_existence(self):
  38. #Test at least the existence of wrapped functions for now
  39. try:
  40. _writer = cv.cudacodec.createVideoWriter("tmp", (128, 128), 30)
  41. except cv.error as e:
  42. self.assertEqual(e.code, cv.Error.StsNotImplemented)
  43. self.skipTest("NVCUVENC is not installed")
  44. self.assertTrue(True) #It is sufficient that no exceptions have been there
  45. if __name__ == '__main__':
  46. NewOpenCVTests.bootstrap()