Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions imutils/video/webcamvideostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from threading import Thread
import cv2

class WebcamVideoStream:
def __init__(self, src=0, name="WebcamVideoStream"):
class WebcamVideoStream(Thread):
def __init__(self, src=0, name="WebcamVideoStream", *args, **kwargs):
# initialize the video camera stream and read the first frame
# from the stream
self.stream = cv2.VideoCapture(src)
Expand All @@ -15,15 +15,11 @@ def __init__(self, src=0, name="WebcamVideoStream"):
# initialize the variable used to indicate if the thread should
# be stopped
self.stopped = False

super().__init__(*args, **kwargs)
self.daemon = True

def start(self):
# start the thread to read frames from the video stream
t = Thread(target=self.update, name=self.name, args=())
t.daemon = True
t.start()
return self

def update(self):
def run(self):
# keep looping infinitely until the thread is stopped
while True:
# if the thread indicator variable is set, stop the thread
Expand Down