当前位置:网站首页>视频按每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()
边栏推荐
- Talk about how to do hardware compatibility testing and quickly migrate to openeuler?
- Joplin实现样式更改
- Parallel interface 8255A
- Redis - ziplist compressed list
- Go 语言入门很简单:Go 处理 XML 文件
- Edusoho enterprise training version intranet only deployment tutorial (to solve the problems of player, upload and background jam)
- [leetcode] 15. Sum of three numbers
- time 函数和 clock_gettime()函数的区别
- 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
- Serial communication interface 8250
猜你喜欢
实现多方数据安全共享,解决普惠金融信息不对称难题
Map collection
服务器常用的一些硬件信息(不断更新)
这些电影中的科幻构想,已经用AI实现了
A Generic Deep-Learning-Based Approach for Automated Surface Inspection-論文閱讀筆記
NoSQL——Redis的配置与优化
MATLAB中polarplot函数使用
90. (cesium chapter) cesium high level listening events
SuperMap iClient3D 11i for Cesium三维场景中图例使用说明
Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution
随机推荐
21、wpf之绑定使用小记
Essay: Research on smart home scheme
Vscode select multiple words
90.(cesium篇)cesium高度监听事件
海思3559开发常识储备:相关名词全解
1254. 统计封闭岛屿的数目
8253计数器介绍
MATLAB中polarplot函数使用
Go zero micro Service Practice Series (VIII. How to handle tens of thousands of order requests per second)
服务器常用的一些硬件信息(不断更新)
The sci-fi ideas in these movies have been realized by AI
lvgl 小部件样式篇
聊聊怎么做硬件兼容性检测,快速迁移到openEuler?
Flutter 从零开始 006 单选开关和复选框
Understanding and learning of MySQL indexing and optimization
光谱共焦位移传感器的原理是什么?能应用那些领域?
实现多方数据安全共享,解决普惠金融信息不对称难题
VScode选中多个单词
麒麟软件韩乃平:数字中国建设需要自己的开源根社区
各厂家rtsp地址格式如下: