-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebcam_capture
More file actions
49 lines (38 loc) · 1.3 KB
/
webcam_capture
File metadata and controls
49 lines (38 loc) · 1.3 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
import cv2
# Tested with Windows 10 and Python 3.6 (Requires Python 3.4 or higher)
class V():
def __init__(self, name, webcam=True ,delay=1000):
self.webcam = webcam
self.name = name
self.delay = delay
vc = cv2.VideoCapture(0)
def showfeed(self):
cv2.namedWindow(str(self.name))
if self.webcam is True:
vc = cv2.VideoCapture(0)
else:
vc = cv2.VideoCapture(str(self.webcam))
if vc.isOpened(): # try to get the first frame
r, f = vc.read()
print("Showing feed, Press ESC to exit")
else:
r = False
while r:
r , f = vc.read()
cv2.imshow(self.name, f) # Show the video frame
key = cv2.waitKey(1)
if key == 27: # exit on ESC
cv2.destroyAllWindows()
vc.release()
return
def captureimages(self):
vc = cv2.VideoCapture(0)
f = vc.read()[1]
count = 0
while count != 10:
cv2.imwrite(f'capture_{self.name}_{str(count)}.png',f) # Change f-string for older Python compatibility
if count == 10:
count = 0
#V('MyWebcam').captureimages()
#V('MyWebcam').showfeed()
#cv2.destroyAllWindows(), vc.release()