当前位置:网站首页>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()
边栏推荐
猜你喜欢

NoSQL - redis configuration and optimization

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

Browser plays RTSP video based on nodejs

MySQL built-in functions

Set set

Ensemble de cartes

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

A high precision positioning approach for category support components with multiscale difference reading notes

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

【LeetCode】15、三数之和
随机推荐
Linux系统Redis的安装
立创 EDA #学习笔记10# | 常用连接器元器件识别 和 无源蜂鸣器驱动电路
[bug solution] fiftyone reports attributeerror: module 'CV2' has no attribute 'GAPI_ wip_ gst_ Gstreamerpipeline 'error resolution
Set set
ModelAtrs声音检测,基于声学特征的异响检测
[leetcode] 15. Sum of three numbers
Hisilicon 3559 sample parsing: Venc
Substrate 源码追新导读: 5月中旬: Uniques NFT模块和Nomination Pool
爱可可AI前沿推介(6.30)
Vscode select multiple words
1020. number of enclaves
Inner join and outer join of MySQL tables
Statistics on the number of closed Islands
lvgl 小部件样式篇
Talk about how to do hardware compatibility testing and quickly migrate to openeuler?
DMA控制器8237A
Map collection
海思3559开发常识储备:相关名词全解
List集合
Map集合