python_opencv ——图片预处里(一)

参考链接:https://blog.csdn.net/qq_38497266/article/details/103245478

将视频处理为指定帧数之间的图片,并保存指定文件夹

 1 import cv2
 2 
 3 
 4 def video2frame(videos_path, frames_save_path, time_interval):
 5     '''
 6     :param videos_path: 视频的存放路径
 7     :param frames_save_path: 视频切分成帧之后图片的保存路径
 8     :param time_interval: 保存间隔
 9     :return:
10     '''
11     vidcap = cv2.VideoCapture(videos_path)
12     success, image = vidcap.read()
13     count = 0
14     while success:
15         success, image = vidcap.read()
16         if count % time_interval == 0:
17             cv2.imencode('.jpg', image)[1].tofile(frames_save_path + "/frame_%d.jpg" % (count/30))
18 
19         count += 1
20         # if count == 20:
21         #   break
22     print(count)
23 
24 
25 if __name__ == '__main__':
26     videos_path = 'video/23.mp4'
27     frames_save_path = 'frame_output/23'
28     time_interval = 30 # 隔30帧保存一次
29     video2frame(videos_path, frames_save_path, time_interval)

 

posted @ 2020-07-14 06:49  cfancy  阅读(154)  评论(0编辑  收藏  举报