forked from TianzhongSong/C3D-keras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
video2img.py
26 lines (23 loc) · 893 Bytes
/
video2img.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import cv2
import os
video_path = '/home/tianz/datasets/ucf101/'
save_path = '/home/tianz/datsets/ucfimgs/'
action_list = os.listdir(video_path)
for action in action_list:
if not os.path.exists(save_path+action):
os.mkdir(save_path+action)
video_list = os.listdir(video_path+action)
for video in video_list:
prefix = video.split('.')[0]
if not os.path.exists(save_path+action+'/'+prefix):
os.mkdir(save_path+action+'/'+prefix)
save_name = save_path + action + '/' + prefix + '/'
video_name = video_path+action+'/'+video
cap = cv2.VideoCapture(video_name)
fps = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
fps_count = 0
for i in range(fps):
ret, frame = cap.read()
if ret:
cv2.imwrite(save_name+str(10000+fps_count)+'.jpg',frame)
fps_count += 1