如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
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.选择
1
|
fourcc = cv2.cv.CV_FOURCC( 'M' , 'J' , 'P' , 'G' ) #opencv2.4
|
opencv3.选择
1
|
fourcc = cv2.VideoWriter_fourcc( 'M' , 'J' , 'P' , 'G' ) #opencv3.0
|
以上这篇python-opencv 将连续图片写成视频格式的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/u011440558/article/details/78272629