1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-16 13:57:05 +08:00

Fixed several test failures in Python tests for CUDA modules.

This commit is contained in:
Alexander Smorkalov
2023-07-20 10:58:38 +03:00
parent 9dfe233020
commit a06aecea95
2 changed files with 18 additions and 14 deletions

View File

@@ -38,7 +38,7 @@ class cudacodec_test(NewOpenCVTests):
# Pass VideoReaderInitParams to the decoder and initialization params to the source (cv::VideoCapture)
params = cv.cudacodec.VideoReaderInitParams()
params.rawMode = True
params.enableHistogramOutput = True
params.enableHistogram = False
ms_gs = 1234
post_processed_sz = (gpu_mat.size()[0]*2, gpu_mat.size()[1]*2)
params.targetSz = post_processed_sz
@@ -48,14 +48,12 @@ class cudacodec_test(NewOpenCVTests):
ret, raw_mode = reader.getVideoReaderProps(cv.cudacodec.VideoReaderProps_PROP_RAW_MODE)
self.assertTrue(ret and raw_mode)
# Retrieve image histogram
# Retrieve image histogram. Not all GPUs support histogram. Just check the method is called correctly
ret, gpu_mat, hist = reader.nextFrameWithHist()
self.assertTrue(ret and not gpu_mat.empty() and hist.size() == (256,1))
self.assertTrue(ret and not gpu_mat.empty())
ret, gpu_mat_, hist_ = reader.nextFrameWithHist(gpu_mat, hist)
self.assertTrue(ret and not gpu_mat.empty() and hist.size() == (256,1))
self.assertTrue(gpu_mat_.cudaPtr() == gpu_mat.cudaPtr() and hist_.cudaPtr() == hist.cudaPtr())
hist_host = cv.cudacodec.MapHist(hist)
self.assertTrue(hist_host.shape == (1,256) and isinstance(hist_host, np.ndarray))
self.assertTrue(ret and not gpu_mat.empty())
self.assertTrue(gpu_mat_.cudaPtr() == gpu_mat.cudaPtr())
# Check post processing applied
self.assertTrue(gpu_mat.size() == post_processed_sz)
@@ -93,6 +91,12 @@ class cudacodec_test(NewOpenCVTests):
else:
self.skipTest(e.err)
def test_map_histogram(self):
hist = cv.cuda_GpuMat((1,256), cv.CV_8UC1)
hist.setTo(1)
hist_host = cv.cudacodec.MapHist(hist)
self.assertTrue(hist_host.shape == (256, 1) and isinstance(hist_host, np.ndarray))
def test_writer(self):
# Test the functionality but not the results of the VideoWriter
@@ -122,4 +126,4 @@ class cudacodec_test(NewOpenCVTests):
os.remove(fname)
if __name__ == '__main__':
NewOpenCVTests.bootstrap()
NewOpenCVTests.bootstrap()

View File

@@ -22,15 +22,15 @@ class nvidiaopticalflow_test(NewOpenCVTests):
cuMat1 = cv.cuda_GpuMat(npMat1)
cuMat2 = cv.cuda_GpuMat(npMat2)
try:
nvof = cv.cuda_NvidiaOpticalFlow_1_0.create(cuMat1.shape[1], cuMat1.shape[0], 5, False, False, False, 0)
flow = nvof.calc(cuMat1, cuMat2, None)
self.assertTrue(flow.shape[1] > 0 and flow.shape[0] > 0)
flowUpSampled = nvof.upSampler(flow[0], cuMat1.shape[1], cuMat1.shape[0], nvof.getGridSize(), None)
nvof = cv.cuda_NvidiaOpticalFlow_1_0.create((npMat1.shape[1], npMat1.shape[0]), 5, False, False, False, 0)
flow, cost = nvof.calc(cuMat1, cuMat2, None)
self.assertTrue(flow.size()[1] > 0 and flow.size()[0] > 0)
flowUpSampled = nvof.upSampler(flow, (npMat1.shape[1], npMat1.shape[0]), nvof.getGridSize(), None)
nvof.collectGarbage()
self.assertTrue(flowUpSampled.size()[1] > 0 and flowUpSampled.size()[0] > 0)
except cv.error as e:
if e.code == cv.Error.StsBadFunc or e.code == cv.Error.StsBadArg or e.code == cv.Error.StsNullPtr:
self.skipTest("Algorithm is not supported in the current environment")
self.assertTrue(flowUpSampled.shape[1] > 0 and flowUpSampled.shape[0] > 0)
if __name__ == '__main__':
NewOpenCVTests.bootstrap()
NewOpenCVTests.bootstrap()