示例代码2(不全,项目中用到的,功能多一些)
# 写视频是否使能
writeVideo_flag = True
# writeVideo_flag = False
#写视频相关操作
if writeVideo_flag:
# Define the codec and create VideoWriter object
w1 = 1280 # 返回视频的宽
h1 = 720 # 返回视频的高
fourcc = cv2.VideoWriter_fourcc(*'MJPG') # avi格式
# fourcc = cv2.VideoWriter_fourcc(*'mp4v')#MP4格式
# out = cv2.VideoWriter('./output/'+args["input"][43:57]+ "_" + args["class"] + '_output.avi', fourcc, 15, (w, h))
out = cv2.VideoWriter('./vedio_out/' + "mangdaojiance_0225" + '_output.avi', fourcc, 30, (w1, h1))
project_outpath = 'vedio_out/0716.mp4'
# project_video_clip = VideoFileClip("0716.mp4")
#project_video_clip = VideoFileClip("vedio_input/0719_test1.mp4")
Frame_jiange = 1 # 每2帧取一幅图片
NumFrame = 0
video_capture = cv2.VideoCapture('vedio_input/0719_test1.mp4')
#video_capture = cv2.VideoCapture(1)
#video_capture = cv2.VideoCapture(0)
# 其中0表示打开内置摄像头,1表示打开外接摄像头
if video_capture.isOpened(): # VideoCaputre对象是否成功打开
print('打开摄像头或者视频成功')
readVideo_flag = True
else:
print('打开摄像头或者视频失败')
readVideo_flag = False
while readVideo_flag:
ret, frame00 = video_capture.read() # frame shape 640*480*3
if ret != True:
break
NumFrame = NumFrame + 1
if NumFrame % Frame_jiange == 0: # 取余每间隔 Frame_jiange 帧处理一次
project_video_out_clip=processing(frame00, object_points, img_points, M, Minv, left_line, right_line)
if writeVideo_flag:
#save a frame
out.write(project_video_out_clip)
参考:
https://blog.csdn.net/weixin_36670529/article/details/100977537