From 71978a762e3c3aec203e791c9eadde480990e49f Mon Sep 17 00:00:00 2001 From: Lin Chi Yu <32578426+linchiyu@users.noreply.github.com> Date: Mon, 9 Nov 2020 22:51:49 -0300 Subject: [PATCH] Inherit Thread from videoStream Make the class a Thread child --- imutils/video/webcamvideostream.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/imutils/video/webcamvideostream.py b/imutils/video/webcamvideostream.py index dbe8751..0934438 100644 --- a/imutils/video/webcamvideostream.py +++ b/imutils/video/webcamvideostream.py @@ -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) @@ -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