python-opencv 将连续图片写成视频格式


import cv2
import os

#图片路径
im_dir = '/home/suanfa/data/out/201708231503440'
#输出视频路径
video_dir = '/home/suanfa/data/out/201708231503440-1018.avi'
#帧率
fps = 30  
#图片数 
num = 426
#图片尺寸
img_size = (841,1023)

#fourcc = cv2.cv.CV_FOURCC('M','J','P','G')#opencv2.4
fourcc = cv2.VideoWriter_fourcc('M','J','P','G') #opencv3.0
videoWriter = cv2.VideoWriter(video_dir, fourcc, fps, img_size)

for i in range(1,num):
    im_name = os.path.join(im_dir, str(i).zfill(6)+'.jpg')
    frame = cv2.imread(im_name)
    videoWriter.write(frame)
    print im_name

videoWriter.release()
print 'finish'

注意:
图片路径下的图片命名格式为
000001.jpg 000002.jpg ……. 00100.jpg……

opencv2.选择

fourcc = cv2.cv.CV_FOURCC('M','J','P','G')#opencv2.4

opencv3.选择

fourcc = cv2.VideoWriter_fourcc('M','J','P','G') #opencv3.0
展开阅读全文

没有更多推荐了,返回首页