1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#!/usr/bin/env python
""" """
__author__ = "Théo de la Hogue"
__credits__ = []
__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "BSD"
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()
|