-
Notifications
You must be signed in to change notification settings - Fork 8
/
data_preparation.py
40 lines (36 loc) · 1.38 KB
/
data_preparation.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import cv2
import os
def convert_mp4_to_image(inpath, outpath, each_x_frame=1):
print("load "+inpath)
vidcap = cv2.VideoCapture(inpath)
success, image = vidcap.read()
count = 0
while success:
if count % each_x_frame == 0:
cv2.imwrite(outpath+str(count).zfill(4)+".jpg", image) # save frame as JPEG file
success, image = vidcap.read()
if success:
count += 1
if count % 100 == 0:
print('Finish frame: ', count)
# time.sleep(1)
print("Finish all ", count, " images")
def convert_h36m_mp4_to_image(base_path, each_x_frame=1):
subjects = ['S1', 'S5', 'S6', 'S7', 'S8']
# subjects = ['S1', 'S5', 'S6', 'S7', 'S8', 'S9', 'S11']
for subject in subjects:
inpath_base = base_path+subject+"/Videos"
outpath_base = base_path+subject+"/Images"
if not os.path.exists(outpath_base):
os.makedirs(outpath_base)
videos = os.listdir(inpath_base)
for video in videos:
inpath = inpath_base + "/" + video
outpath = outpath_base + "/" + video[:-4]
if not os.path.exists(outpath):
os.makedirs(outpath)
outpath = outpath + "/frame_"
convert_mp4_to_image(inpath, outpath, each_x_frame)
if __name__ == "__main__":
path = "./"
convert_h36m_mp4_to_image(path+'Human36m/')