MCPcopy Create free account
hub / github.com/PyImageSearch/imutils / WebcamVideoStream

Class WebcamVideoStream

imutils/video/webcamvideostream.py:5–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import cv2
4
5class WebcamVideoStream:
6 def __init__(self, src=0, name="WebcamVideoStream"):
7 # initialize the video camera stream and read the first frame
8 # from the stream
9 self.stream = cv2.VideoCapture(src)
10 (self.grabbed, self.frame) = self.stream.read()
11
12 # initialize the thread name
13 self.name = name
14
15 # initialize the variable used to indicate if the thread should
16 # be stopped
17 self.stopped = False
18
19 def start(self):
20 # start the thread to read frames from the video stream
21 t = Thread(target=self.update, name=self.name, args=())
22 t.daemon = True
23 t.start()
24 return self
25
26 def update(self):
27 # keep looping infinitely until the thread is stopped
28 while True:
29 # if the thread indicator variable is set, stop the thread
30 if self.stopped:
31 return
32
33 # otherwise, read the next frame from the stream
34 (self.grabbed, self.frame) = self.stream.read()
35
36 def read(self):
37 # return the frame most recently read
38 return self.frame
39
40 def stop(self):
41 # indicate that the thread should be stopped
42 self.stopped = True

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…