cv.VideoWriter(),其功能主要是创建一个对象,来写入视频。
import numpy as np
import cv2 as cv
cap=cv.VideoCapture(0)
fourcc=cv.VideoWriter_fourcc(*'XVID')
video_writer=cv.VideoWriter('output.avi',fourcc,30.0,(600,450))
while cap.isOpened():
ret,frame=cap.read()
if not ret:
break
frame=cv.flip(frame,1)
video_writer.write(frame) #将一帧写入
cv.imshow('frame',frame)
if cv.waitKey(1)==ord('q'):
break
cap.release()
video_writer.release()
cv.destroyAllWindows()