<s> from threading import Thread <EOL> import cv2 <EOL> class WebcamVideoStream : <EOL> def __init__ ( self , src = <NUM_LIT:0> ) : <EOL> self . stream = cv2 . VideoCapture ( src ) <EOL> ( self . grabbed , self . frame ) = self . stream . read ( ) <EOL> self . stopped = False <EOL> def start ( self ) : <EOL> t = Thread ( target = self . update , args = ( ) ) <EOL> t . daemon = True <EOL> t . start ( ) <EOL> return self <EOL> def update ( self ) : <EOL> while True : <EOL> if self . stopped : <EOL> return <EOL> ( self . grabbed , self . frame ) = self . stream . read ( ) <EOL> def read ( self ) : <EOL> return self . frame <EOL> def stop ( self ) : <EOL> self . stopped = True </s>
