文件夹内照片拼接为视频
import cv2
import os
size = (1920,1080)#视频尺寸,需要与组成的图像一致
fourcc = cv2.VideoWriter_fourcc('D', 'I', 'V', 'X')
videowrite = cv2.VideoWriter(r'C:\Users\syg310\Desktop\dair-video\concat3.mp4',fourcc,25,size)#25是帧数,size是图片尺寸
img_list=[]
filepath = r'C:\Users\syg310\Desktop\dair-video'
for filename in os.listdir(filepath):#获取文件夹下所有文件名称
#print(filename)
img = cv2.imread(filepath+'/'+filename)
if img is None:
print(filename + " 缺失!")
continue#继续吧,视频少一帧没什么所谓
img_list.append(img)
for i in range(2730):#把图片写入视频,2730为图片的个数
videowrite.write(img_list[i])
videowrite.release()
print('图像整合成功')