Python OpenCV图片转视频
粘贴即用,注意使用时最好把自己的文件按照数字顺序命名。按照引导输入操作。
# 一键傻瓜式引导图片串成视频
# 注意使用前最好把文件命名为数字顺序格式
import os
import cv2
def frame2video(image_path, save_path, fps, size):
fourcc = cv2.VideoWriter_fourcc(*'I420')
video_writer = cv2.VideoWriter(save_path, fourcc, fps, size)
file_list = os.listdir(image_path)
# print(file_list)
counter = 1
for file in file_list:
print(counter)
counter += 1
image = image_path + file
image = cv2.imread(image)
video_writer.write(image)
video_writer.release()
print("we are done!")
def guide():
image_path = input("请输入图片存储路径,注意在最后要加\或/:")
save_path = image_path + "video.avi"
fps = int(input("请输入每秒钟的帧数:"))
width = input("请输入图片的宽:")
height = input("请输入图片的高:")
size = (int(width), int(height))
return image_path, save_path, fps, size
if __name__ == "__main__":
image_path, save_path, fps, size = guide()
frame2video(image_path, save_path, fps, size)