class ThreadedCamera(object):
     def __init__(self, source=0):
         global cap
         self.capture = cv2.VideoCapture(source)
  
         self.thread = Thread(target=self.update, args=())
         self.thread.daemon = True  # 防止主线程挂掉,子线变成程僵尸进程
         self.thread.start()
  
         self.status = False
         self.frame = None
  
     def update(self):
         while True:
             if self.capture.isOpened():
                 (self.status, self.frame) = self.capture.read()
  
     def grab_frame(self):
         if self.status:
             return (self.status,self.frame)
         return (None,None)
         
 streamer = ThreadedCamera(args.video)
 while True:#cv.waitKey(1) != 'q':
     has_frame, show = streamer.grab_frame()