视频的读取和保存
import cv2
cap = cv2.VideoCapture(‘test.mp4’) # 写入自己的视频路径
fourcc = cv2.VideoWriter_fourcc(*‘XVID’)
fps =cap.get(cv2.CAP_PROP_FPS)
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
out = cv2.VideoWriter(’./output.avi’,fourcc, fps, size) # 输出视频路径
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
# 读取并播放视频
import cv2 as cv
cap = cv.VideoCapture(’*.avi’) # 写入自己的视频路径
FPS = cap.get(cv.CAP_PROP_FPS)
print(FPS)
delay = int(1000/FPS)
while cap.isOpened():
ret, fra