-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv2i.py
More file actions
60 lines (45 loc) · 1.43 KB
/
Copy pathv2i.py
File metadata and controls
60 lines (45 loc) · 1.43 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import cv2
import os
import glob
video_path_list = sorted(glob.glob(os.path.join("*.mp4")))
# rotate 90 clockwise
def RotateClockWise90(img):
trans_img = cv2.transpose(img)
new_img = cv2.flip(trans_img, 1)
return new_img
# rotate 90 anticlockwise
def RotateAntiClockWise90(img):
trans_img = cv2.transpose(img)
new_img = cv2.flip(trans_img, 0)
return new_img
for video_path in video_path_list:
print("Processing ", video_path)
if 'front' in video_path:
clockwise = False
elif 'back' in video_path:
clockwise = True
else:
clockwise = None
outdir = os.path.join(video_path + 'image')
if not os.path.exists(outdir):
os.makedirs(outdir)
video = cv2.VideoCapture(video_path)
numFrame = 0
while True:
if video.grab():
flag, frame = video.retrieve()
if not flag:
continue
else:
numFrame += 1
image_path = os.path.join(outdir, '%4d' %(numFrame) + ".jpg")
if clockwise == True:
frame = RotateClockWise90(frame)
elif clockwise == False:
frame = RotateAntiClockWise90(frame)
else:
pass
cv2.imwrite(image_path, frame)
else:
break
print("Done.")