718c41634f
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
|
|
'''
|
|
CUDA-accelerated Computer Vision functions
|
|
'''
|
|
|
|
# Python 2/3 compatibility
|
|
from __future__ import print_function
|
|
|
|
import numpy as np
|
|
import cv2 as cv
|
|
import os
|
|
|
|
from tests_common import NewOpenCVTests, unittest
|
|
|
|
class cuda_test(NewOpenCVTests):
|
|
def setUp(self):
|
|
super(cuda_test, self).setUp()
|
|
if not cv.cuda.getCudaEnabledDeviceCount():
|
|
self.skipTest("No CUDA-capable device is detected")
|
|
|
|
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)
|
|
|
|
if __name__ == '__main__':
|
|
NewOpenCVTests.bootstrap()
|