Skip to content

Commit 508c8db

Browse files
committed
Merge pull request #3196 from cudawarped:expose_cudacodec_format_to_python
2 parents dd8be23 + 54d1ae0 commit 508c8db

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

modules/cudacodec/include/opencv2/cudacodec.hpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,25 @@ enum DeinterlaceMode
290290

291291
/** @brief Struct providing information about video file format. :
292292
*/
293-
struct FormatInfo
293+
struct CV_EXPORTS_W_SIMPLE FormatInfo
294294
{
295-
Codec codec;
296-
ChromaFormat chromaFormat;
297-
int nBitDepthMinus8 = -1;
298-
int ulWidth = 0;//!< Coded sequence width in pixels.
299-
int ulHeight = 0;//!< Coded sequence height in pixels.
300-
int width = 0;//!< Width of the decoded frame returned by nextFrame(frame).
301-
int height = 0;//!< Height of the decoded frame returned by nextFrame(frame).
302-
int ulMaxWidth = 0;
303-
int ulMaxHeight = 0;
304-
Rect displayArea;//!< ROI inside the decoded frame returned by nextFrame(frame), containing the useable video frame.
305-
bool valid = false;
306-
double fps = 0;
307-
int ulNumDecodeSurfaces = 0;//!< Maximum number of internal decode surfaces.
308-
DeinterlaceMode deinterlaceMode;
295+
CV_WRAP FormatInfo() : nBitDepthMinus8(-1), ulWidth(0), ulHeight(0), width(0), height(0), ulMaxWidth(0), ulMaxHeight(0), valid(false),
296+
fps(0), ulNumDecodeSurfaces(0) {};
297+
298+
CV_PROP_RW Codec codec;
299+
CV_PROP_RW ChromaFormat chromaFormat;
300+
CV_PROP_RW int nBitDepthMinus8;
301+
CV_PROP_RW int ulWidth;//!< Coded sequence width in pixels.
302+
CV_PROP_RW int ulHeight;//!< Coded sequence height in pixels.
303+
CV_PROP_RW int width;//!< Width of the decoded frame returned by nextFrame(frame).
304+
CV_PROP_RW int height;//!< Height of the decoded frame returned by nextFrame(frame).
305+
int ulMaxWidth;
306+
int ulMaxHeight;
307+
CV_PROP_RW Rect displayArea;//!< ROI inside the decoded frame returned by nextFrame(frame), containing the useable video frame.
308+
CV_PROP_RW bool valid;
309+
CV_PROP_RW double fps;
310+
CV_PROP_RW int ulNumDecodeSurfaces;//!< Maximum number of internal decode surfaces.
311+
CV_PROP_RW DeinterlaceMode deinterlaceMode;
309312
};
310313

311314
/** @brief cv::cudacodec::VideoReader generic properties identifier.
@@ -342,7 +345,7 @@ class CV_EXPORTS_W VideoReader
342345

343346
/** @brief Returns information about video file format.
344347
*/
345-
virtual FormatInfo format() const = 0;
348+
CV_WRAP virtual FormatInfo format() const = 0;
346349

347350
/** @brief Grabs the next frame from the video source.
348351

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ def test_reader(self):
1919
vid_path = os.environ['OPENCV_TEST_DATA_PATH'] + '/cv/video/1920x1080.avi'
2020
try:
2121
reader = cv.cudacodec.createVideoReader(vid_path)
22+
format_info = reader.format()
2223
ret, gpu_mat = reader.nextFrame()
2324
self.assertTrue(ret)
2425
self.assertTrue('GpuMat' in str(type(gpu_mat)), msg=type(gpu_mat))
2526
#TODO: print(cv.utils.dumpInputArray(gpu_mat)) # - no support for GpuMat
2627

28+
if(not format_info.valid):
29+
format_info = reader.format()
30+
sz = gpu_mat.size()
31+
self.assertTrue(sz[0] == format_info.width and sz[1] == format_info.height)
32+
2733
# not checking output, therefore sepearate tests for different signatures is unecessary
2834
ret, _gpu_mat2 = reader.nextFrame(gpu_mat)
2935
#TODO: self.assertTrue(gpu_mat == gpu_mat2)

0 commit comments

Comments
 (0)