参考此处
def write_video(file_path, fps, save_video_name="test.avi"):
import os
img_names = [os.path.join(file_path, name) for name in os.listdir(file_path)]
if not img_names:
print("no images in " + file_path)
return
img0 = cv2.imread(img_names[0])
h, w = img0.shape[0:2]
fourcc = cv2.VideoWriter_fourcc(*'XVID')
writer = cv2.VideoWriter(os.path.join(file_path, save_video_name), fourcc, fps, (w, h)) # 注意这里要改成h w!!!!! 这和openCV读的图片是反的
for img in img_names:
p = cv2.imread(img)
writer.write(p)
writer.release()



