综述
python 从图片变为视频
代码
import cv2
import numpy as np
import os
from os.path import isfile, join
pathIn= './im3/' # img sequence 注意: 您的index应该为诸如 : 1.png 2.png 之类
pathOut = 'videoscans_10000_smooth_7.avi'
fps = 7
frame_array = []
files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
#for sorting the file names properly
files.sort(key= lambda x:int(x[:-4]))
frame_array = []
for i in range(len(files)):
filename = pathIn + files[i]
# reading each files
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width, height)
# inserting the frames into an image array
frame_array.append(img)
out = cv2.VideoWriter(pathOut, cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
for i in range(len(frame_array)):
# writing to a image array
out.write(frame_array[i])
out.release()