脚本代码如下,python小白看不懂代码欢迎联系我,QQ840694971,密码:黄俊雄
import cv2
import os
import shutil
# from config import fg_video_path
fg_video_path = 'data/fg.mp4'
def become_video(fg_in_bg):
cap = cv2.VideoCapture(fg_video_path)
fgs = int(cap.get(cv2.CAP_PROP_FPS))
pictrue_in_filelist = os.listdir(fg_in_bg)
name = fg_in_bg + "/" + pictrue_in_filelist[0]
img = cv2.imread(name)
h, w, c = img.shape
size = (w, h)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out_video = fg_in_bg + '.avi'
video_writer = cv2.VideoWriter(out_video, fourcc, fgs, size)
for i in range(len(pictrue_in_filelist)):
pictrue_in_filename = fg_in_bg + "/" + pictrue_in_filelist[i]
img12 = cv2.imread(pictrue_in_filename)
video_writer.write(img12)
video_writer.release()
print("删除合成的图片数据集")
shutil.rmtree(fg_in_bg)
return out_video
if __name__ == '__main__':
video = become_video("data/fg_in_bg")
我图片序列集是文件夹data/fg_in_bg,data/fg.mp4是我准备的一个视频,以这个视频的帧数来将图片合成视频。
关注点赞评论,素质三连,累了下期见……