""" """ """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ __author__ = "Théo de la Hogue" __credits__ = [] __copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" __license__ = "GPLv3" import unittest import numpy as np import cv2 as cv import os class cuda_test(unittest.TestCase): """Test Cuda-accelerated OpenCV functions class.""" @unittest.skipIf(cv.cuda.getCudaEnabledDeviceCount() == 0, "No cuda device found") 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)) @unittest.skipIf(cv.cuda.getCudaEnabledDeviceCount() == 0, "No cuda device found") 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)) @unittest.skipIf(cv.cuda.getCudaEnabledDeviceCount() == 0, "No cuda device found") 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) @unittest.skipIf(cv.cuda.getCudaEnabledDeviceCount() == 0, "No cuda device found") 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) @unittest.skipIf(cv.cuda.getCudaEnabledDeviceCount() == 0, "No cuda device found") 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)) @unittest.skipIf(cv.cuda.getCudaEnabledDeviceCount() == 0, "No cuda device found") 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()