在 OpenCV 中,cv2.VideoWriter 类用于创建视频文件。当创建一个 cv2.VideoWriter 对象时,你可以通过多种方式指定其参数来控制视频的各种属性,如编码格式、帧率、尺寸等。下面是对 cv2.VideoWriter 的构造函数参数的详细介绍:
基本参数
filename (str): 要保存的视频文件的完整路径和文件名。
fourcc (int): 用于指定视频编码器的 4 字符编码。这个编码决定了视频的压缩格式。你可以通过 cv2.VideoWriter_fourcc 方法来获得这个编码,例如 cv2.VideoWriter_fourcc(‘M’, ‘J’, ‘P’, ‘G’)。
fps (float): 视频的帧率,即每秒钟显示的帧数。
frameSize (tuple of int): 视频帧的大小,格式为 (width, height)。
isColor (bool): 指定输出的视频是否为彩色。默认值为 True,表示输出彩色视频。如果设置为 False,则输出黑白视频。
fourcc(四字符代码)是一个用于指定视频编解码器的编码格式,用于确定视频文件的压缩方式。这个编码器标志是由四个字符组成的,用于在创建视频文件时定义编解码器的类型。在 OpenCV 中,你可以通过 cv2.VideoWriter_fourcc 函数来指定这个四字符代码。
常见的 fourcc 代码有:
DIVX: 使用 DivX 编码器。广泛支持,但主要用于 AVI 文件格式。
XVID: MPEG-4 编码标准,更开放和广泛支持。通常用于 AVI 文件,以及其他一些格式。
MJPG (Motion JPEG): 以 JPEG 格式逐帧压缩的视频,较大但编辑时较方便,支持跨平台。
X264: 高级视频编码(H.264),提供很好的压缩比,广泛用于 MP4 文件。
MP4V: MPEG-4 编码器。用于 MP4 文件,与 Apple QuickTime 兼容。
AVC1: 另一种表示 H.264 的方式。
WMV1, WMV2: Windows Media Video 版本 1 和 2,Microsoft 的视频压缩格式。
HUFF: 无损 HuffYUV 编码,用于保持视频质量但文件较大。
H264 / H265: H.264 或 H . 265 / H E V C H.265/HEVC H.265/HEVC,高效的视频压缩标准,适用于高清视频传输。
FLV1: 使用 Flash Video 格式,适合网络流媒体。
使用 cv2.VideoWriter_fourcc
OpenCV: 开源计算机视觉库
最近提交(Master分支:8 个月前 )
250b5003
Add image dimension check to avoid StereoSGBM non-determinism #27305
Addresses #25828
Users noticed that StereoSGBM would occasionally give non-deterministic results for `.compute(imgL, imgR)`.
I and others traced the cause to out-of-bounds access that was not being caught when the input images were not wide enough for the input block size and number of disparities to StereoSGBM. The specific math and logic can be found in the above issue's discussion.
This PR adds a CV_Check to make sure images are wider than 1/2 of the block size + the max disparity the algorithm will search.
The check was only added to the regular `compute` method for StereoSGBM and not to the other modes, as I did not observe the non-deterministic behavior with the other compute modes like HH.
In addition, this PR adds a test case to Calib3d to make sure the check is being thrown in the problem case and that the results are deterministic in the good case.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
1 天前
9201ca1a
Make sure to not access outside normDiffTabMake sure to not access outside normDiffTab #27321
If the norm is outside the array (e.g. Hamming), memory is read outside of the array, which does not matter because the invalid pointer is not used oustide of the function (e.g. the Hamming path is taken) but it triggers the sanitizer.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
1 天前
所有评论(0)