mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-19 02:16:34 +08:00
cudacodec: return luma hist from VideoReader::nextFrame if requested
This commit is contained in:
@@ -14,36 +14,53 @@ class cudacodec_test(NewOpenCVTests):
|
||||
@unittest.skipIf('OPENCV_TEST_DATA_PATH' not in os.environ,
|
||||
"OPENCV_TEST_DATA_PATH is not defined")
|
||||
def test_reader(self):
|
||||
#Test the functionality but not the results of the video reader
|
||||
# Test the functionality but not the results of the VideoReader
|
||||
|
||||
vid_path = os.environ['OPENCV_TEST_DATA_PATH'] + '/cv/video/1920x1080.avi'
|
||||
vid_path = os.environ['OPENCV_TEST_DATA_PATH'] + '/highgui/video/big_buck_bunny.h264'
|
||||
try:
|
||||
reader = cv.cudacodec.createVideoReader(vid_path)
|
||||
format_info = reader.format()
|
||||
ret, gpu_mat = reader.nextFrame()
|
||||
self.assertTrue(ret)
|
||||
self.assertTrue('GpuMat' in str(type(gpu_mat)), msg=type(gpu_mat))
|
||||
self.assertTrue(isinstance(gpu_mat, cv.cuda.GpuMat), msg=type(gpu_mat))
|
||||
#TODO: print(cv.utils.dumpInputArray(gpu_mat)) # - no support for GpuMat
|
||||
|
||||
# Retrieve format info
|
||||
if(not format_info.valid):
|
||||
format_info = reader.format()
|
||||
sz = gpu_mat.size()
|
||||
self.assertTrue(sz[0] == format_info.width and sz[1] == format_info.height)
|
||||
|
||||
# not checking output, therefore sepearate tests for different signatures is unecessary
|
||||
ret, _gpu_mat2 = reader.nextFrame(gpu_mat)
|
||||
#TODO: self.assertTrue(gpu_mat == gpu_mat2)
|
||||
self.assertTrue(ret)
|
||||
ret, gpu_mat_ = reader.nextFrame(gpu_mat)
|
||||
self.assertTrue(ret and gpu_mat_.cudaPtr() == gpu_mat.cudaPtr())
|
||||
|
||||
# Pass VideoReaderInitParams to the decoder and initialization params to the source (cv::VideoCapture)
|
||||
params = cv.cudacodec.VideoReaderInitParams()
|
||||
params.rawMode = True
|
||||
params.enableHistogramOutput = True
|
||||
ms_gs = 1234
|
||||
post_processed_sz = (gpu_mat.size()[0]*2, gpu_mat.size()[1]*2)
|
||||
params.targetSz = post_processed_sz
|
||||
reader = cv.cudacodec.createVideoReader(vid_path,[cv.CAP_PROP_OPEN_TIMEOUT_MSEC, ms_gs], params)
|
||||
ret, ms = reader.get(cv.CAP_PROP_OPEN_TIMEOUT_MSEC)
|
||||
self.assertTrue(ret and ms == ms_gs)
|
||||
ret, raw_mode = reader.getVideoReaderProps(cv.cudacodec.VideoReaderProps_PROP_RAW_MODE)
|
||||
self.assertTrue(ret and raw_mode)
|
||||
|
||||
# Retrieve image histogram
|
||||
ret, gpu_mat, hist = reader.nextFrameWithHist()
|
||||
self.assertTrue(ret and not gpu_mat.empty() and hist.size() == (256,1))
|
||||
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))
|
||||
|
||||
# Check post processing applied
|
||||
self.assertTrue(gpu_mat.size() == post_processed_sz)
|
||||
|
||||
# Change color format
|
||||
ret, colour_code = reader.getVideoReaderProps(cv.cudacodec.VideoReaderProps_PROP_COLOR_FORMAT)
|
||||
self.assertTrue(ret and colour_code == cv.cudacodec.ColorFormat_BGRA)
|
||||
colour_code_gs = cv.cudacodec.ColorFormat_GRAY
|
||||
@@ -51,6 +68,7 @@ class cudacodec_test(NewOpenCVTests):
|
||||
ret, colour_code = reader.getVideoReaderProps(cv.cudacodec.VideoReaderProps_PROP_COLOR_FORMAT)
|
||||
self.assertTrue(ret and colour_code == colour_code_gs)
|
||||
|
||||
# Read raw encoded bitstream
|
||||
ret, i_base = reader.getVideoReaderProps(cv.cudacodec.VideoReaderProps_PROP_RAW_PACKAGES_BASE_INDEX)
|
||||
self.assertTrue(ret and i_base == 2.0)
|
||||
self.assertTrue(reader.grab())
|
||||
@@ -75,8 +93,8 @@ class cudacodec_test(NewOpenCVTests):
|
||||
else:
|
||||
self.skipTest(e.err)
|
||||
|
||||
def test_writer_existence(self):
|
||||
#Test at least the existence of wrapped functions for now
|
||||
def test_writer(self):
|
||||
# Test the functionality but not the results of the VideoWriter
|
||||
|
||||
try:
|
||||
fd, fname = tempfile.mkstemp(suffix=".h264")
|
||||
@@ -91,11 +109,12 @@ class cudacodec_test(NewOpenCVTests):
|
||||
writer.write(blankFrameIn)
|
||||
writer.release()
|
||||
encoder_params_out = writer.getEncoderParams()
|
||||
self.assert_true(encoder_params_in.gopLength == encoder_params_out.gopLength)
|
||||
self.assertTrue(encoder_params_in.gopLength == encoder_params_out.gopLength)
|
||||
cap = cv.VideoCapture(fname,cv.CAP_FFMPEG)
|
||||
self.assert_true(cap.isOpened())
|
||||
self.assertTrue(cap.isOpened())
|
||||
ret, blankFrameOut = cap.read()
|
||||
self.assert_true(ret and blankFrameOut.shape == blankFrameIn.download().shape)
|
||||
self.assertTrue(ret and blankFrameOut.shape == blankFrameIn.download().shape)
|
||||
cap.release()
|
||||
except cv.error as e:
|
||||
self.assertEqual(e.code, cv.Error.StsNotImplemented)
|
||||
self.skipTest("Either NVCUVENC or a GPU hardware encoder is missing or the encoding profile is not supported.")
|
||||
|
Reference in New Issue
Block a user