根据视频帧导出mp4视频,其中img_root为视频帧文件夹路径。
代码如下(示例):
#!/usr/bin/env python
import cv2
import os
img_root = 'VisDrone2019-MOT-val/sequences/uav0000086_00000_v/' # 视频帧文件夹路径,注意最后一个文件夹要有斜杠
fps = 20 # 保存视频的FPS,可以适当调整
img = cv2.imread('VisDrone2019-MOT-val/sequences/uav0000086_00000_v/0000001.jpg') # 图片样本
imginfo = img.shape
size = (imginfo[1],imginfo[0])
print(size)
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
videoWriter = cv2.VideoWriter('sample.mp4',fourcc,fps,size,True)
indexes_image = os.listdir(img_root)
for index in indexes_image:
frame = cv2.imread(img_root + str(index))
videoWriter.write(frame)
videoWriter.release()