forked from ultralytics/yolov5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture_vid.py
53 lines (38 loc) · 1.13 KB
/
capture_vid.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
41
42
43
44
45
46
47
48
49
50
51
52
53
'''
Capture frames from video and save as JPEG images.
'''
import os
import cv2
import sys
import argparse
def main(path_vid: str, path_imgs: str):
cap = cv2.VideoCapture(path_vid)
id = 0
try:
os.mkdir(path_imgs)
os.mkdir(path_imgs + '/images')
except:
pass
while True:
ret, frame = cap.read()
if not ret:
print('Cant capture video')
break
# Show frame on window
cv2.imshow('Display',frame)
k = cv2.waitKey(1)
# Press 'q' on the keyboard to quit program
if k == ord('q'):
break
# Save the frame as JPEG file
cv2.imwrite(path_imgs + f'/images/{id}.jpg', frame)
id+=1
cap.release()
cv2.destroyAllWindows()
sys.exit()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--path_vid', type=str, default='./data/videos/cars.mp4' , help='path to video')
parser.add_argument('--path_imgs', type=str, default='./datasets/cars_1' , help='path to save images')
opt = parser.parse_args()
main(opt.path_vid, opt.path_imgs)