0. VideoCapture
- VideoCapture:构造函数;
常见成员函数:
open:打开视频文件,或者捕获视频设备,该函数会首先调用 release() 函数以关闭已打开的文件或设备;
Python: cv2.VideoCapture.open(filename) → retval Python: cv2.VideoCapture.open(device) → retval
isOpened:
- release:关闭已打开的文件或设备;
grab:从视频文件或者设备中抓取下一帧;
cv2.VideoCapture.grab() → retval
retrieve:解码并返回以抓取的视频帧;
cv2.VideoCapture.retrieve([image[, channel]]) → retval, image
get:获取指定的属性值;
cv2.VideoCapture.get(propId) → retval
set
1. VideoWriter
VideoWriter([filename, fourcc, fps, frameSize[, isColor]]) -> <VideoWriter object>
参数解释:
- fps:帧率,但 opencv 但未提供一个直接计算 camera 帧率的 api,因此需要手动计算(读取的帧数/用时)
fourcc:Four-Character Codes,
CV_FOURCC(‘P’, ‘I’, ‘M’, ‘1’) = MPEG-1 codec
CV_FOURCC(‘M’, ‘J’, ‘P’, ‘G’) = motion-jpeg codec
CV_FOURCC(‘M’, ‘P’, ‘4’, ‘2’) = MPEG-4.2 codec
CV_FOURCC(‘D’, ‘I’, ‘V’, ‘3’) = MPEG-4.3 codec
CV_FOURCC(‘D’, ‘I’, ‘V’, ‘X’) = MPEG-4 codec
CV_FOURCC(‘U’, ‘2’, ‘6’, ‘3’) = H263 codec
CV_FOURCC(‘I’, ‘2’, ‘6’, ‘3’) = H263I codec
CV_FOURCC(‘F’, ‘L’, ‘V’, ‘1’) = FLV1 codec