1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-18 08:44:11 +08:00

Merge pull request #3196 from cudawarped:expose_cudacodec_format_to_python

This commit is contained in:
Alexander Alekhin
2022-03-16 10:37:59 +00:00
2 changed files with 25 additions and 16 deletions

View File

@@ -290,22 +290,25 @@ enum DeinterlaceMode
/** @brief Struct providing information about video file format. :
*/
struct FormatInfo
struct CV_EXPORTS_W_SIMPLE FormatInfo
{
Codec codec;
ChromaFormat chromaFormat;
int nBitDepthMinus8 = -1;
int ulWidth = 0;//!< Coded sequence width in pixels.
int ulHeight = 0;//!< Coded sequence height in pixels.
int width = 0;//!< Width of the decoded frame returned by nextFrame(frame).
int height = 0;//!< Height of the decoded frame returned by nextFrame(frame).
int ulMaxWidth = 0;
int ulMaxHeight = 0;
Rect displayArea;//!< ROI inside the decoded frame returned by nextFrame(frame), containing the useable video frame.
bool valid = false;
double fps = 0;
int ulNumDecodeSurfaces = 0;//!< Maximum number of internal decode surfaces.
DeinterlaceMode deinterlaceMode;
CV_WRAP FormatInfo() : nBitDepthMinus8(-1), ulWidth(0), ulHeight(0), width(0), height(0), ulMaxWidth(0), ulMaxHeight(0), valid(false),
fps(0), ulNumDecodeSurfaces(0) {};
CV_PROP_RW Codec codec;
CV_PROP_RW ChromaFormat chromaFormat;
CV_PROP_RW int nBitDepthMinus8;
CV_PROP_RW int ulWidth;//!< Coded sequence width in pixels.
CV_PROP_RW int ulHeight;//!< Coded sequence height in pixels.
CV_PROP_RW int width;//!< Width of the decoded frame returned by nextFrame(frame).
CV_PROP_RW int height;//!< Height of the decoded frame returned by nextFrame(frame).
int ulMaxWidth;
int ulMaxHeight;
CV_PROP_RW Rect displayArea;//!< ROI inside the decoded frame returned by nextFrame(frame), containing the useable video frame.
CV_PROP_RW bool valid;
CV_PROP_RW double fps;
CV_PROP_RW int ulNumDecodeSurfaces;//!< Maximum number of internal decode surfaces.
CV_PROP_RW DeinterlaceMode deinterlaceMode;
};
/** @brief cv::cudacodec::VideoReader generic properties identifier.
@@ -342,7 +345,7 @@ public:
/** @brief Returns information about video file format.
*/
virtual FormatInfo format() const = 0;
CV_WRAP virtual FormatInfo format() const = 0;
/** @brief Grabs the next frame from the video source.

View File

@@ -19,11 +19,17 @@ class cudacodec_test(NewOpenCVTests):
vid_path = os.environ['OPENCV_TEST_DATA_PATH'] + '/cv/video/1920x1080.avi'
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))
#TODO: print(cv.utils.dumpInputArray(gpu_mat)) # - no support for GpuMat
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)