当前位置:网站首页>视频按每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()
边栏推荐
- MySQL 复合查询
- 麒麟软件韩乃平:数字中国建设需要自己的开源根社区
- 治数如治水,数据治理和数据创新难在哪?
- 会议预告 | 华为 2012 实验室全球软件技术峰会-欧洲分会场
- R语言ggplot2可视化:使用ggplot2可视化散点图、aes函数中的colour参数指定不同分组的数据点使用不同的颜色显示
- STM32 porting the fish component of RT thread Standard Edition
- 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
- Joplin实现样式更改
- MySQL索引和优化的理解学习
- What is the principle of spectral confocal displacement sensor? Which fields can be applied?
猜你喜欢

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

List集合

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

MySQL 复合查询

edusoho企培版纯内网部署教程(解决播放器,上传,后台卡顿问题)

Hisilicon 3559 developing common sense reserves: a complete explanation of related terms

解决服务器重装无法通过ssh连接的问题

A High-Precision Positioning Approach for Catenary Support Components With Multiscale Difference阅读笔记

AGCO AI frontier promotion (6.30)

光谱共焦位移传感器的原理是什么?能应用那些领域?
随机推荐
Edusoho enterprise training version intranet only deployment tutorial (to solve the problems of player, upload and background jam)
Embedded sig | multi OS hybrid deployment framework
SuperMap iClient3D 11i for Cesium三维场景中图例使用说明
Map collection
[bug solution] fiftyone reports attributeerror: module 'CV2' has no attribute 'GAPI_ wip_ gst_ Gstreamerpipeline 'error resolution
光谱共焦位移传感器的原理是什么?能应用那些领域?
Installing onnx is very slow. Use Tsinghua image
NoSQL——Redis的配置与优化
Set set
Hisilicon 3559 sample parsing: Venc
A review of quantum neural networks 2022 for generating learning tasks
Yolov5 export the pit encountered by onnx
海思3559 sample解析:venc
iServer发布ES服务查询设置最大返回数量
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
Hannaiping of Qilin software: the construction of Digital China needs its own open source root community
Swagger2自动生成APi文档
海思3559开发常识储备:相关名词全解
R language ggplot2 visualization: use ggplot2 visualization scatter diagram and the size parameter in AES function to specify the size of data points (point size)
[cf] 803 div2 B. Rising Sand