python-opencv 将连续图片写成视频格式的方法
程序员文章站
2023-12-10 10:27:22
如下所示:
import cv2
import os
#图片路径
im_dir = '/home/suanfa/data/out/20170823150...
如下所示:
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
以上这篇python-opencv 将连续图片写成视频格式的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。