当前位置:网站首页>Videos are stored in a folder every 100 frames, and pictures are transferred to videos after processing
Videos are stored in a folder every 100 frames, and pictures are transferred to videos after processing
2022-06-30 12:24:00 【cv-daily】
video Turn picture
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") # Get the video object
cap = cv2.VideoCapture("/media/zhanglu/ff11386b-3ffe-4e34-a2f7-35bd45cb2e72/data/realbsvsr/0629.mov") # Get the video object
isOpened = cap.isOpened # Decide whether to open
# Video information acquisition
fps = cap.get(cv2.CAP_PROP_FPS)
imageNum = -1
sum=0
while (isOpened):
sum+=1
(frameState, frame) = cap.read() # Record each frame and acquisition status
# 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 Satisfy opencv Display format
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
imageNum = imageNum + 1
name = str(imageNum).zfill(8)
fileName = 'data/part/part1/' + str(name) + '.png' # Storage path
cv2.imwrite(fileName, frame, [cv2.IMWRITE_JPEG_QUALITY, 100])
print(fileName + " successfully write in") # Output storage status
elif frameState == False:
break
print('finish!')
cap.release()
Pictures per folder 00000000.png~00000099.png Deposit
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))
After processing, save these folders as video
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)) # Create a video stream object - Format 1
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) # Write a frame to the video file -- Only images , No sound
video.release()
cv2.waitKey()
边栏推荐
猜你喜欢

不同类型的变量与零究竟是如何比较

How do different types of variables compare with zero

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

Joplin implements style changes

Construction de la plate - forme universelle haisi 3559: obtenir le codage après modification du cadre de données

List collection

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

海思3559 sample解析:venc

Some commonly used hardware information of the server (constantly updated)

Use of polarplot function in MATLAB
随机推荐
Flutter 从零开始 006 单选开关和复选框
浏览器播放rtsp视频,基于nodeJs
ZABBIX monitors the number of TCP connections
Joplin implements style changes
NoSQL - redis configuration and optimization
Multiparty cardinality testing for threshold private set-2021: Interpretation
海思3559萬能平臺搭建:獲取數據幀修改後編碼
Vscode select multiple words
Pinda general permission system (day 7~day 8)
Embedded SIG | 多 OS 混合部署框架
Getting started with the go language is simple: go handles XML files
拆分电商系统为微服务
解决服务器重装无法通过ssh连接的问题
Talk about how to do hardware compatibility testing and quickly migrate to openeuler?
Redis的配置文件及新数据类型
A new journey of the smart court, paperless office, escorting the green trial of the smart court
[cf] 803 div2 A. XOR Mixup
Edusoho enterprise training version intranet only deployment tutorial (to solve the problems of player, upload and background jam)
redis在项目中的使用
会议预告 | 华为 2012 实验室全球软件技术峰会-欧洲分会场