Python 图片转视频

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)
posted @ 2020-04-14 09:46  willwuss  阅读(1339)  评论(0编辑  收藏  举报