diff options
author | Théo de la Hogue | 2023-02-28 09:41:15 +0100 |
---|---|---|
committer | Théo de la Hogue | 2023-02-28 09:41:15 +0100 |
commit | ddd417ca84c5e16ba30c441598d209d190bf4ad3 (patch) | |
tree | ad75ba24d856f21d13efd460594b00e576deb322 /src | |
parent | b6c9eb85ab587766f4658e0ef75039f9094a9620 (diff) | |
download | argaze-ddd417ca84c5e16ba30c441598d209d190bf4ad3.zip argaze-ddd417ca84c5e16ba30c441598d209d190bf4ad3.tar.gz argaze-ddd417ca84c5e16ba30c441598d209d190bf4ad3.tar.bz2 argaze-ddd417ca84c5e16ba30c441598d209d190bf4ad3.tar.xz |
Adding test for opencv cuda
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze.test/OpenCVCuda.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/argaze.test/OpenCVCuda.py b/src/argaze.test/OpenCVCuda.py new file mode 100644 index 0000000..fd28abf --- /dev/null +++ b/src/argaze.test/OpenCVCuda.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +import unittest + +import numpy as np +import cv2 as cv +import os + +class cuda_test(unittest.TestCase): + """Test Cuda-accelerated OpenCV functions class.""" + + def test_setup(self): + + self.assertGreater(cv.cuda.getCudaEnabledDeviceCount(), 0) + + def test_cuda_upload_download(self): + + npMat = (np.random.random((128, 128, 3)) * 255).astype(np.uint8) + cuMat = cv.cuda_GpuMat() + cuMat.upload(npMat) + + 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() + cuMat.upload(npMat) + + self.assertTrue(cuMat.cudaPtr() != 0) + + stream = cv.cuda_Stream() + self.assertTrue(stream.cudaPtr() != 0) + + asyncstream = cv.cuda_Stream(1) # cudaStreamNonBlocking + self.assertTrue(asyncstream.cudaPtr() != 0) + + def test_cuda_buffer_pool(self): + + cv.cuda.setBufferPoolUsage(True) + cv.cuda.setBufferPoolConfig(cv.cuda.getDevice(), 1024 * 1024 * 64, 2) + stream_a = cv.cuda.Stream() + pool_a = cv.cuda.BufferPool(stream_a) + cuMat = pool_a.getBuffer(1024, 1024, cv.CV_8UC3) + cv.cuda.setBufferPoolUsage(False) + + self.assertEqual(cuMat.size(), (1024, 1024)) + self.assertEqual(cuMat.type(), cv.CV_8UC3) + + def test_cuda_release(self): + + npMat = (np.random.random((128, 128, 3)) * 255).astype(np.uint8) + cuMat = cv.cuda_GpuMat() + cuMat.upload(npMat) + cuMat.release() + + self.assertTrue(cuMat.cudaPtr() == 0) + self.assertTrue(cuMat.step == 0) + self.assertTrue(cuMat.size() == (0, 0)) + + def test_cuda_denoising(self): + + self.assertEqual(True, hasattr(cv.cuda, 'fastNlMeansDenoising')) + self.assertEqual(True, hasattr(cv.cuda, 'fastNlMeansDenoisingColored')) + self.assertEqual(True, hasattr(cv.cuda, 'nonLocalMeans')) + +if __name__ == '__main__': + + unittest.main()
\ No newline at end of file |