欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

多帧图像转为视频

程序员文章站 2022-03-31 20:54:06
...

使用的opencv版本是3.4,图片的名称为0001.jpg,0002.jpg,……2409.jpg.

import cv2

fps = 25   #视频帧率
fourcc = cv2.VideoWriter_fourcc('M','J','P','G')  
videoWriter = cv2.VideoWriter('/home/jianyuchen/flownet2-master/flownet2-tool/flow/video13.avi', fourcc, fps, (1280,720))   #(1360,480)为视频大小
for i in range(1,2410):
    if i<10:
        p1 = 'flow_y_000'
        p2 = i
        img = cv2.imread('/home/jianyuchen/flownet2-master/flownet2-tool/flow/video13/'+str(p1)+str(p2)+'.jpg')
    if 10<=i<100:
        p1 = 'flow_y_00'
        p2 = i
        img = cv2.imread('/home/jianyuchen/flownet2-master/flownet2-tool/flow/video13/'+str(p1)+str(p2)+'.jpg')
    if 100<=i<1000:
        p1 = 'flow_y_0'
        p2 = i
        img = cv2.imread('/home/jianyuchen/flownet2-master/flownet2-tool/flow/video13/'+str(p1)+str(p2)+'.jpg')
    if i>=1000:
        p1= 'flow_y_'
        p2 = i
        img = cv2.imread('/home/jianyuchen/flownet2-master/flownet2-tool/flow/video13/'+str(p1)+str(p2)+'.jpg')
#    cv2.imshow('img', img12)
#    cv2.waitKey(1000/int(fps))
    videoWriter.write(img)
videoWriter.release()