




















使用 cv2.VideoCapture 类
Args:
vc = cv2.VideoCapture(filename)
使用 VideoCapture 对象的 isOpened 方法
# determine whether to open normally
if vc.isOpened():
ret, frame = vc.read()
else:
ret = False
若成功,返回 True。
使用 VideoCapture 对象的 read 方法
使用 VideoCapture 对象的 read 方法按帧读取视频,ret, frame 是 read 方法的两个返回值 ,其中 ret 是布尔值,如果能正确读取帧,则返回 True;如果文件读取到结尾,它的返回值就为 False。frame 就是每一帧的图像,是一个三维矩阵。
# loop read video frame
while ret:
ret, frame = vc.read()
使用 cv2.imwrite() 函数
第一个参数是文件名,第二个参数是图片资源。
cv2.imwrite(image_path, image)
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。