import cv2
from PIL import Image
import numpy as np
cap=cv2.VideoCapture("C:/Users/xpp/Desktop/Lena.mp4")#获取视频对象
isOpened=cap.isOpened#判断是否打开
#视频信息获取
fps=cap.get(cv2.CAP_PROP_FPS)
imageNum=0
sum=0
timef=1#隔1帧保存一张图片
while (isOpened):
sum =1
(frameState, frame)=cap.read()#记录每帧及获取状态
if frameState==True and (sum%timef==0):
#格式转变,BGRtoRGB
frame=cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
#转变成Image
frame=Image.fromarray(np.uint8(frame))
frame=np.array(frame)
#RGBtoBGR满足opencv显示格式
frame=cv2.cvtColor(frame,cv2.COLOR_RGB2BGR)
imageNum=imageNum 1
fileName='C:/Users/xpp/Desktop/Lena/' str(imageNum) '.jpg'#存储路径
cv2.imwrite(fileName,frame,[cv2.IMWRITE_JPEG_QUALITY,100])
print(fileName " successfully write in")#输出存储状态
elif frameState==False:
break
print('finish!')
cap.release()
http://mpvideo.qpic.cn/0bc3heaaeaaauyahqzl2vvrfaoodai4qaaqa.f10003.mp4?
算法:视频抽帧是采用以帧数为间隔的方法进行抽帧形成“视频图像集合”。
文献:Schultz, R. R. , & Stevenson, R. L. . (1996). Extraction of high-resolution frames from video sequences. IEEE Transactions on Image Processing A Publication of the IEEE Signal Processing Society, 5(6), 996-1011.
Kich, V. A. , De Jesus, J. C. , Grando, R. B. , Kolling, A. H. , Heisler, Gabriel Vinícius, & Guerra, R. D. S. . (2022). Deep reinforcement learning using a low-dimensional observation filter for visual complex video game playing.
R, R, Schultz, R, L, & Stevenson. (1996). Extraction of high-resolution frames from video sequences. IEEE Transactions on Image Processing A Publication of the IEEE Signal Processing Society.
数据集:host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar