当前位置:网站首页>视频按每100帧存一个文件夹,处理完再图片转视频
视频按每100帧存一个文件夹,处理完再图片转视频
2022-06-30 12:00:00 【cv-daily】
video转图片
import cv2
from PIL import Image
import numpy as np
import os
# cap = cv2.VideoCapture("/home/zhanglu/tao/contain/tlt_infer_testing/deepstm_result/result.mp4") # 获取视频对象
cap = cv2.VideoCapture("/media/zhanglu/ff11386b-3ffe-4e34-a2f7-35bd45cb2e72/data/realbsvsr/0629.mov") # 获取视频对象
isOpened = cap.isOpened # 判断是否打开
# 视频信息获取
fps = cap.get(cv2.CAP_PROP_FPS)
imageNum = -1
sum=0
while (isOpened):
sum+=1
(frameState, frame) = cap.read() # 记录每帧及获取状态
# if frameState == True and (sum % timef==0):
if frameState == True:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = Image.fromarray(np.uint8(frame))
frame = np.array(frame)
# RGBtoBGR满足opencv显示格式
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
imageNum = imageNum + 1
name = str(imageNum).zfill(8)
fileName = 'data/part/part1/' + str(name) + '.png' # 存储路径
cv2.imwrite(fileName, frame, [cv2.IMWRITE_JPEG_QUALITY, 100])
print(fileName + " successfully write in") # 输出存储状态
elif frameState == False:
break
print('finish!')
cap.release()
图片按每个文件夹00000000.png~00000099.png存放
import os,cv2
path='imgs/all/'
new_path='imgs/partaa/'
dir=os.listdir(path)
count=0
for name in dir:
a=cv2.imread(path+name)
name_i=int(name.strip('.png'))
res=int(name_i/100)
for i in range(99):
if i==0:
continue
if res>=i and res<i+1:
new_path_1=new_path+'part'+str(res+1)
if not os.path.exists(new_path_1):
os.mkdir(new_path_1)
new_name_i=name_i-100*res
name_last = str(new_name_i).zfill(8)+'.png'
os.rename(os.path.join(path,name),os.path.join(new_path_1,name_last))
处理完再把这些文件夹存成视频
import os,cv2
video = cv2.VideoWriter('/media/zhanglu/0bb0d537-0b35-45bf-94ec-9def4a6dd599/zhanglu/RealBasic/BasicVSR_PlusPlus-master/ss.mp4', cv2.VideoWriter_fourcc(*"mp4v"), 30, (1408,792)) #创建视频流对象-格式一
path='/media/zhanglu/0bb0d537-0b35-45bf-94ec-9def4a6dd599/zhanglu/RealBasic/BasicVSR_PlusPlus-master/results/'
for i in range(1,35):
path_new = path+ 'demo_'+str(i)
dir=os.listdir(path_new)
for j in range(100):
for name in dir:
if j==int(name.strip('.png')):
img=cv2.imread(os.path.join(path_new,name))
video.write(img) # 向视频文件写入一帧--只有图像,没有声音
video.release()
cv2.waitKey()
边栏推荐
- SuperMap iDesktop 常见倾斜数据处理全流程解析
- [cf] 803 div2 A. XOR Mixup
- 剑指 Offer 05. 替换空格: 把字符串 s 中的每个空格替换成“%20“
- R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram and use scale_ color_ viridis_ D function specifies the color scheme of data points
- [cloud native | kubernetes] in depth understanding of deployment (VIII)
- Understanding and learning of MySQL indexing and optimization
- R语言ggplot2可视化:使用ggplot2可视化散点图、在geom_point参数中设置show_legend参数为FALSE配置不显示图例信息
- The website with id 0 that was requested wasn‘t found. Verify the website and try again
- 解决服务器重装无法通过ssh连接的问题
- Lvgl widget styles
猜你喜欢

使用深度学习进行生物网络分析

Edusoho enterprise training version intranet only deployment tutorial (to solve the problems of player, upload and background jam)

治数如治水,数据治理和数据创新难在哪?

Redis6学习笔记-第二章-Redis6的基本操作

Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance

What are the applications of 3D visual inspection in production flow

使用Power Designer工具构建数据库模型

STM32 移植 RT-Thread 标准版的 FinSH 组件

海思3559开发常识储备:相关名词全解

Use of redis in projects
随机推荐
Use of polarplot function in MATLAB
如何使用插件化机制优雅的封装你的请求hook
A new journey of the smart court, paperless office, escorting the green trial of the smart court
VScode选中多个单词
A high precision positioning approach for category support components with multiscale difference reading notes
A review of quantum neural networks 2022 for generating learning tasks
SuperMap iClient3D 11i for Cesium三维场景中图例使用说明
Set集合
Conference Preview - Huawei 2012 lab global software technology summit - European session
Map集合
并行接口8255A
3D线光谱共焦传感器在半导体如何检测
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
【云原生 | Kubernetes篇】深入了解Deployment(八)
聊聊怎么做硬件兼容性检测,快速迁移到openEuler?
Serial communication interface 8250
移除无效的括号[用数组模拟栈]
R language ggplot2 visualization: use ggplot2 visualization scatter diagram and the color parameter in AES function to specify that data points in different groups are displayed in different colors
海思3559开发常识储备:相关名词全解
R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)