python-----图片保存为视频
2024-09-01 15:12:58
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/7/2 13:32
# @Author : xiaodai
# -*- coding: UTF-8 -*-
import os
import cv2
from tqdm import tqdm
from multiprocessing import Pool # 图片合成视频
def pic_to_video(path,save_path,time_dir):
filelist = os.listdir(path) #获取该目录下的所有文件名
writer = None
print('-------->',path,save_path)
for item in tqdm(filelist):
if item.endswith('.jpg'): #判断图片后缀是否是.jpg
item = path + '/' + item
img = cv2.imread(item) #使用opencv读取图像,直接返回numpy.ndarray 对象,通道顺序为BGR ,注意是BGR,通道值默认范围0-255。
if writer is None:
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
writer = cv2.VideoWriter(save_path+'/'+time_dir+'.mp4', fourcc, 16,
(img.shape[1], img.shape[0]), True)
if writer is not None:
writer.write(img) if __name__ == '__main__':
org_path = r"F:\temp\test"
for cam_name in os.listdir(org_path):
cam_path = os.path.join(org_path,cam_name)
p = Pool(8)
for time_dir in os.listdir(cam_path):
path = os.path.join(cam_path,time_dir,'JPEGImages')
save_path = os.path.join(cam_path,time_dir,'JPEGImages')
os.makedirs(save_path,exist_ok=True)
p.apply_async(pic_to_video, args=(path, save_path,time_dir,))
p.close()
p.join()
原文:https://blog.csdn.net/Hss891213/article/details/82468268
最新文章
- c#一个泛型控制Textbox 和label 控件 泛型方法。
- jboss:在standalone.xml中设置系统属性(system-properties)
- 手机端开发icon的问题
- C# 如何查看源程序的IL代码
- 使用CSC.EXE编译第一个HELLO WORLD
- Oracle得知(十五):分布式数据库
- protobuf代码生成
- 运行React-Native项目
- linux内核中断之看门狗
- Three.js学习笔记02
- 前端开发【第四篇: Dom操作】
- luogu P1268 树的重量
- 奇怪吸引子---GenesioTesi
- Android之把eoe客户端的关联ViewPager的滑动条勾出来使用
- 解释一下文件/etc/fstab的内容
- 解决NSImage绘制的时候图像模糊
- Java - io输入输出流 --转换流
- git 和github
- JavaScript DOM编程艺术学习笔记-第二章JavaScript语法
- 【leetcode刷题笔记】Permutation Sequence