Skip to content

Commit 4899bee

Browse files
authored
Merge pull request #3535 from asmorkalov:as/cuda_pytest_stabilization
Fixed several test failures in Python tests for CUDA modules
2 parents 9dfe233 + a06aece commit 4899bee

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

modules/cudacodec/misc/python/test/test_cudacodec.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_reader(self):
3838
# Pass VideoReaderInitParams to the decoder and initialization params to the source (cv::VideoCapture)
3939
params = cv.cudacodec.VideoReaderInitParams()
4040
params.rawMode = True
41-
params.enableHistogramOutput = True
41+
params.enableHistogram = False
4242
ms_gs = 1234
4343
post_processed_sz = (gpu_mat.size()[0]*2, gpu_mat.size()[1]*2)
4444
params.targetSz = post_processed_sz
@@ -48,14 +48,12 @@ def test_reader(self):
4848
ret, raw_mode = reader.getVideoReaderProps(cv.cudacodec.VideoReaderProps_PROP_RAW_MODE)
4949
self.assertTrue(ret and raw_mode)
5050

51-
# Retrieve image histogram
51+
# Retrieve image histogram. Not all GPUs support histogram. Just check the method is called correctly
5252
ret, gpu_mat, hist = reader.nextFrameWithHist()
53-
self.assertTrue(ret and not gpu_mat.empty() and hist.size() == (256,1))
53+
self.assertTrue(ret and not gpu_mat.empty())
5454
ret, gpu_mat_, hist_ = reader.nextFrameWithHist(gpu_mat, hist)
55-
self.assertTrue(ret and not gpu_mat.empty() and hist.size() == (256,1))
56-
self.assertTrue(gpu_mat_.cudaPtr() == gpu_mat.cudaPtr() and hist_.cudaPtr() == hist.cudaPtr())
57-
hist_host = cv.cudacodec.MapHist(hist)
58-
self.assertTrue(hist_host.shape == (1,256) and isinstance(hist_host, np.ndarray))
55+
self.assertTrue(ret and not gpu_mat.empty())
56+
self.assertTrue(gpu_mat_.cudaPtr() == gpu_mat.cudaPtr())
5957

6058
# Check post processing applied
6159
self.assertTrue(gpu_mat.size() == post_processed_sz)
@@ -93,6 +91,12 @@ def test_reader(self):
9391
else:
9492
self.skipTest(e.err)
9593

94+
def test_map_histogram(self):
95+
hist = cv.cuda_GpuMat((1,256), cv.CV_8UC1)
96+
hist.setTo(1)
97+
hist_host = cv.cudacodec.MapHist(hist)
98+
self.assertTrue(hist_host.shape == (256, 1) and isinstance(hist_host, np.ndarray))
99+
96100
def test_writer(self):
97101
# Test the functionality but not the results of the VideoWriter
98102

@@ -122,4 +126,4 @@ def test_writer(self):
122126
os.remove(fname)
123127

124128
if __name__ == '__main__':
125-
NewOpenCVTests.bootstrap()
129+
NewOpenCVTests.bootstrap()

modules/cudaoptflow/misc/python/test/test_nvidiaopticalflow.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ def test_calc(self):
2222
cuMat1 = cv.cuda_GpuMat(npMat1)
2323
cuMat2 = cv.cuda_GpuMat(npMat2)
2424
try:
25-
nvof = cv.cuda_NvidiaOpticalFlow_1_0.create(cuMat1.shape[1], cuMat1.shape[0], 5, False, False, False, 0)
26-
flow = nvof.calc(cuMat1, cuMat2, None)
27-
self.assertTrue(flow.shape[1] > 0 and flow.shape[0] > 0)
28-
flowUpSampled = nvof.upSampler(flow[0], cuMat1.shape[1], cuMat1.shape[0], nvof.getGridSize(), None)
25+
nvof = cv.cuda_NvidiaOpticalFlow_1_0.create((npMat1.shape[1], npMat1.shape[0]), 5, False, False, False, 0)
26+
flow, cost = nvof.calc(cuMat1, cuMat2, None)
27+
self.assertTrue(flow.size()[1] > 0 and flow.size()[0] > 0)
28+
flowUpSampled = nvof.upSampler(flow, (npMat1.shape[1], npMat1.shape[0]), nvof.getGridSize(), None)
2929
nvof.collectGarbage()
30+
self.assertTrue(flowUpSampled.size()[1] > 0 and flowUpSampled.size()[0] > 0)
3031
except cv.error as e:
3132
if e.code == cv.Error.StsBadFunc or e.code == cv.Error.StsBadArg or e.code == cv.Error.StsNullPtr:
3233
self.skipTest("Algorithm is not supported in the current environment")
33-
self.assertTrue(flowUpSampled.shape[1] > 0 and flowUpSampled.shape[0] > 0)
3434

3535
if __name__ == '__main__':
36-
NewOpenCVTests.bootstrap()
36+
NewOpenCVTests.bootstrap()

0 commit comments

Comments
 (0)