-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveToImage.py
More file actions
39 lines (32 loc) · 916 Bytes
/
Copy pathsaveToImage.py
File metadata and controls
39 lines (32 loc) · 916 Bytes
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
import cv2
import os
filepath = './input.mp4'
savepath = "./img"
video = cv2.VideoCapture(filepath)
if not video.isOpened():
print("Could not Open:", filepath)
exit(0)
length = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = int(video.get(cv2.CAP_PROP_FPS))
print("length :", length)
print("width : ", width)
print("height : ", height)
print("fps :", fps)
try:
if not os.path.exists(savepath):
os.makedirs(savepath)
except OSError:
print('Error: Creating directory' + savepath)
count = 0
ret = True
while(video.isOpened() and ret):
ret, image = video.read()
if not ret:
break
if(int(video.get(1)) % fps == 0):
save_filepath = os.path.join(savepath, "{}.jpg".format(count))
cv2.imwrite("img/{}.jpg".format(count), image)
count += 1
video.release()