Creating Video from JPG or PNG images using OpenCV-python

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

转自
Steps:

  1. Fetch all the image file names using glob
  2. Read all the images using cv2.imread()
  3. Store all the images into a list
  4. Create a VideoWriter object using cv2.VideoWriter()
  5. Save the images to video file using cv2.VideoWriter().write()
  6. 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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值