转自
Steps:
- Fetch all the image file names using glob
- Read all the images using cv2.imread()
- Store all the images into a list
- Create a VideoWriter object using cv2.VideoWriter()
- Save the images to video file using cv2.VideoWriter().write()
- Release the VideoWriter and destroy all windows.
import cv2
import numpy as np
import glob
img_array = []
# glob.glob(正则表达式), 返回一个列表
for filename in glob.glob('C:/New folder/Images/*.jpg'):
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width

这篇博客介绍了如何使用Python的OpenCV库将一组图片转换为视频文件。首先,通过glob模块获取所有图片文件名,然后利用cv2.imread()读取图片并存储到列表中。接着,创建VideoWriter对象,指定输出视频的编码、帧率和尺寸。最后,遍历图片列表,通过VideoWriter.write()方法写入每一帧,并在完成时释放资源。示例代码中还展示了如何将.jpg和.png文件转换为.avi和.mp4格式的视频。
最低0.47元/天 解锁文章
1362

被折叠的 条评论
为什么被折叠?



