python opencv 把多张图片合成视频
# -*- coding: utf-8 -*- import os import cv2 def picToVideo(picDir,videoName): ##完成写入对象的创建,第一个参数是合成之后的视频的名称, #第二个参数是可以使用的编码器, #第三个参数是帧率即每秒钟展示多少张图片, #第四个参数是图片大小信息 # 设置写入格式 fourcc = cv2.VideoWriter_fourcc('M', 'P', '4', 'V') indexImg0 = cv2.imread("G:\\ACTION_2022062401\\2022062411240000.jpg") print(indexImg0.shape) videowrite = cv2.VideoWriter(videoName,fourcc,20,(indexImg0.shape[1],indexImg0.shape[0])) for rt, dirs, filesName in os.walk(picDir): print(dirs) print(filesName) print(rt) for indexFileName in filesName: indexFilePath = os.path.join('%s\\%s' % (rt, indexFileName)) #print(indexFilePath) indexImg = cv2.imread(indexFilePath) videowrite.write(indexImg) videowrite.release() print("--------------end----------") #picToVideo("G:\\ACTION_2022062401\\output_action_1","G:\\ACTION_2022062401\\1.mp4") picToVideo("G:\\ACTION_2022062401\\output_action_2","G:\\ACTION_2022062401\\2.mp4") #picToVideo("G:\\ACTION_2022062401\\output_action_3","G:\\ACTION_2022062401\\3.mp4")
###########################