-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.py
68 lines (52 loc) · 1.62 KB
/
cli.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import cv2
import os
from vidgear.gears import CamGear
import sys
import argparse
import time
parser = argparse.ArgumentParser(
prog="downlaod_youtube_frames.",
description="Program to automatically download youtube images datasets.",
epilog="A simple and nice cli script to create youtube datasets",
)
parser.add_argument("--videolink", required=True, type=str, help="YouTube video link")
parser.add_argument(
"--destination", required=True, type=str, help="Target path to save imgz"
)
parser.add_argument(
"--showframe", required=False, action="store_true", help="Show the resulting frames"
)
args = parser.parse_args()
path = args.destination
source = args.videolink
show_frame = args.showframe
time_start = time.time()
stream = CamGear(
source=source,
stream_mode=True,
time_delay=1,
logging=True,
).start()
currentframe = 0
while True:
frame = stream.read()
if frame is None:
break
if show_frame:
cv2.imshow("Output Frame", frame)
name = path + "./frame" + str(currentframe) + ".jpg"
print("Creating..." + name)
cv2.imwrite(name, frame)
currentframe += 5
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cv2.destroyAllWindows()
stream.stop()
time_end = time.time()
time_taken = round(time_end - time_start, 3)
print("=======================================================")
print("-------------------------------------------------------")
print(f"## The time taken to create dataset: {time_taken} seconds ##")
print("-------------------------------------------------------")
print("=======================================================")