注意下方尺寸问题
images_directory = 'G:\\opt\\upload\\imageGroup\\123'
video_output = 'G:\\opt\\upload\\imageGroup\\123\\output_video.mp4'
import cv2
import os
# Get the list of image filenames in the directory
image_files = sorted(os.listdir(images_directory))
fps = 30
frame_size = (1080, 1620) # 图片尺寸根据下方 print(image.shape) 确认 大小不一致 无法播放
# Initialize the video writer
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(video_output, fourcc, fps, frame_size,True)
# Iterate through the image files and write them to the video
for image_file in image_files:
image_path = os.path.join(images_directory, image_file)
if image_path.endswith('.jpg'):
print(image_path)
image = cv2.imread(image_path)
cv2.imshow('frame', image)
print(image.shape)
video_writer.write(image)
# Release the video writer
video_writer.release()