forked from wasmerio/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtake_pictures_from_webcam.py
More file actions
34 lines (30 loc) · 881 Bytes
/
Copy pathtake_pictures_from_webcam.py
File metadata and controls
34 lines (30 loc) · 881 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
#!/usr/bin/env python3
import cv2
import click
import os
@click.command()
@click.option(
"--directory", default="None", help="Directory in which to store frames"
)
@click.option(
"--name", default="person", help="Directory in which to store frames"
)
def main(name, directory):
if directory=="None":
directory = os.getcwd()
capture = cv2.VideoCapture(0)
frame_count = 0
while True:
ret, frame = capture.read()
frame = cv2.resize(frame, (600,600))
cv2.imshow("frame", frame)
key = cv2.waitKey(50)
if key & 0xFF == ord("q"):
cv2.destroyAllWindows()
break
if key & 0xFF == ord(" "):
cv2.imwrite(f"{directory}/{name+str(frame_count)}.jpg", frame)
print(f"got {name+str(frame_count)}" )
frame_count += 1
if __name__ == "__main__":
main()