opencv-python将视频切分成帧
原始视频是41秒,每秒30帧,opencv提供了简单的实现来切分视频。代码:# !/usr/bin/python3# -*- coding:utf-8 -*-# Author:WeiFeng Liu# @Time: 2021/12/9 上午8:19import cv2import globimport osdef video_to_frame(save_path,video_path):# sav
·
原始视频是41秒,每秒30帧,opencv提供了简单的实现来切分视频。
代码:
# !/usr/bin/python3
# -*- coding:utf-8 -*-
# Author:WeiFeng Liu
# @Time: 2021/12/9 上午8:19
import cv2
import glob
import os
def video_to_frame(save_path,video_path):
# save_path : frame save path
# video_path : source video path
# max_index :
video = cv2.VideoCapture(video_path)
index = 0
if video.isOpened():
rval,frame = video.read()
else:
rval = False
while rval:
print(index)
rval,frame = video.read()
cv2.imwrite(save_path + '/' + str(index)+'.jpg',frame)
index += 1
if __name__ == "__main__":
video_to_frame(video_path="video segmentation/cityscapes/fcn_result.mp4",
save_path="video_to_frame",
)
print("succeed")
更多推荐
已为社区贡献1条内容
所有评论(0)