#本节讲解视频的读取,显示和保存
# 1. cv2.VideoCapture()
# 有两种用法
# cv2.VideoCapture(filename)
# filename : 要打开的视频
# cv2.VideoCapture(device)
# device : 要打开的摄像头,如果要打开默认摄像头,则填 0 ,如笔记本自带的摄像头
import cv2
cap = cv2.VideoCapture('video_1.avi')
# 读取视频
# while(cap.isOpened()):
# ret, frame = cap.read()
# if ret == False:
# break
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# cv2.imshow('frame', gray)
# cv2.waitKey(10)
# k = cv2.waitKey(0)
#
# if k == 27:
# cap.release()
# cv2.destroyAllWindows()
# 保存视频
# 1.指定 FourCC 编码 FOURCC is short for "four character code"
# FOURCC是four character code“四个字符代码”的缩写
# -媒体文件中使用的视频编解码器,压缩格式,颜色或像素格式的标识符。
# FourCC 就是一个4字节码,用来确定视频的编码格式。
# 可用的编码可以查看 http://www.fourcc.org/codecs.php, 推荐使用 ”XVID"
fourcc = cv2.VideoWriter_fourcc(*'XVID')
# fourcc = cv2.VideoWriter_fourcc('X','V','I','D')
# def VideoWriter_fourcc(c1, c2, c3, c4): # real signature unknown; restored from __doc__
# """
# VideoWriter_fourcc
python + opencv 第三节 视频文件的读取和保存
最新推荐文章于 2025-10-07 20:13:51 发布

最低0.47元/天 解锁文章
1341

被折叠的 条评论
为什么被折叠?



