From a06aecea955b1fa571cfa0302ffc8faeda85c48f Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 20 Jul 2023 10:58:38 +0300 Subject: [PATCH] Fixed several test failures in Python tests for CUDA modules. --- .../misc/python/test/test_cudacodec.py | 20 +++++++++++-------- .../python/test/test_nvidiaopticalflow.py | 12 +++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/cudacodec/misc/python/test/test_cudacodec.py b/modules/cudacodec/misc/python/test/test_cudacodec.py index 1e5d3755c..cf20daeb1 100644 --- a/modules/cudacodec/misc/python/test/test_cudacodec.py +++ b/modules/cudacodec/misc/python/test/test_cudacodec.py @@ -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() \ No newline at end of file + NewOpenCVTests.bootstrap() diff --git a/modules/cudaoptflow/misc/python/test/test_nvidiaopticalflow.py b/modules/cudaoptflow/misc/python/test/test_nvidiaopticalflow.py index 94822c408..7ba6abd01 100644 --- a/modules/cudaoptflow/misc/python/test/test_nvidiaopticalflow.py +++ b/modules/cudaoptflow/misc/python/test/test_nvidiaopticalflow.py @@ -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() \ No newline at end of file + NewOpenCVTests.bootstrap()