**
可以在ubuntu使用,前提:图像名称是6位按顺序的数字
**
# encoding:utf-8
import cv2
import os
# 图片路径
im_dir = '/home/dj/PycharmProjects/YOLODataProcess/sickfece2img/batchpro/outimg/1'
# 输出视频路径
video_dir = '1.avi'
# 帧率
fps = 25
# 图片数
num = 650
# 图片尺寸
img_size = (2560, 1440)
# 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