import cv2
from cv2 import VideoWriter, VideoWriter_fourcc, imread, resize
import os
from PIL import Image
def PicToVideo(imgPath, videoPath):
images = os.listdir(imgPath)
fps = 25 //帧数
fourcc = VideoWriter_fourcc(*"MJPG")
im = Image.open(imgPath + images[0])
videoWriter = cv2.VideoWriter(videoPath, fourcc, fps, im.size)
for im_name in range(len(images)):
frame = cv2.imread(imgPath + images[im_name])
print(im_name)
videoWriter.write(frame)
videoWriter.release()
imgPath = "J:/data/image/" //图像路径
videoPath = "J:/data/video.avi" //视频路径.avi
PicToVideo(imgPath, videoPath)