最近写的一个小工作,将视频切分成帧
import cv2
import os
video_folder = './row_data'#原始数据文件夹
for video_file in os.listdir(video_folder):
if video_file.endswith('.avi'):
video_path = os.path.join(video_folder, video_file)
cap = cv2.VideoCapture(video_path)
vid_name = os.path.splitext(video_file)[0]
os.mkdir(os.path.join(video_folder, vid_name)) #创建输出的文件夹
success, frame = cap.read()
count = 1
while success:
cv2.imwrite(os.path.join(video_folder, vid_name, "{:03d}.jpg".format(count)), frame)
success, frame = cap.read()
print('Read frame {} from {}'.format(count, video_file))
count += 1